@libp2p/autonat-v2 2.0.14 → 2.0.15-811a29f8a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,10 +1,7 @@
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 yc=Object.create;var Tr=Object.defineProperty;var xc=Object.getOwnPropertyDescriptor;var wc=Object.getOwnPropertyNames;var Ec=Object.getPrototypeOf,Sc=Object.prototype.hasOwnProperty;var vc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)Tr(r,e,{get:t[e],enumerable:!0})},Ns=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of wc(t))!Sc.call(r,s)&&s!==e&&Tr(r,s,{get:()=>t[s],enumerable:!(n=xc(t,s))||n.enumerable});return r};var _c=(r,t,e)=>(e=r!=null?yc(Ec(r)):{},Ns(t||!r||!r.__esModule?Tr(e,"default",{value:r,enumerable:!0}):e,r)),Ac=r=>Ns(Tr({},"__esModule",{value:!0}),r);var za=vc(Sr=>{(function(){var r,t,e,n,s,o,i,a;a=function(c){var u,f,l,d;return u=(c&255<<24)>>>24,f=(c&255<<16)>>>16,l=(c&65280)>>>8,d=c&255,[u,f,l,d].join(".")},i=function(c){var u,f,l,d,m,h;for(u=[],l=d=0;d<=3&&c.length!==0;l=++d){if(l>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}h=t(c),m=h[0],f=h[1],c=c.substring(f),u.push(m)}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"),o=e("a"),s=e("A"),t=function(c){var u,f,l,d,m;for(d=0,u=10,f="9",l=0,c.length>1&&c[l]==="0"&&(c[l+1]==="x"||c[l+1]==="X"?(l+=2,u=16):"0"<=c[l+1]&&c[l+1]<="9"&&(l++,u=8,f="7")),m=l;l<c.length;){if("0"<=c[l]&&c[l]<=f)d=d*u+(e(c[l])-n)>>>0;else if(u===16)if("a"<=c[l]&&c[l]<="f")d=d*u+(10+e(c[l])-o)>>>0;else if("A"<=c[l]&&c[l]<="F")d=d*u+(10+e(c[l])-s)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");l++}if(l===m)throw new Error("empty octet");return[d,l]},r=(function(){function c(u,f){var l,d,m,h;if(typeof u!="string")throw new Error("Missing `net' parameter");if(f||(h=u.split("/",2),u=h[0],f=h[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(v){throw l=v,new Error("Invalid mask: "+f)}for(d=m=32;m>=0;d=--m)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(f||f===0)this.bitmask=parseInt(f,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 l=v,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+f);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 f,l,d;for(d=i(this.first),l=i(this.last),f=0;d<=l;)u(a(d),d,f),f++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c})(),Sr.ip2long=i,Sr.long2ip=a,Sr.Netmask=r}).call(Sr)});var yd={};bt(yd,{autoNATv2:()=>bd});var Pt=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"}},Rr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Pr=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 Nn=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 Or=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 s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:o})=>o!==e),this.#t.set(t,s))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var kr=Symbol.for("@libp2p/service-capabilities"),Nr=Symbol.for("@libp2p/service-dependencies");var Fn={};bt(Fn,{base58btc:()=>X,base58flickr:()=>Rc});var Xd=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 Ot(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 Ic(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 s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(e[i]!==255)throw new TypeError(o+" is ambiguous");e[i]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(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)*f+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 m(h){var v=d(h);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:m}}var Bc=Ic,Dc=Bc,Hs=Dc;var Un=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")}},Mn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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)}},Kn=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 Kn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var qn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new Un(t,e,n),this.decoder=new Mn(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function xe({name:r,prefix:t,encode:e,decode:n}){return new qn(r,t,e,n)}function $t({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Hs(e,r);return xe({prefix:t,name:r,encode:n,decode:o=>Ot(s(o))})}function Lc(r,t,e,n){let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*e/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=t[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,i+=e,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function Cc(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<e-i]),n)for(;(o.length*e&7)!==0;)o+="=";return o}function Tc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let s=Tc(n);return xe({prefix:t,name:r,encode(o){return Cc(o,n,e)},decode(o){return Lc(o,s,e,r)}})}var X=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Rc=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var zn={};bt(zn,{base32:()=>Gt,base32hex:()=>Nc,base32hexpad:()=>Mc,base32hexpadupper:()=>Kc,base32hexupper:()=>Uc,base32pad:()=>Oc,base32padupper:()=>kc,base32upper:()=>Pc,base32z:()=>qc});var Gt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Pc=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Oc=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kc=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Nc=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Uc=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Mc=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Kc=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),qc=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Vn={};bt(Vn,{base36:()=>Ze,base36upper:()=>Fc});var Ze=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fc=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var zc=Ys,Gs=128,Vc=127,Hc=~Vc,$c=Math.pow(2,31);function Ys(r,t,e){t=t||[],e=e||0;for(var n=e;r>=$c;)t[e++]=r&255|Gs,r/=128;for(;r&Hc;)t[e++]=r&255|Gs,r>>>=7;return t[e]=r|0,Ys.bytes=e-n+1,t}var Gc=Hn,Zc=128,Zs=127;function Hn(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Hn.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&Zs)<<s:(i&Zs)*Math.pow(2,s),s+=7}while(i>=Zc);return Hn.bytes=o-n,e}var Yc=Math.pow(2,7),Xc=Math.pow(2,14),jc=Math.pow(2,21),Wc=Math.pow(2,28),Qc=Math.pow(2,35),Jc=Math.pow(2,42),tu=Math.pow(2,49),eu=Math.pow(2,56),ru=Math.pow(2,63),nu=function(r){return r<Yc?1:r<Xc?2:r<jc?3:r<Wc?4:r<Qc?5:r<Jc?6:r<tu?7:r<eu?8:r<ru?9:10},ou={encode:zc,decode:Gc,encodingLength:nu},su=ou,Ye=su;function Xe(r,t=0){return[Ye.decode(r,t),Ye.decode.bytes]}function we(r,t,e=0){return Ye.encode(r,t,e),t}function Ee(r){return Ye.encodingLength(r)}function ve(r,t){let e=t.byteLength,n=Ee(r),s=n+Ee(e),o=new Uint8Array(s+e);return we(r,o,0),we(e,o,n),o.set(t,s),new Se(r,e,t,o)}function je(r){let t=Ot(r),[e,n]=Xe(t),[s,o]=Xe(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Se(e,s,i,t)}function Xs(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 Se=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function js(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return au(e,$n(r),t??X.encoder);default:return cu(e,$n(r),t??Gt.encoder)}}var Ws=new WeakMap;function $n(r){let t=Ws.get(r);if(t==null){let e=new Map;return Ws.set(r,e),e}return t}var at=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}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!==uu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=ve(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Xs(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:s,multihash:o,bytes:i}=e;return new r(n,s,o,i??Qs(n,s,o.bytes))}else if(e[fu]===!0){let{version:n,multihash:s,code:o}=e,i=je(s);return r.create(n,o,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 s=Qs(t,e,n.bytes);return new r(t,e,n,s)}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,s=Ot(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new Se(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,d]=Xe(t.subarray(e));return e+=d,l},s=n(),o=We;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),u=e+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,e){let[n,s]=iu(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return $n(o).set(n,t),o}};function iu(r,t){switch(r[0]){case"Q":{let e=t??X;return[X.prefix,e.decode(`${X.prefix}${r}`)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}case Gt.prefix:{let e=t??Gt;return[Gt.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 au(r,t,e){let{prefix:n}=e;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function cu(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var We=112,uu=18;function Qs(r,t,e){let n=Ee(r),s=n+Ee(t),o=new Uint8Array(s+e.byteLength);return we(r,o,0),we(t,o,n),o.set(e,s),o}var fu=Symbol.for("@ipld/js-cid/CID");var Gn={};bt(Gn,{identity:()=>At});var Js=0,lu="identity",ti=Ot;function du(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return ve(Js,ti(r))}var At={code:Js,name:lu,encode:ti,digest:du};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 yt(r=0){return new Uint8Array(r)}function pt(r=0){return new Uint8Array(r)}function kt(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=pt(t),n=0;for(let s of r)e.set(s,n),n+=s.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 s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function Mr(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(Mr(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(Mr(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(Mr(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:s}=this._subList(t,e);return kt(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:kt(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_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=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,f=e>a&&e<=c;if(u&&f){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){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(!Mr(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let l=0;l<o;l++)i[l]=-1;for(let l=0;l<s;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=e;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let m=this.get(l+d);if(n[d]!==m){f=Math.max(1,d-a[m]);break}}if(f===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=pt(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 s=yt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,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 s=yt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,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 s=yt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,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=pt(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 s=yt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,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 s=yt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,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 s=yt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,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 s=yt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,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 s=yt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,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((s,o)=>s+o.byteLength,0)),n.length=e,n}};var Zn={};bt(Zn,{base10:()=>hu});var hu=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var Yn={};bt(Yn,{base16:()=>pu,base16upper:()=>mu});var pu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xn={};bt(Xn,{base2:()=>gu});var gu=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var jn={};bt(jn,{base256emoji:()=>Eu});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}"),bu=ni.reduce((r,t,e)=>(r[e]=t,r),[]),yu=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 xu(r){return r.reduce((t,e)=>(t+=bu[e],t),"")}function wu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=yu[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var Eu=xe({prefix:"\u{1F680}",name:"base256emoji",encode:xu,decode:wu});var Qn={};bt(Qn,{base64:()=>Su,base64pad:()=>vu,base64url:()=>Wn,base64urlpad:()=>_u});var Su=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vu=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Wn=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_u=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Jn={};bt(Jn,{base8:()=>Au});var Au=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var to={};bt(to,{identity:()=>Iu});var Iu=xe({prefix:"\0",name:"identity",encode:r=>zs(r),decode:r=>Fs(r)});var Rh=new TextEncoder,Ph=new TextDecoder;var no={};bt(no,{sha256:()=>Qe,sha512:()=>Cu});var Lu=20;function ro({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:s}){return new eo(r,t,e,n,s)}var eo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,s,o){this.name=t,this.code=e,this.encode=n,this.minDigestLength=s??Lu,this.maxDigestLength=o}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(s=>oi(s,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 ve(t,r)}function ii(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Qe=ro({name:"sha2-256",code:18,encode:ii("SHA-256")}),Cu=ro({name:"sha2-512",code:19,encode:ii("SHA-512")});var Je={...to,...Xn,...Jn,...Zn,...Yn,...zn,...Vn,...Fn,...Qn,...jn},$h={...no,...Gn};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))),oo=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=pt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Tu={utf8:ai,"utf-8":ai,hex:Je.base16,latin1:oo,ascii:oo,binary:oo,...Je},Kr=Tu;function H(r,t="utf8"){let e=Kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function W(r,t="utf8"){let e=Kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ru=parseInt("11111",2),so=parseInt("10000000",2),Pu=parseInt("01111111",2),ui={0:tr,1:tr,2:Ou,3:Uu,4:Mu,5:Nu,6:ku,16:tr,22:tr,48:tr};function io(r,t={offset:0}){let e=r[t.offset]&Ru;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]&so)===so){let n=r[t.offset]&Pu,s="0x";t.offset++;for(let o=0;o<n;o++,t.offset++)s+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(s,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=io(r,t);if(n===null)break;e.push(n)}return e}function Ou(r,t){let e=er(r,t),n=t.offset,s=t.offset+e,o=[];for(let i=n;i<s;i++)i===n&&r[i]===0||o.push(r[i]);return t.offset+=e,Uint8Array.from(o)}function ku(r,t){let e=er(r,t),n=t.offset+e,s=r[t.offset];t.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Nu(r,t){return t.offset++,null}function Uu(r,t){let e=er(r,t),n=r[t.offset];t.offset++;let s=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 s}function Mu(r,t){let e=er(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Ku(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 ao(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Ku(r.byteLength);return new Q(Uint8Array.from([t.byteLength|so]),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]),ao(t),t)}function li(r){let t=Uint8Array.from([0]),e=new Q(t,r);return new Q(Uint8Array.from([3]),ao(e),e)}function qr(r,t=48){let e=new Q;for(let n of r)e.append(n);return new Q(Uint8Array.from([t]),ao(e),e)}async function di(r,t,e,n){let s=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,e.subarray());return n?.signal?.throwIfAborted(),o}var qu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Fu=Uint8Array.from([6,5,43,129,4,0,34]),zu=Uint8Array.from([6,5,43,129,4,0,35]),Vu={ext:!0,kty:"EC",crv:"P-256"},Hu={ext:!0,kty:"EC",crv:"P-384"},$u={ext:!0,kty:"EC",crv:"P-521"},co=32,uo=48,fo=66;function hi(r){let t=io(r);return pi(t)}function pi(r){let t=r[1][1][0],e=1,n,s;if(t.byteLength===co*2+1)return n=W(t.subarray(e,e+co),"base64url"),s=W(t.subarray(e+co),"base64url"),new _e({...Vu,key_ops:["verify"],x:n,y:s});if(t.byteLength===uo*2+1)return n=W(t.subarray(e,e+uo),"base64url"),s=W(t.subarray(e+uo),"base64url"),new _e({...Hu,key_ops:["verify"],x:n,y:s});if(t.byteLength===fo*2+1)return n=W(t.subarray(e,e+fo),"base64url"),s=W(t.subarray(e+fo),"base64url"),new _e({...$u,key_ops:["verify"],x:n,y:s});throw new ft(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function mi(r){return qr([fi(Uint8Array.from([1])),qr([Gu(r.crv)],160),qr([li(new Q(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function Gu(r){if(r==="P-256")return qu;if(r==="P-384")return Fu;if(r==="P-521")return zu;throw new ft(`Invalid curve ${r}`)}var _e=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 At.digest(Ae(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,e,n){return di(this.jwk,e,t,n)}};function ne(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ct(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=ne(r),s=r?.length,o=t!==void 0;if(!n||o&&s!==t){let i=e&&`"${e}" `,a=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Fr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Ct(r.outputLen),Ct(r.blockLen)}function Ie(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 Ut(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function zr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var yi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Mt(r){if(N(r),yi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Zu[r[e]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function gi(r){if(r>=Nt._0&&r<=Nt._9)return r-Nt._0;if(r>=Nt.A&&r<=Nt.F)return r-(Nt.A-10);if(r>=Nt.a&&r<=Nt.f)return r-(Nt.a-10)}function Kt(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 s=0,o=0;s<e;s++,o+=2){let i=gi(r.charCodeAt(o)),a=gi(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function mt(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];N(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}function lo(r,t={}){let e=(s,o)=>r(o).update(s).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=s=>r(s),Object.assign(e,t),Object.freeze(e)}function Be(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 ho=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,s){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=zr(this.buffer)}update(t){Ie(this),N(t);let{view:e,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=zr(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ie(this),bi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;e[i++]=128,Ut(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let l=i;l<s;l++)e[l]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);let a=zr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],o)}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:s,finished:o,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=a,s%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},qt=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 Vr=BigInt(4294967295),Ei=BigInt(32);function Yu(r,t=!1){return t?{h:Number(r&Vr),l:Number(r>>Ei&Vr)}:{h:Number(r>>Ei&Vr)|0,l:Number(r&Vr)|0}}function Si(r,t=!1){let e=r.length,n=new Uint32Array(e),s=new Uint32Array(e);for(let o=0;o<e;o++){let{h:i,l:a}=Yu(r[o],t);[n[o],s[o]]=[i,a]}return[n,s]}var po=(r,t,e)=>r>>>e,mo=(r,t,e)=>r<<32-e|t>>>e,oe=(r,t,e)=>r>>>e|t<<32-e,se=(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 Tt(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|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,s)=>t+e+n+s+(r/2**32|0)|0,Bi=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Di=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var ju=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]),Zt=new Uint32Array(64),go=class extends rr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)Zt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=Zt[l-15],m=Zt[l-2],h=It(d,7)^It(d,18)^d>>>3,v=It(m,17)^It(m,19)^m>>>10;Zt[l]=v+Zt[l-7]+h+Zt[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=It(a,6)^It(a,11)^It(a,25),m=f+d+xi(a,c,u)+ju[l]+Zt[l]|0,v=(It(n,2)^It(n,13)^It(n,22))+wi(n,s,o)|0;f=u,u=c,c=a,a=i+m|0,i=o,o=s,s=n,n=m+v|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){Ut(Zt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}},bo=class extends go{A=qt[0]|0;B=qt[1]|0;C=qt[2]|0;D=qt[3]|0;E=qt[4]|0;F=qt[5]|0;G=qt[6]|0;H=qt[7]|0;constructor(){super(32)}};var 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))),Wu=Li[0],Qu=Li[1],Yt=new Uint32Array(80),Xt=new Uint32Array(80),yo=class extends rr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:m,Gl:h,Hh:v,Hl:x}=this;return[t,e,n,s,o,i,a,c,u,f,l,d,m,h,v,x]}set(t,e,n,s,o,i,a,c,u,f,l,d,m,h,v,x){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=m|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)Yt[w]=t.getUint32(e),Xt[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let I=Yt[w-15]|0,P=Xt[w-15]|0,U=oe(I,P,1)^oe(I,P,8)^po(I,P,7),M=se(I,P,1)^se(I,P,8)^mo(I,P,7),S=Yt[w-2]|0,E=Xt[w-2]|0,O=oe(S,E,19)^nr(S,E,61)^po(S,E,6),K=se(S,E,19)^or(S,E,61)^mo(S,E,6),C=Ai(M,K,Xt[w-7],Xt[w-16]),g=Ii(C,U,O,Yt[w-7],Yt[w-16]);Yt[w]=g|0,Xt[w]=C|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:m,Fl:h,Gh:v,Gl:x,Hh:y,Hl:A}=this;for(let w=0;w<80;w++){let I=oe(l,d,14)^oe(l,d,18)^nr(l,d,41),P=se(l,d,14)^se(l,d,18)^or(l,d,41),U=l&m^~l&v,M=d&h^~d&x,S=Bi(A,P,M,Qu[w],Xt[w]),E=Di(S,y,I,U,Wu[w],Yt[w]),O=S|0,K=oe(n,s,28)^nr(n,s,34)^nr(n,s,39),C=se(n,s,28)^or(n,s,34)^or(n,s,39),g=n&o^n&a^o&a,b=s&i^s&c^i&c;y=v|0,A=x|0,v=m|0,x=h|0,m=l|0,h=d|0,{h:l,l:d}=Tt(u|0,f|0,E|0,O|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let p=vi(O,C,b);n=_i(p,E,K,g),s=p|0}({h:n,l:s}=Tt(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Tt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Tt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Tt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Tt(this.Eh|0,this.El|0,l|0,d|0),{h:m,l:h}=Tt(this.Fh|0,this.Fl|0,m|0,h|0),{h:v,l:x}=Tt(this.Gh|0,this.Gl|0,v|0,x|0),{h:y,l:A}=Tt(this.Hh|0,this.Hl|0,y|0,A|0),this.set(n,s,o,i,a,c,u,f,l,d,m,h,v,x,y,A)}roundClean(){Ut(Yt,Xt)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},xo=class extends yo{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 Ci=lo(()=>new bo,ho(1));var Ti=lo(()=>new xo,ho(3));var Eo=BigInt(0),wo=BigInt(1);function Ft(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function Ri(r){if(typeof r=="bigint"){if(!Hr(r))throw new Error("positive bigint expected, got "+r)}else Ct(r);return r}function sr(r){let t=Ri(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===""?Eo:BigInt("0x"+r)}function De(r){return Pi(Mt(r))}function ie(r){return Pi(Mt(Gr(N(r)).reverse()))}function $r(r,t){Ct(t),r=Ri(r);let e=Kt(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function So(r,t){return $r(r,t).reverse()}function Gr(r){return Uint8Array.from(r)}var Hr=r=>typeof r=="bigint"&&Eo<=r;function Ju(r,t,e){return Hr(r)&&Hr(t)&&Hr(e)&&t<=r&&r<e}function ir(r,t,e,n){if(!Ju(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function vo(r){let t;for(t=0;r>Eo;r>>=wo,t+=1);return t}var ar=r=>(wo<<BigInt(r))-wo;function Oi(r,t,e){if(Ct(r,"hashLen"),Ct(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=x=>new Uint8Array(x),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...x)=>e(u,mt(c,...x)),m=(x=s)=>{u=d(o,x),c=d(),x.length!==0&&(u=d(i,x),c=d())},h=()=>{if(f++>=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 mt(...y)};return(x,y)=>{l(),m(x);let A;for(;!(A=y(h()));)m();return l(),A}}function jt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,i,a){let c=r[o];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${u}`)}let s=(o,i)=>Object.entries(o).forEach(([a,c])=>n(a,c,i));s(t,!1),s(e,!0)}function Le(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let o=r(e,...n);return t.set(e,o),o}}var dt=BigInt(0),J=BigInt(1),ae=BigInt(2),Ui=BigInt(3),Mi=BigInt(4),Ki=BigInt(5),tf=BigInt(7),qi=BigInt(8),ef=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,s=dt,o=J,i=J,a=dt;for(;e!==dt;){let u=n/e,f=n%e,l=s-i*u,d=o-a*u;n=e,e=f,s=i,o=a,i=l,a=d}if(n!==J)throw new Error("invert: does not exist");return j(s,t)}function Ao(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 Ao(r,n,t),n}function rf(r,t){let e=(r.ORDER-Ki)/qi,n=r.mul(t,ae),s=r.pow(n,e),o=r.mul(t,s),i=r.mul(r.mul(o,ae),s),a=r.mul(o,r.sub(i,r.ONE));return Ao(r,a,t),a}function nf(r){let t=Ce(r),e=Vi(r),n=e(t,t.neg(t.ONE)),s=e(t,n),o=e(t,t.neg(n)),i=(r+tf)/Fi;return(a,c)=>{let u=a.pow(c,i),f=a.mul(u,n),l=a.mul(u,s),d=a.mul(u,o),m=a.eql(a.sqr(f),c),h=a.eql(a.sqr(l),c);u=a.cmov(u,f,m),f=a.cmov(d,l,h);let v=a.eql(a.sqr(f),c),x=a.cmov(u,f,v);return Ao(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%ae===dt;)t/=ae,e++;let n=ae,s=Ce(r);for(;Ni(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return zi;let o=s.pow(n,t),i=(t+J)/ae;return function(c,u){if(c.is0(u))return u;if(Ni(c,u)!==1)throw new Error("Cannot find square root");let f=e,l=c.mul(c.ONE,o),d=c.pow(u,t),m=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===f)throw new Error("Cannot find square root");let x=J<<BigInt(f-h-1),y=c.pow(l,x);f=h,l=c.sqr(y),d=c.mul(d,l),m=c.mul(m,y)}return m}}function of(r){return r%Mi===Ui?zi:r%qi===Ki?rf:r%Fi===ef?nf(r):Vi(r)}var Hi=(r,t)=>(j(r,t)&J)===J,sf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Io(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=sf.reduce((n,s)=>(n[s]="function",n),t);return jt(r,e),r}function af(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,s=t;for(;e>dt;)e&J&&(n=r.mul(n,s)),s=r.sqr(s),e>>=J;return n}function cr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),s=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),o=r.inv(s);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),o),n}function Ni(r,t){let e=(r.ORDER-J)/ae,n=r.pow(t,e),s=r.eql(n,r.ONE),o=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function cf(r,t){t!==void 0&&Ct(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var _o=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:s,nByteLength:o}=cf(t,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=o,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 af(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=of(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?So(t,this.BYTES):$r(t,this.BYTES)}fromBytes(t,e=!1){N(t);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(s);u.set(t,o?0:u.length-t.length),t=u}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=o?ie(t):De(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 Ce(r,t={}){return new _o(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 Bo(r){let t=$i(r);return t+Math.ceil(t/2)}function Do(r,t,e=!1){N(r);let n=r.length,s=$i(t),o=Bo(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=e?ie(r):De(r),a=j(i,t-J)+J;return e?So(a,s):$r(a,s)}var Te=BigInt(0),ce=BigInt(1);function ur(r,t){let e=t.negate();return r?e:t}function ue(r,t){let e=cr(r.Fp,t.map(n=>n.Z));return t.map((n,s)=>r.fromAffine(n.toAffine(e[s])))}function Xi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Lo(r,t){Xi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),s=2**r,o=ar(r),i=BigInt(r);return{windows:e,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function Gi(r,t,e){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=e,a=Number(r&s),c=r>>i;a>n&&(a-=o,c+=ce);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,m=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:m,offsetF:u}}var Co=new WeakMap,ji=new WeakMap;function To(r){return ji.get(r)||1}function Zi(r){if(r!==Te)throw new Error("invalid wNAF")}var Re=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 s=t;for(;e>Te;)e&ce&&(n=n.add(s)),s=s.double(),e>>=ce;return n}precomputeWindow(t,e){let{windows:n,windowSize:s}=Lo(e,this.bits),o=[],i=t,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let u=1;u<s;u++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=Lo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:m}=Gi(n,a,i);n=c,f?o=o.add(ur(d,e[m])):s=s.add(ur(l,e[u]))}return Zi(n),{p:s,f:o}}wNAFUnsafe(t,e,n,s=this.ZERO){let o=Lo(t,this.bits);for(let i=0;i<o.windows&&n!==Te;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Gi(n,i,o);if(n=a,!u){let l=e[c];s=s.add(f?l.negate():l)}}return Zi(n),s}getPrecomputes(t,e,n){let s=Co.get(e);return s||(s=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(s=n(s)),Co.set(e,s))),s}cached(t,e,n){let s=To(t);return this.wNAF(s,this.getPrecomputes(s,t,n),e)}unsafe(t,e,n,s){let o=To(t);return o===1?this._unsafeLadder(t,e,s):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),e,s)}createCache(t,e){Xi(e,this.bits),ji.set(t,e),Co.delete(t)}hasCache(t){return To(t)!==1}};function Wi(r,t,e,n){let s=t,o=r.ZERO,i=r.ZERO;for(;e>Te||n>Te;)e&ce&&(o=o.add(s)),n&ce&&(i=i.add(s)),s=s.double(),e>>=ce,n>>=ce;return{p1:o,p2:i}}function Yi(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Io(t),t}else return Ce(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>Te))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Yi(t.p,e.Fp,n),o=Yi(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!s.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:s,Fn:o}}function Yr(r,t){return function(n){let s=r(n);return{secretKey:s,publicKey:t(s)}}}var Wt=BigInt(0),tt=BigInt(1),Ro=BigInt(2),uf=BigInt(8);function ff(r,t,e,n){let s=r.sqr(e),o=r.sqr(n),i=r.add(r.mul(t.a,s),o),a=r.add(r.ONE,r.mul(t.d,r.mul(s,o)));return r.eql(i,a)}function Qi(r,t={}){let e=Zr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:s}=e,o=e.CURVE,{h:i}=o;jt(t,{},{uvRatio:"function"});let a=Ro<<BigInt(s.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:Wt}}});if(!ff(n,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(x,y,A=!1){let w=A?tt:Wt;return ir("coordinate "+x,y,w,a),y}function l(x){if(!(x instanceof h))throw new Error("EdwardsPoint expected")}let d=Le((x,y)=>{let{X:A,Y:w,Z:I}=x,P=x.is0();y==null&&(y=P?uf:n.inv(I));let U=c(A*y),M=c(w*y),S=n.mul(I,y);if(P)return{x:Wt,y:tt};if(S!==tt)throw new Error("invZ was invalid");return{x:U,y:M}}),m=Le(x=>{let{a:y,d:A}=o;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),C=c(E*c(K+S)),g=c(O+c(A*c(M*S)));if(C!==g)throw new Error("bad point: equation left != right (1)");let b=c(w*I),p=c(P*U);if(b!==p)throw new Error("bad point: equation left != right (2)");return!0});class h{static BASE=new h(o.Gx,o.Gy,tt,c(o.Gx*o.Gy));static ZERO=new h(Wt,tt,tt,Wt);static Fp=n;static Fn=s;X;Y;Z;T;constructor(y,A,w,I){this.X=f("x",y),this.Y=f("y",A),this.Z=f("z",w,!0),this.T=f("t",I),Object.freeze(this)}static CURVE(){return o}static fromAffine(y){if(y instanceof h)throw new Error("extended point not allowed");let{x:A,y:w}=y||{};return f("x",A),f("y",w),new h(A,w,tt,c(A*w))}static fromBytes(y,A=!1){let w=n.BYTES,{a:I,d:P}=o;y=Gr(N(y,w,"point")),Ft(A,"zip215");let U=Gr(y),M=y[w-1];U[w-1]=M&-129;let S=ie(U),E=A?a:n.ORDER;ir("point.y",S,Wt,E);let O=c(S*S),K=c(O-tt),C=c(P*O-I),{isValid:g,value:b}=u(K,C);if(!g)throw new Error("bad point: invalid y coordinate");let p=(b&tt)===tt,_=(M&128)!==0;if(!A&&b===Wt&&_)throw new Error("bad point: x=0 and x_0=1");return _!==p&&(b=c(-b)),h.fromAffine({x:b,y:S})}static fromHex(y,A=!1){return h.fromBytes(Kt(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(){m(this)}equals(y){l(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}=o,{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,C=K-M,g=S-U,b=c(O*C),p=c(K*g),_=c(O*g),B=c(C*K);return new h(b,p,B,_)}add(y){l(y);let{a:A,d:w}=o,{X:I,Y:P,Z:U,T:M}=this,{X:S,Y:E,Z:O,T:K}=y,C=c(I*S),g=c(P*E),b=c(M*w*K),p=c(U*O),_=c((I+P)*(S+E)-C-g),B=p-b,L=p+b,T=c(g-A*C),D=c(_*B),R=c(L*T),k=c(_*T),$=c(B*L);return new h(D,R,$,k)}subtract(y){return this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=v.cached(this,y,I=>ue(h,I));return ue(h,[A,w])[0]}multiplyUnsafe(y,A=h.ZERO){if(!s.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===Wt?h.ZERO:this.is0()||y===tt?this:v.unsafe(this,y,w=>ue(h,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,o.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 Mt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new Re(h,s.BITS);return h.BASE.precompute(8),h}function Ji(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');jt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:s,Fp:o,Fn:i}=r,a=e.randomBytes||Be,c=e.adjustScalarBytes||(S=>S),u=e.domain||((S,E,O)=>{if(Ft(O,"phflag"),E.length||O)throw new Error("Contexts/pre-hash are not supported");return S});function f(S){return i.create(ie(S))}function l(S){let E=w.secretKey;N(S,w.secretKey,"secretKey");let O=N(t(S),2*E,"hashedSecretKey"),K=c(O.slice(0,E)),C=O.slice(E,2*E),g=f(K);return{head:K,prefix:C,scalar:g}}function d(S){let{head:E,prefix:O,scalar:K}=l(S),C=s.multiply(K),g=C.toBytes();return{head:E,prefix:O,scalar:K,point:C,pointBytes:g}}function m(S){return d(S).pointBytes}function h(S=Uint8Array.of(),...E){let O=mt(...E);return f(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:C,pointBytes:g}=d(E),b=h(O.context,K,S),p=s.multiply(b).toBytes(),_=h(O.context,p,g,S),B=i.create(b+_*C);if(!i.isValid(B))throw new Error("sign failed: invalid s");let L=mt(p,i.toBytes(B));return N(L,w.signature,"result")}let x={zip215:!0};function y(S,E,O,K=x){let{context:C,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&&Ft(g,"zip215"),n&&(E=n(E));let p=b/2,_=S.subarray(0,p),B=ie(S.subarray(p,b)),L,T,D;try{L=r.fromBytes(O,g),T=r.fromBytes(_,g),D=s.multiplyUnsafe(B)}catch{return!1}if(!g&&L.isSmallOrder())return!1;let R=h(C,T.toBytes(),L.toBytes(),E);return T.add(L.multiplyUnsafe(R)).subtract(D).clearCofactor().is0()}let A=o.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 ne(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 C=K?o.div(tt+E,tt-E):o.div(E-tt,E+tt);return o.toBytes(C)},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:Yr(I,m),getPublicKey:m,sign:v,verify:y,utils:M,Point:r,lengths:w})}var lf=BigInt(1),ta=BigInt(2);var df=BigInt(5),hf=BigInt(8),Po=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),pf={p:Po,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:hf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function mf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=Po,a=r*r%o*r%o,c=V(a,ta,o)*a%o,u=V(c,lf,o)*r%o,f=V(u,df,o)*u%o,l=V(f,t,o)*f%o,d=V(l,e,o)*l%o,m=V(d,n,o)*d%o,h=V(m,s,o)*m%o,v=V(h,s,o)*m%o,x=V(v,t,o)*f%o;return{pow_p_5_8:V(x,ta,o)*r%o,b2:a}}function gf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ea=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function bf(r,t){let e=Po,n=j(t*t*t,e),s=j(n*n*t,e),o=mf(r*s).pow_p_5_8,i=j(r*n*o,e),a=j(t*i*i,e),c=i,u=j(i*ea,e),f=a===r,l=a===j(-r,e),d=a===j(-r*ea,e);return f&&(i=c),(l||d)&&(i=u),Hi(i,e)&&(i=j(-i,e)),{isValid:f||l,value:i}}var yf=Qi(pf,{uvRatio:bf});function xf(r){return Ji(yf,Ti,Object.assign({adjustScalarBytes:gf},r))}var ra=xf({});var fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Xr=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 Xr("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 jr=na;var Wr=32;var Oo,wf=(async()=>{try{return await jr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ef(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await jr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await jr.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 Sf(r,t,e){return ra.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function oa(r,t,e){return Oo==null&&(Oo=await wf),Oo?Ef(r,t,e):Sf(r,t,e)}function Qr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Jr=class{type="Ed25519";raw;constructor(t){this.raw=ko(t,Wr)}toMultihash(){return At.digest(Ae(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let s=oa(this.raw,e,t);return Qr(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function ia(r){return r=ko(r,Wr),new Jr(r)}function ko(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 _f=Math.pow(2,7),Af=Math.pow(2,14),If=Math.pow(2,21),No=Math.pow(2,28),Uo=Math.pow(2,35),Mo=Math.pow(2,42),Ko=Math.pow(2,49),F=128,ct=127;function gt(r){if(r<_f)return 1;if(r<Af)return 2;if(r<If)return 3;if(r<No)return 4;if(r<Uo)return 5;if(r<Mo)return 6;if(r<Ko)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Pe(r,t,e=0){switch(gt(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 Bf(r,t,e=0){switch(gt(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 qo(r,t){let e=r[t],n=0;if(n+=e&ct,e<F||(e=r[t+1],n+=(e&ct)<<7,e<F)||(e=r[t+2],n+=(e&ct)<<14,e<F)||(e=r[t+3],n+=(e&ct)<<21,e<F)||(e=r[t+4],n+=(e&ct)*No,e<F)||(e=r[t+5],n+=(e&ct)*Uo,e<F)||(e=r[t+6],n+=(e&ct)*Mo,e<F)||(e=r[t+7],n+=(e&ct)*Ko,e<F))return n;throw new RangeError("Could not decode varint")}function Df(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<F||(e=r.get(t+1),n+=(e&ct)<<7,e<F)||(e=r.get(t+2),n+=(e&ct)<<14,e<F)||(e=r.get(t+3),n+=(e&ct)<<21,e<F)||(e=r.get(t+4),n+=(e&ct)*No,e<F)||(e=r.get(t+5),n+=(e&ct)*Uo,e<F)||(e=r.get(t+6),n+=(e&ct)*Mo,e<F)||(e=r.get(t+7),n+=(e&ct)*Ko,e<F))return n;throw new RangeError("Could not decode varint")}function aa(r,t,e=0){return t==null&&(t=pt(gt(r))),t instanceof Uint8Array?Pe(r,t,e):Bf(r,t,e)}function lr(r,t=0){return r instanceof Uint8Array?qo(r,t):Df(r,t)}var Fo=new Float32Array([-0]),Qt=new Uint8Array(Fo.buffer);function ua(r,t,e){Fo[0]=r,t[e]=Qt[0],t[e+1]=Qt[1],t[e+2]=Qt[2],t[e+3]=Qt[3]}function fa(r,t){return Qt[0]=r[t],Qt[1]=r[t+1],Qt[2]=r[t+2],Qt[3]=r[t+3],Fo[0]}var zo=new Float64Array([-0]),ut=new Uint8Array(zo.buffer);function la(r,t,e){zo[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function da(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],zo[0]}var Lf=BigInt(Number.MAX_SAFE_INTEGER),Cf=BigInt(Number.MIN_SAFE_INTEGER),xt=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 fe;if(t<Lf&&t>Cf)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>ha&&(s=0n,++n>ha&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return fe;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):fe}},fe=new xt(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.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 s,o=[],i=0,a;for(;t<e;)a=r[t++],a<128?o[i++]=a:a>191&&a<224?o[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,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Vo(r,t,e){let n=e,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function tn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Ho=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,Bt(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 Bt(this,4);return tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=fa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(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 Bt(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 Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(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 xt(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 Bt(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 Bt(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 Bt(this,8);let t=tn(this.buf,this.pos+=4),e=tn(this.buf,this.pos+=4);return new xt(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=qo(this.buf,this.pos);return this.pos+=gt(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 dr(r){return new Ho(r instanceof Uint8Array?r:r.subarray())}function Et(r,t,e){let n=dr(r);return t.decode(n,void 0,e)}function $o(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return pt(i);s+i>t&&(n=pt(t),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var le=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Go(){}var Yo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Tf=$o();function Rf(r){return globalThis.Buffer!=null?pt(r):Tf(r)}var pr=class{len;head;tail;states;constructor(){this.len=0,this.head=new le(Go,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new le(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(en,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(en,e.length(),e)}uint64Number(t){return this._push(Pe,gt(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=xt.fromBigInt(t).zzEncode();return this._push(en,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(en,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zo,1,t?1:0)}fixed32(t){return this._push(hr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(hr,4,e.lo)._push(hr,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push(hr,4,e.lo)._push(hr,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(Zo,1,0):this.uint32(e)._push(Of,e,t)}string(t){let e=pa(t);return e!==0?this.uint32(e)._push(Vo,e,t):this._push(Zo,1,0)}fork(){return this.states=new Yo(this),this.head=this.tail=new le(Go,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 le(Go,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=Rf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Zo(r,t,e){t[e]=r&255}function Pf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Xo=class extends le{next;constructor(t,e){super(Pf,t,e),this.next=void 0}};function en(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 hr(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 Of(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(pr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(kf,t,r),this},pr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Nf,t,r),this});function kf(r,t,e){t.set(r,e)}function Nf(r,t,e){r.length<40?Vo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(H(r),e)}function jo(){return new pr}function St(r,t){let e=jo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*vt(r,t,e){let n=dr(r);yield*t.stream(n,void 0,"$",e)}var rn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function nn(r,t,e,n,s){return{name:r,type:t,encode:e,decode:n,stream:s}}function de(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},s=function*(i){let a=i.int32();yield t(a)};return nn("enum",rn.VARINT,e,n,s)}function _t(r,t,e){return nn("message",rn.LENGTH_DELIMITED,r,t,e)}var mr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ht;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ht||(ht={}));var Wo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Wo||(Wo={}));(function(r){r.codec=()=>de(Wo)})(ht||(ht={}));var gr;(function(r){let t;r.codec=()=>(t==null&&(t=_t((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),ht.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=ht.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ht.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),t);function e(o){return St(o,r.codec())}r.encode=e;function n(o,i){return Et(o,r.codec(),i)}r.decode=n;function s(o,i){return vt(o,r.codec(),i)}r.stream=s})(gr||(gr={}));var Qo;(function(r){let t;r.codec=()=>(t==null&&(t=_t((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),ht.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=ht.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ht.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),t);function e(o){return St(o,r.codec())}r.encode=e;function n(o,i){return Et(o,r.codec(),i)}r.decode=n;function s(o,i){return vt(o,r.codec(),i)}r.stream=s})(Qo||(Qo={}));var on=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Fr(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,s=new Uint8Array(n);s.set(e.length>n?t.create().update(e).digest():e);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),Ut(s)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(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:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,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()}},Jo=(r,t,e)=>new on(r,t).update(e).digest();Jo.create=(r,t)=>new on(r,t);var ba=(r,t)=>(r+(r>=0?t:-t)/ya)/t;function Mf(r,t,e){let[[n,s],[o,i]]=t,a=ba(i*r,e),c=ba(-s*r,e),u=r-a*n-c*o,f=-a*s-c*i,l=u<zt,d=f<zt;l&&(u=-u),d&&(f=-f);let m=ar(Math.ceil(vo(e)/2))+Oe;if(u<zt||u>=m||f<zt||f>=m)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:l,k1:u,k2neg:d,k2:f}}function es(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ts(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Ft(e.lowS,"lowS"),Ft(e.prehash,"prehash"),e.format!==void 0&&es(e.format),e}var rs=class extends Error{constructor(t=""){super(t)}},Jt={Err:rs,_tlv:{encode:(r,t)=>{let{Err:e}=Jt;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,s=sr(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?sr(s.length/2|128):"";return sr(r)+o+s+t},decode(r,t){let{Err:e}=Jt,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 s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&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 f of u)i=i<<8|f;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}=Jt;if(r<zt)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}=Jt;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 De(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Jt,s=N(r,void 0,"signature"),{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:u,l:f}=n.decode(2,c);if(f.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}=Jt,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),o=n+s;return t.encode(48,o)}},zt=BigInt(0),Oe=BigInt(1),ya=BigInt(2),sn=BigInt(3),Kf=BigInt(4);function xa(r,t={}){let e=Zr("weierstrass",r,t),{Fp:n,Fn:s}=e,o=e.CURVE,{h:i,n:a}=o;jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Ea(n,s);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,g,b){let{x:p,y:_}=g.toAffine(),B=n.toBytes(p);if(Ft(b,"isCompressed"),b){f();let L=!n.isOdd(_);return mt(wa(L),B)}else return mt(Uint8Array.of(4),B,n.toBytes(_))}function d(C){N(C,void 0,"Point");let{publicKey:g,publicKeyUncompressed:b}=u,p=C.length,_=C[0],B=C.subarray(1);if(p===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)}f();let R=n.isOdd(D);return(_&1)===1!==R&&(D=n.neg(D)),{x:L,y:D}}else if(p===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 ${p}, expected compressed=${g} or uncompressed=${b}`)}let m=t.toBytes||l,h=t.fromBytes||d;function v(C){let g=n.sqr(C),b=n.mul(g,C);return n.add(n.add(b,n.mul(C,o.a)),o.b)}function x(C,g){let b=n.sqr(g),p=v(C);return n.eql(b,p)}if(!x(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(o.a,sn),Kf),A=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(y,A)))throw new Error("bad curve params: a or b");function w(C,g,b=!1){if(!n.isValid(g)||b&&n.is0(g))throw new Error(`bad point coordinate ${C}`);return g}function I(C){if(!(C instanceof E))throw new Error("Weierstrass Point expected")}function P(C){if(!c||!c.basises)throw new Error("no endo");return Mf(C,c.basises,s.ORDER)}let U=Le((C,g)=>{let{X:b,Y:p,Z:_}=C;if(n.eql(_,n.ONE))return{x:b,y:p};let B=C.is0();g==null&&(g=B?n.ONE:n.inv(_));let L=n.mul(b,g),T=n.mul(p,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=Le(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:b}=C.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(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function S(C,g,b,p,_){return b=new E(n.mul(b.X,C),b.Y,b.Z),g=ur(p,g),b=ur(_,b),g.add(b)}class E{static BASE=new E(o.Gx,o.Gy,n.ONE);static ZERO=new E(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(g,b,p){this.X=w("x",g),this.Y=w("y",b,!0),this.Z=w("z",p),Object.freeze(this)}static CURVE(){return o}static fromAffine(g){let{x:b,y:p}=g||{};if(!g||!n.isValid(b)||!n.isValid(p))throw new Error("invalid affine point");if(g instanceof E)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(p)?E.ZERO:new E(b,p,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(Kt(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(sn),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:p,Z:_}=this,{X:B,Y:L,Z:T}=g,D=n.eql(n.mul(b,T),n.mul(B,_)),R=n.eql(n.mul(p,T),n.mul(L,_));return D&&R}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b}=o,p=n.mul(b,sn),{X:_,Y:B,Z:L}=this,T=n.ZERO,D=n.ZERO,R=n.ZERO,k=n.mul(_,_),$=n.mul(B,B),z=n.mul(L,L),q=n.mul(_,B);return q=n.add(q,q),R=n.mul(_,L),R=n.add(R,R),T=n.mul(g,R),D=n.mul(p,z),D=n.add(T,D),T=n.sub($,D),D=n.add($,D),D=n.mul(T,D),T=n.mul(q,T),R=n.mul(p,R),z=n.mul(g,z),q=n.sub(k,z),q=n.mul(g,q),q=n.add(q,R),R=n.add(k,k),k=n.add(R,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),R=n.mul(z,$),R=n.add(R,R),R=n.add(R,R),new E(T,D,R)}add(g){I(g);let{X:b,Y:p,Z:_}=this,{X:B,Y:L,Z:T}=g,D=n.ZERO,R=n.ZERO,k=n.ZERO,$=o.a,z=n.mul(o.b,sn),q=n.mul(b,B),G=n.mul(p,L),rt=n.mul(_,T),Lt=n.add(b,p),Z=n.add(B,L);Lt=n.mul(Lt,Z),Z=n.add(q,G),Lt=n.sub(Lt,Z),Z=n.add(b,_);let it=n.add(B,T);return Z=n.mul(Z,it),it=n.add(q,rt),Z=n.sub(Z,it),it=n.add(p,_),D=n.add(L,T),it=n.mul(it,D),D=n.add(G,rt),it=n.sub(it,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),R=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),R=n.add(R,q),q=n.mul(it,Z),D=n.mul(Lt,D),D=n.sub(D,q),q=n.mul(Lt,G),k=n.mul(it,k),k=n.add(k,q),new E(D,R,k)}subtract(g){return this.add(g.negate())}is0(){return this.equals(E.ZERO)}multiply(g){let{endo:b}=t;if(!s.isValidNot0(g))throw new Error("invalid scalar: out of range");let p,_,B=L=>K.cached(this,L,T=>ue(E,T));if(b){let{k1neg:L,k1:T,k2neg:D,k2:R}=P(g),{p:k,f:$}=B(T),{p:z,f:q}=B(R);_=$.add(q),p=S(b.beta,k,z,L,D)}else{let{p:L,f:T}=B(g);p=L,_=T}return ue(E,[p,_])[0]}multiplyUnsafe(g){let{endo:b}=t,p=this;if(!s.isValid(g))throw new Error("invalid scalar: out of range");if(g===zt||p.is0())return E.ZERO;if(g===Oe)return p;if(K.hasCache(this))return this.multiply(g);if(b){let{k1neg:_,k1:B,k2neg:L,k2:T}=P(g),{p1:D,p2:R}=Wi(E,p,B,T);return S(b.beta,D,R,_,L)}else return K.unsafe(p,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 Ft(g,"isCompressed"),this.assertValidity(),m(E,this,g)}toHex(g=!0){return Mt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let O=s.BITS,K=new Re(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 qf(r,t={}){let{Fn:e}=r,n=t.randomBytes||Be,s=Object.assign(Ea(r.Fp,e),{seed:Bo(e.ORDER)});function o(m){try{let h=e.fromBytes(m);return e.isValidNot0(h)}catch{return!1}}function i(m,h){let{publicKey:v,publicKeyUncompressed:x}=s;try{let y=m.length;return h===!0&&y!==v||h===!1&&y!==x?!1:!!r.fromBytes(m)}catch{return!1}}function a(m=n(s.seed)){return Do(N(m,s.seed,"seed"),e.ORDER)}function c(m,h=!0){return r.BASE.multiply(e.fromBytes(m)).toBytes(h)}function u(m){let{secretKey:h,publicKey:v,publicKeyUncompressed:x}=s;if(!ne(m)||"_lengths"in e&&e._lengths||h===v)return;let y=N(m,void 0,"key").length;return y===v||y===x}function f(m,h,v=!0){if(u(m)===!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(m);return r.fromBytes(h).multiply(x).toBytes(v)}let l={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},d=Yr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:r,utils:l,lengths:s})}function Sa(r,t,e={}){Fr(t),jt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Be,s=e.hmac||((b,p)=>Jo(t,b,p)),{Fp:o,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:m}=qf(r,e),h={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},v=a*ya<o.ORDER;function x(b){let p=a>>Oe;return b>p}function y(b,p){if(!i.isValidNot0(p))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return p}function A(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(b,p){es(p);let _=m.signature,B=p==="compact"?_:p==="recovered"?_+1:void 0;return N(b,B)}class I{r;s;recovery;constructor(p,_,B){if(this.r=y("r",p),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(p,_=h.format){w(p,_);let B;if(_==="der"){let{r:R,s:k}=Jt.toSig(N(p));return new I(R,k)}_==="recovered"&&(B=p[0],_="compact",p=p.subarray(1));let L=m.signature/2,T=p.subarray(0,L),D=p.subarray(L,L*2);return new I(i.fromBytes(T),i.fromBytes(D),B)}static fromHex(p,_){return this.fromBytes(Kt(p),_)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new I(this.r,this.s,p)}recoverPublicKey(p){let{r:_,s:B}=this,L=this.assertRecovery(),T=L===2||L===3?_+a:_;if(!o.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=o.toBytes(T),R=r.fromBytes(mt(wa((L&1)===0),D)),k=i.inv(T),$=U(N(p,void 0,"msgHash")),z=i.create(-$*k),q=i.create(B*k),G=r.BASE.multiplyUnsafe(z).add(R.multiplyUnsafe(q));if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return x(this.s)}toBytes(p=h.format){if(es(p),p==="der")return Kt(Jt.hexFromSig(this));let{r:_,s:B}=this,L=i.toBytes(_),T=i.toBytes(B);return p==="recovered"?(A(),mt(Uint8Array.of(this.assertRecovery()),L,T)):mt(L,T)}toHex(p){return Mt(this.toBytes(p))}}let P=e.bits2int||function(p){if(p.length>8192)throw new Error("input is too large");let _=De(p),B=p.length*8-c;return B>0?_>>BigInt(B):_},U=e.bits2int_modN||function(p){return i.create(P(p))},M=ar(c);function S(b){return ir("num < 2^"+c,b,zt,M),i.toBytes(b)}function E(b,p){return N(b,void 0,"message"),p?N(t(b),void 0,"prehashed message"):b}function O(b,p,_){let{lowS:B,prehash:L,extraEntropy:T}=ts(_,h);b=E(b,L);let D=U(b),R=i.fromBytes(p);if(!i.isValidNot0(R))throw new Error("invalid private key");let k=[S(R),S(D)];if(T!=null&&T!==!1){let G=T===!0?n(m.secretKey):T;k.push(N(G,void 0,"extraEntropy"))}let $=mt(...k),z=D;function q(G){let rt=P(G);if(!i.isValidNot0(rt))return;let Lt=i.inv(rt),Z=r.BASE.multiply(rt).toAffine(),it=i.create(Z.x);if(it===zt)return;let Cr=i.create(Lt*i.create(z+it*R));if(Cr===zt)return;let Os=(Z.x===it?0:2)|Number(Z.y&Oe),ks=Cr;return B&&x(Cr)&&(ks=i.neg(Cr),Os^=1),new I(it,ks,v?void 0:Os)}return{seed:$,k2sig:q}}function K(b,p,_={}){let{seed:B,k2sig:L}=O(b,p,_);return Oi(t.outputLen,i.BYTES,s)(B,L).toBytes(_.format)}function C(b,p,_,B={}){let{lowS:L,prehash:T,format:D}=ts(B,h);if(_=N(_,void 0,"publicKey"),p=E(p,T),!ne(b)){let R=b instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}w(b,D);try{let R=I.fromBytes(b,D),k=r.fromBytes(_);if(L&&R.hasHighS())return!1;let{r:$,s:z}=R,q=U(p),G=i.inv(z),rt=i.create(q*G),Lt=i.create($*G),Z=r.BASE.multiplyUnsafe(rt).add(k.multiplyUnsafe(Lt));return Z.is0()?!1:i.create(Z.x)===$}catch{return!1}}function g(b,p,_={}){let{prehash:B}=ts(_,h);return p=E(p,B),I.fromBytes(b,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:m,Point:r,sign:K,verify:C,recoverPublicKey:g,Signature:I,hash:t})}var os={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ff={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var va=BigInt(2);function zf(r){let t=os.p,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,f=u*u*r%t,l=V(f,e,t)*f%t,d=V(l,e,t)*f%t,m=V(d,va,t)*u%t,h=V(m,s,t)*m%t,v=V(h,o,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)*f%t,I=V(w,i,t)*h%t,P=V(I,n,t)*u%t,U=V(P,va,t);if(!ns.eql(ns.sqr(U),r))throw new Error("Cannot find square root");return U}var ns=Ce(os.p,{sqrt:zf}),Vf=xa(os,{Fp:ns,endo:Ff}),ke=Sa(Vf,Ci);function _a(r,t,e,n){let s=Qe.digest(e instanceof Uint8Array?e:e.subarray());if(Qr(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),ke.verify(t,o,r,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new fr(String(o))});try{return n?.signal?.throwIfAborted(),ke.verify(t,s.digest,r,{prehash:!1,format:"der"})}catch(o){throw new fr(String(o))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=Ia(t),this.raw=Aa(this._key)}toMultihash(){return At.digest(Ae(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){return _a(this._key,e,t,n)}};function Ba(r){return new an(r)}function Aa(r){return ke.Point.fromBytes(r).toBytes()}function Ia(r){try{return ke.Point.fromBytes(r),r}catch(t){throw new Rr(String(t))}}function Da(r){let{Type:t,Data:e}=gr.decode(r.digest),n=e??new Uint8Array;switch(t){case ht.Ed25519:return ia(n);case ht.secp256k1:return Ba(n);case ht.ECDSA:return hi(n);default:throw new Ge}}function Ae(r){return gr.encode({Type:ht[r.type],Data:r.raw})}var La=Symbol.for("nodejs.util.inspect.custom"),Hf=114,br=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()})`}[Nn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Hf,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()})`}},cn=class extends br{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},un=class extends br{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},fn=class extends br{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},$f=2336,ln=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(H(this.url))}[La](){return`PeerId(${this.url})`}[Nn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1($f,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=W(t)),t.toString()===this.toString())}};function Ca(r){if(Zf(r))return new cn({multihash:r});if(Gf(r))try{let t=Da(r);if(t.type==="Ed25519")return new un({multihash:r,publicKey:t});if(t.type==="secp256k1")return new fn({multihash:r,publicKey:t})}catch{let e=W(r.digest);return new ln(new URL(e))}throw new Pr("Supplied PeerID Multihash is invalid")}function Gf(r){return r.code===At.code}function Zf(r){return r.code===Qe.code}function ss(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return e}function dn(r){let t=je(X.decode(`z${r}`));return Ca(t)}var hn=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 ss(this.set.entries(),t=>{let e=dn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=dn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return ss(this.set.values(),t=>dn(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 is(){return new hn}var as={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},Ra=new globalThis.TextEncoder;function Yf(r,t){let e=as[t],n=Ta[t];for(let s=0;s<r.length;s++)n^=BigInt(r[s]),n=BigInt.asUintN(t,n*e);return n}function Xf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=as[t],s=Ta[t],o=r;for(;o.length>0;){let i=Ra.encodeInto(o,e);o=o.slice(i.read);for(let a=0;a<i.written;a++)s^=BigInt(e[a]),s=BigInt.asUintN(t,s*n)}return s}function cs(r,{size:t=32,utf8Buffer:e}={}){if(!as[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 Xf(r,t,e);r=Ra.encode(r)}return Yf(r,t)}var yr={hash:r=>Number(cs(r,{size:32})),hashV:(r,t)=>jf(yr.hash(r,t))};function jf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),H(t,"base16")}var us=64,Dt=class{fp;h;seed;constructor(t,e,n,s=2){if(s>us)throw new TypeError("Invalid Fingerprint Size");let o=e.hashV(t,n),i=yt(s);for(let a=0;a<i.length;a++)i[a]=o[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 he(r,t){return Math.floor(Math.random()*(t-r))+r}var pe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Dt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Dt))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 Dt))throw new TypeError("Invalid Fingerprint");let e=he(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Dt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Wf=500,xr=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??yr,this.seed=t.seed??he(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=H(t));let e=new Dt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,s=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new pe(this.bucketSize)),this.buckets[s]==null&&(this.buckets[s]=new pe(this.bucketSize)),this.buckets[n].add(e)||this.buckets[s].add(e))return this.count++,!0;let o=[n,s],i=o[he(0,o.length-1)];this.buckets[i]==null&&(this.buckets[i]=new pe(this.bucketSize));for(let a=0;a<Wf;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 pe(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=H(t));let e=new Dt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,s=this.buckets[n]?.has(e)??!1;if(s)return s;let o=(n^e.hash())%this.filterSize;return this.buckets[o]?.has(e)??!1}remove(t){typeof t=="string"&&(t=H(t));let e=new Dt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,s=this.buckets[n]?.remove(e)??!1;if(s)return this.count--,s;let o=(n^e.hash())%this.filterSize,i=this.buckets[o]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Qf={1:.5,2:.84,4:.95,8:.98};function Jf(r=.001){return r>.002?2:r>1e-5?4:8}function Pa(r,t=.001){let e=Jf(t),n=Qf[e],s=Math.round(r/n),o=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),us);return{filterSize:s,bucketSize:e,fingerprintSize:o}}var pn=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??yr,this.seed=t.seed??he(0,Math.pow(2,10)),this.filterSeries=[new xr({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 xr({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 fs(r,t=.001,e){return new pn({...Pa(r,t),...e??{}})}function te(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 mn=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,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(o*=t,o+=f,o>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:o})}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 s=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[s]=i[0],e[s+1]=i[1],e[s+2]=i[2],e[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];e[s]=o>>8,e[s+1]=o&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,s]=t(e);if(n===16)return e;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=t(o.subarray(0,i));return e.set(o.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Oa=45,tl=15,Ne=new mn;function gn(r){if(!(r.length>tl))return Ne.new(r).parseWith(()=>Ne.readIPv4Addr())}function bn(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 s of r)if(!(n<t)){if(n>e)break;if(s!==255)return!1;n++}return!0}function Na(r,t,e,n){let s=0;for(let o of r)if(!(s<e)){if(s>n)break;if(o!==t[s])return!1;s++}return!0}function ls(r){switch(r.length){case me:return r.join(".");case ge:{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 s=e+1;s<r.length;s++)if(r[s]!=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 me=4,ge=16,Jg=parseInt("0xFFFF",16),el=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function wr(r,t){t.length===ge&&r.length===me&&ka(t,0,11)&&(t=t.slice(12)),t.length===me&&r.length===ge&&Na(r,el,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 s=0;s<e;s++)n[s]=r[s]&t[s];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 ds(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=me,s=gn(t);if(s==null&&(n=ge,s=bn(t),s==null))throw new Error("Failed to parse given CIDR: "+r);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=hs(o,8*n);return{network:wr(s,i),mask:i}}function hs(r,t){if(t!==8*me&&t!==8*ge)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 s=0;s<e;s++){if(r>=8){n[s]=255,r-=8;continue}n[s]=255-(255>>r),r=0}return n}var Er=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=ds(t));else{let n=Ue(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n.length*8){let o=Ue(e);if(o==null)throw new Error("Failed to parse mask");this.mask=o}else this.mask=hs(s,8*n.length);this.network=wr(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 ls(this.network)+"/"+e}};function qa(r,t){return new Er(r).contains(t)}function Fa(r){try{let t=te(r);switch(t.type){case"ip6":return qa("2000::/3",t.host);default:return!1}}catch{return!1}}function Me(r){return!!gn(r)}function yn(r){return!!bn(r)}var Va=_c(za(),1),rl=["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"],nl=rl.map(r=>new Va.Netmask(r));function ps(r){for(let t of nl)if(t.contains(r))return!0;return!1}function ol(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function sl(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"),s=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return ps(s)}function il(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function al(r){let t=r.split(":"),e=t[t.length-1];return ps(e)}function cl(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 xn(r){if(Me(r))return ps(r);if(ol(r))return sl(r);if(il(r))return al(r);if(yn(r))return cl(r)}function Ha(r){try{let t=te(r);switch(t.type){case"ip4":case"ip6":return xn(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 wn=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 wn(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 wn(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 ms=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function En(r={}){return ul(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 ul(r,t){t=t??{};let e=t.onEnd,n=new qe,s,o,i,a=Ke(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,y)=>{o=A=>{o=null,n.push(A);try{x(r(n))}catch(w){y(w)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ke()})}},u=x=>o!=null?o(x):(n.push(x),s),f=x=>(n=new qe,o!=null?o({error:x}):(n.push({error:x}),s)),l=x=>{if(i)return s;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?s:(i=!0,x!=null?f(x):u({done:!0})),m=()=>(n=new qe,d(),{done:!0}),h=x=>(d(x),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:m,throw:h,push:l,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 ms)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,A])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},e==null)return s;let v=s;return s={[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:l,end(x){return v.end(x),e!=null&&(e(x),e=void 0),s},get readableLength(){return v.readableLength},onEmpty:x=>v.onEmpty(x)},s}var gs=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},$a=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function bs(r,t){let{milliseconds:e,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=t,a,c,f=new Promise((l,d)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){d($a(i));return}if(i&&(c=()=>{d($a(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,d),e===Number.POSITIVE_INFINITY)return;let m=new gs;a=o.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(h){d(h)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?l():s instanceof Error?d(s):(m.message=s??`Promise timed out after ${e} milliseconds`,d(m))},e)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var fl=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 ll(r,t,e){let n,s=new Promise((o,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:f}=fl(r),l=async(...m)=>{let h=e.multiArgs?m:m[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(),o(c))},d=(...m)=>{n(),i(e.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of a)f(m,l);for(let m of e.rejectionEvents)a.includes(m)||f(m,d)};for(let m of a)u(m,l);for(let m of e.rejectionEvents)a.includes(m)||u(m,d);e.signal&&e.signal.addEventListener("abort",()=>{d(e.signal.reason)},{once:!0}),e.resolveImmediately&&o(c)});if(s.cancel=n,typeof e.timeout=="number"){let o=bs(s,{milliseconds:e.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function Fe(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=ll(r,t,e),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}function vr(r,t){let e,n=function(){let s=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(s,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Sn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},be=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function dl(r){return r.reason}async function _r(r,t,e){if(t==null)return r;let n=e?.translateError??dl;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([r,new Promise((o,i)=>{s=()=>{i(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var vn=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 Pt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function hl(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var _n=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=hl(),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 Pt),this.cleanup())}async join(t={}){let e=new vn(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 _r(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 An=class extends Or{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=vr(this.emitEmpty.bind(this),1),this.emitIdle=vr(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 Sn;let n=new _n(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(e).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let o=0;o<this.queue.length;o++)if(this.queue[o]===n){this.queue.splice(o,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Pt)}),this.clear()}async onEmpty(t){this.size!==0&&await 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=En({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},s=c=>{c.detail!=null&&e.push(c.detail)},o=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Pt("Queue aborted"))};this.addEventListener("completed",s),this.addEventListener("failure",o),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",s),this.removeEventListener("failure",o),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function Ar(r){let t=new globalThis.AbortController;function e(){let o=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(o);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let o of r){if(o?.aborted===!0){e();break}o?.addEventListener!=null&&o.addEventListener("abort",e)}function n(){for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",e)}let s=t.signal;return s.clear=n,s}var ot=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Vt=class extends Error{static name="ValidationError";name="ValidationError"},In=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Bn=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 ye(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Ga(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 s=ye(n);return kt([e,s],e.length+s.length)}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!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Gt.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 s=ye(n);return kt([e,s],e.length+s.length)}function Es(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=W(t,"base32"),s=ze(e);return`${n}:${s}`}var Ss=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let s=parseInt(e,10);if(isNaN(s)||s<0||s>255)throw new ot("Invalid byte value in IP address");t[n]=s}),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 o=Me(e[n]),i;o&&(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 o=[n,1];for(n=9-e.length;n>0;n--)o.push("0");e.splice.apply(e,o)}let s=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let o=parseInt(e[n],16);if(isNaN(o)||o<0||o>65535)throw new ot("Invalid byte value in IP address");s[t++]=o>>8&255,s[t++]=o&255}return s},Xa=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(".")},ja=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 s=r[n],o=r[n+1],i=`${s.toString(16).padStart(2,"0")}${o.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 Wa(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),pl=(function(){let r=ys[0].or(ys[1]);return ys.slice(2).forEach(t=>r=r.or(t)),r})();function Qa(r){return pl.decode(r)}function Ja(r){return t=>r.encoder.encode(t)}function ml(r){if(parseInt(r).toString()!==r)throw new Vt("Value must be an integer")}function gl(r){if(r<0)throw new Vt("Value must be a positive integer, or zero")}function bl(r){return t=>{if(t>r)throw new Vt(`Value must be smaller than or equal to ${r}`)}}function yl(...r){return t=>{for(let e of r)e(t)}}var Ir=yl(ml,gl,bl(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 Bn(`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)}))}},Ht=new vs,nd=[{code:4,name:"ip4",size:32,valueToBytes:Ss,bytesToValue:Xa,validate:r=>{if(!Me(r))throw new Vt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Ir},{code:273,name:"udp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Ir},{code:33,name:"dccp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Ir},{code:41,name:"ip6",size:128,valueToBytes:Ya,bytesToValue:ja,stringToValue:Wa,validate:r=>{if(!yn(r))throw new Vt(`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:ye,bytesToValue:ze,validate:Ir},{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):at.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Es,valueToBytes:Ga},{code:445,name:"onion3",size:296,bytesToValue:Es,valueToBytes:Za},{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:Ja(Wn),valueToBytes:Qa},{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}];nd.forEach(r=>{Ht.addProtocol(r)});function tc(r){let t=[],e=0;for(;e<r.length;){let n=lr(r,e),s=Ht.getProtocol(n),o=gt(n),i=od(s,r,e+o),a=0;i>0&&s.size===et&&(a=gt(i));let c=o+a+i,u={code:n,name:s.name,bytes:r.subarray(e,e+c)};if(i>0){let f=e+o+a,l=r.subarray(f,f+i);u.value=s.bytesToValue?.(l)??W(l)}t.push(u),e+=c}return t}function ec(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let s=Ht.getProtocol(n.code),o=gt(n.code),i,a=0,c=0;n.value!=null&&(i=s.valueToBytes?.(n.value)??H(n.value),a=i.byteLength,s.size===et&&(c=gt(a)));let u=new Uint8Array(o+c+a),f=0;Pe(n.code,u,f),f+=o,i!=null&&(s.size===et&&(Pe(a,u,f),f+=c),u.set(i,f)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return kt(e,t)}function rc(r){if(r.charAt(0)!=="/")throw new ot('String multiaddr must start with "/"');let t=[],e="protocol",n="",s="";for(let o=1;o<r.length;o++){let i=r.charAt(o);i!=="/"&&(e==="protocol"?s+=r.charAt(o):n+=r.charAt(o));let a=o===r.length-1;if(i==="/"||a){let c=Ht.getProtocol(s);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",s="",e="protocol";continue}else if(a)throw new ot(`Component ${s} 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 ${s} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",s="",e="protocol"}}}if(s!==""&&n!=="")throw new ot("Incomplete multiaddr");return t}function nc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Ht.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 od(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:lr(t,e)}var sd=Symbol.for("nodejs.util.inspect.custom"),Is=Symbol.for("@multiformats/multiaddr");function id(r){if(r==null&&(r="/"),oc(r))return r.getComponents();if(r instanceof Uint8Array)return tc(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),rc(r);if(Array.isArray(r))return r;throw new ot("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Dn=class r{[Is]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=id(t),e.validate!==!1&&ad(this)}get bytes(){return this.#r==null&&(this.#r=ec(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=nc(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(),s=n.lastIndexOf(e);if(s<0)throw new In(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,s),{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)}[sd](){return`Multiaddr(${this.toString()})`}};function ad(r){r.getComponents().forEach(t=>{let e=Ht.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function oc(r){return!!r?.[Is]}function sc(r){return new Dn(r)}var cd=4194304,Ln=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"},Cs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ud(r){return typeof r?.closeRead=="function"}function fd(r){return typeof r?.close=="function"}function Bs(r){return ud(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:fd(r)?r.status!=="open":!1}function ld(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function dd(r,t){let e=t?.maxBufferSize??cd,n=new Q,s,o=!1;if(!ld(r))throw new ft("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>e){let l=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${l} > ${e}`))}s?.resolve()};r.addEventListener("message",i);let a=f=>{f.error!=null?s?.reject(f.error):s?.resolve()};r.addEventListener("close",a);let c=()=>{s?.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(o===!0)throw new Ln("Stream was unwrapped");if(Bs(r)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new be(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=l){s.resolve();break}if(await _r(s.promise,f?.signal),Bs(r)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let d=f?.bytes??n.byteLength;if(n.byteLength<d){if(Bs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new be(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(f)}let m=n.sublist(0,d);return n.consume(d),m},async write(f,l){if(o===!0)throw new Ln("Stream was unwrapped");r.send(f)||await Fe(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!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 hd(r,t={}){let e=dd(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=gt(t.maxDataLength));let n=t?.lengthDecoder??lr,s=t?.lengthEncoder??aa;return{async read(i){let a=-1,c=new Q;for(;;){let f=await e.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Ds("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Cs(`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 be(`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 be(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new Q(s(i.byteLength),i),a)},async writeV(i,a){let c=new Q(...i.flatMap(u=>[s(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function Ve(r,t){let e=hd(r,t),n={read:async(s,o)=>{let i=await e.read(o);return s.decode(i)},write:async(s,o,i)=>{await e.write(o.encode(s),i)},writeV:async(s,o,i)=>{await e.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Cn=class extends An{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function ic(r,t,e){let n,s,o=!1;function i(){let u={signal:s.signal},f;e?.timeout!=null&&(f=Ar([s.signal,AbortSignal.timeout(e.timeout)]),u.signal=f),o=!0,Promise.resolve().then(async()=>{await r(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),o=!1,!s.signal.aborted&&(n=setTimeout(i,t))})}let a=vr(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:()=>{o||(clearTimeout(n),a())},start:()=>{c||(c=!0,s=new AbortController,s.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),s?.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 ac(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ts({name:t,metrics:e}):n=new Map,n}var Rs="libp2p",Ps="autonat";var cc="dial-request",uc="dial-back",fc=200n*1024n,lc=4096;var He;(function(r){let t;r.codec=()=>(t==null&&(t=_t((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o={...o},o.dialDataResponse!=null&&(o.dialDataRequest=void 0,o.dialResponse=void 0,o.dialRequest=void 0),o.dialDataRequest!=null&&(o.dialDataResponse=void 0,o.dialResponse=void 0,o.dialRequest=void 0),o.dialResponse!=null&&(o.dialDataResponse=void 0,o.dialDataRequest=void 0,o.dialRequest=void 0),o.dialRequest!=null&&(o.dialDataResponse=void 0,o.dialDataRequest=void 0,o.dialResponse=void 0),o.dialRequest!=null&&(i.uint32(10),Br.codec().encode(o.dialRequest,i)),o.dialResponse!=null&&(i.uint32(18),Rt.codec().encode(o.dialResponse,i)),o.dialDataRequest!=null&&(i.uint32(26),Dr.codec().encode(o.dialDataRequest,i)),o.dialDataResponse!=null&&(i.uint32(34),Lr.codec().encode(o.dialDataResponse,i)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.dialRequest=Br.codec().decode(o,o.uint32(),{limits:a.limits?.dialRequest});break}case 2:{c.dialResponse=Rt.codec().decode(o,o.uint32(),{limits:a.limits?.dialResponse});break}case 3:{c.dialDataRequest=Dr.codec().decode(o,o.uint32(),{limits:a.limits?.dialDataRequest});break}case 4:{c.dialDataResponse=Lr.codec().decode(o,o.uint32(),{limits:a.limits?.dialDataResponse});break}default:{o.skipType(f&7);break}}}return c.dialDataResponse!=null&&(delete c.dialDataRequest,delete c.dialResponse,delete c.dialRequest),c.dialDataRequest!=null&&(delete c.dialDataResponse,delete c.dialResponse,delete c.dialRequest),c.dialResponse!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialRequest),c.dialRequest!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialResponse),c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield*Br.codec().stream(o,o.uint32(),`${a}.dialRequest`,{limits:c.limits?.dialRequest});break}case 2:{yield*Rt.codec().stream(o,o.uint32(),`${a}.dialResponse`,{limits:c.limits?.dialResponse});break}case 3:{yield*Dr.codec().stream(o,o.uint32(),`${a}.dialDataRequest`,{limits:c.limits?.dialDataRequest});break}case 4:{yield*Lr.codec().stream(o,o.uint32(),`${a}.dialDataResponse`,{limits:c.limits?.dialDataResponse});break}default:{o.skipType(f&7);break}}}})),t);function e(o){return St(o,r.codec())}r.encode=e;function n(o,i){return Et(o,r.codec(),i)}r.decode=n;function s(o,i){return vt(o,r.codec(),i)}r.stream=s})(He||(He={}));var Br;(function(r){let t;r.codec=()=>(t==null&&(t=_t((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.addrs!=null&&o.addrs.length>0)for(let c of o.addrs)i.uint32(10),i.bytes(c);o.nonce!=null&&o.nonce!==0n&&(i.uint32(17),i.fixed64(o.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={addrs:[],nonce:0n},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.addrs!=null&&c.addrs.length===a.limits.addrs)throw new mr('Decode error - repeated field "addrs" had too many elements');c.addrs.push(o.bytes());break}case 2:{c.nonce=o.fixed64();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={addrs:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{if(c.limits?.addrs!=null&&u.addrs===c.limits.addrs)throw new mr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${a}.addrs[]`,index:u.addrs,value:o.bytes()},u.addrs++;break}case 2:{yield{field:`${a}.nonce`,value:o.fixed64()};break}default:{o.skipType(l&7);break}}}})),t);function e(o){return St(o,r.codec())}r.encode=e;function n(o,i){return Et(o,r.codec(),i)}r.decode=n;function s(o,i){return vt(o,r.codec(),i)}r.stream=s})(Br||(Br={}));var Dr;(function(r){let t;r.codec=()=>(t==null&&(t=_t((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.addrIdx!=null&&o.addrIdx!==0&&(i.uint32(8),i.uint32(o.addrIdx)),o.numBytes!=null&&o.numBytes!==0n&&(i.uint32(16),i.uint64(o.numBytes)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={addrIdx:0,numBytes:0n},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.addrIdx=o.uint32();break}case 2:{c.numBytes=o.uint64();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.addrIdx`,value:o.uint32()};break}case 2:{yield{field:`${a}.numBytes`,value:o.uint64()};break}default:{o.skipType(f&7);break}}}})),t);function e(o){return St(o,r.codec())}r.encode=e;function n(o,i){return Et(o,r.codec(),i)}r.decode=n;function s(o,i){return vt(o,r.codec(),i)}r.stream=s})(Dr||(Dr={}));var st;(function(r){r.UNUSED="UNUSED",r.E_DIAL_ERROR="E_DIAL_ERROR",r.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",r.OK="OK"})(st||(st={}));var Tn;(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"})(Tn||(Tn={}));(function(r){r.codec=()=>de(Tn)})(st||(st={}));var Rt;(function(r){let t;(function(a){a.E_INTERNAL_ERROR="E_INTERNAL_ERROR",a.E_REQUEST_REJECTED="E_REQUEST_REJECTED",a.E_DIAL_REFUSED="E_DIAL_REFUSED",a.OK="OK"})(t=r.ResponseStatus||(r.ResponseStatus={}));let e;(function(a){a[a.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",a[a.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",a[a.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",a[a.OK=200]="OK"})(e||(e={})),(function(a){a.codec=()=>de(e)})(t=r.ResponseStatus||(r.ResponseStatus={}));let n;r.codec=()=>(n==null&&(n=_t((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&e[a.status]!==0&&(c.uint32(8),r.ResponseStatus.codec().encode(a.status,c)),a.addrIdx!=null&&a.addrIdx!==0&&(c.uint32(16),c.uint32(a.addrIdx)),a.dialStatus!=null&&Tn[a.dialStatus]!==0&&(c.uint32(24),st.codec().encode(a.dialStatus,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:st.UNUSED},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{f.status=r.ResponseStatus.codec().decode(a);break}case 2:{f.addrIdx=a.uint32();break}case 3:{f.dialStatus=st.codec().decode(a);break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{yield{field:`${u}.status`,value:r.ResponseStatus.codec().decode(a)};break}case 2:{yield{field:`${u}.addrIdx`,value:a.uint32()};break}case 3:{yield{field:`${u}.dialStatus`,value:st.codec().decode(a)};break}default:{a.skipType(d&7);break}}}})),n);function s(a){return St(a,r.codec())}r.encode=s;function o(a,c){return Et(a,r.codec(),c)}r.decode=o;function i(a,c){return vt(a,r.codec(),c)}r.stream=i})(Rt||(Rt={}));var Lr;(function(r){let t;r.codec=()=>(t==null&&(t=_t((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.data!=null&&o.data.byteLength>0&&(i.uint32(10),i.bytes(o.data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={data:yt(0)},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),t);function e(o){return St(o,r.codec())}r.encode=e;function n(o,i){return Et(o,r.codec(),i)}r.decode=n;function s(o,i){return vt(o,r.codec(),i)}r.stream=s})(Lr||(Lr={}));var $e;(function(r){let t;r.codec=()=>(t==null&&(t=_t((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.nonce!=null&&o.nonce!==0n&&(i.uint32(9),i.fixed64(o.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={nonce:0n},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.nonce=o.fixed64();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.nonce`,value:o.fixed64()};break}default:{o.skipType(f&7);break}}}})),t);function e(o){return St(o,r.codec())}r.encode=e;function n(o,i){return Et(o,r.codec(),i)}r.decode=n;function s(o,i){return vt(o,r.codec(),i)}r.stream=s})($e||($e={}));var ee;(function(r){let t;(function(a){a.OK="OK"})(t=r.DialBackStatus||(r.DialBackStatus={}));let e;(function(a){a[a.OK=0]="OK"})(e||(e={})),(function(a){a.codec=()=>de(e)})(t=r.DialBackStatus||(r.DialBackStatus={}));let n;r.codec=()=>(n==null&&(n=_t((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&e[a.status]!==0&&(c.uint32(8),r.DialBackStatus.codec().encode(a.status,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.OK},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{f.status=r.DialBackStatus.codec().decode(a);break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{yield{field:`${u}.status`,value:r.DialBackStatus.codec().decode(a)};break}default:{a.skipType(d&7);break}}}})),n);function s(a){return St(a,r.codec())}r.encode=s;function o(a,c){return Et(a,r.codec(),c)}r.decode=o;function i(a,c){return vt(a,r.codec(),c)}r.stream=i})(ee||(ee={}));function Rn(r,t){return Math.round(Math.random()*(t-r)+r)}var md=4,gd=8,Pn=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=ac({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=ic(this.findRandomPeers.bind(this),6e4),this.addressFilter=fs(1024),this.queue=new Cn({concurrency:3,maxSize:50}),this.maxDialDataBytes=e.maxDialDataBytes??fc,this.dialDataChunkSize=e.dialDataChunkSize??lc,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[kr]=["@libp2p/autonat"];get[Nr](){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=Ar([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(s=>s.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 s=Ve(t,{maxDataLength:this.maxMessageSize});try{let o=await s.read($e,{signal:n});if(!this.nonces.has(o.nonce))throw new wt("No matching dial found for nonce value");this.nonces.delete(o.nonce),await s.write({status:ee.DialBackStatus.OK},ee),await t.close({signal:n})}catch(o){this.log.error("error handling incoming dial back stream - %e",o),t.abort(o)}}getUnverifiedMultiaddrs(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,i)=>o.type==="observed"&&i.type!=="observed"?1:i.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||te(o.multiaddr).type==="ip6"&&(!e||!Fa(o.multiaddr))||Ha(o.multiaddr))),s=[];for(let o of n){let i=o.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=o.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:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:is(),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(i,a)}s.push(a)}return s}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})=>te(i).type==="ip6"),s=this.getNetworkSegment(t.remoteAddr),o=this.getUnverifiedMultiaddrs(s,n);if(o.length!==0){if(!this.hasConnectionCapacity()){o[0]?.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",o[0].multiaddr),this.confirmAddress(o[0])):this.log("skipping verifying %a because we are too close to the connection limit",o[0]?.multiaddr);return}this.queue.add(async i=>{let a=Ar([i.signal,AbortSignal.timeout(this.timeout)]),c=BigInt(Rn(0,Number.MAX_SAFE_INTEGER));this.nonces.add(c);try{await this.askPeerToVerify(t,s,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,s){let o=[...this.dialResults.values()].filter(a=>a.result==null).map(a=>a.multiaddr);if(o.length===0){this.queue.clear();return}this.log.trace("asking %a to verify multiaddrs %s",t.remoteAddr,o);let i=await t.newStream(this.dialRequestProtocol,s);try{let a=Ve(i).pb(He);await a.write({dialRequest:{addrs:o.map(c=>c.bytes),nonce:n}},s);for(let c=0;c<o.length;c++){let u=await a.read(s);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 m=new Uint8Array(this.dialDataChunkSize),h=BigInt(this.dialDataChunkSize);for(let v=0n;v<u.dialDataRequest.numBytes;v+=h)await a.write({dialDataResponse:{data:m}},s);u=await a.read(s)}if(u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}if(u.dialResponse.status!==Rt.ResponseStatus.OK)return;let l=o[u.dialResponse.addrIdx];if(l==null){this.log.trace("peer dialed unknown address");continue}let d=this.dialResults.get(l.toString());if(d==null){this.log.trace("peer reported %a as %s but there is no result object",l,u.dialResponse.status);continue}if(d.networkSegments.includes(e)){this.log.trace("%a results already included network segment %s",l,e);continue}if(d.result!=null){this.log.trace("already resolved result for %a, ignoring response from",l,t.remotePeer);continue}if(d.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,l);continue}if(d.verifyingPeers.add(t.remotePeer),d.networkSegments.push(e),u.dialResponse.dialStatus===st.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===st.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,d.multiaddr),d.failure++;else if(u.dialResponse.dialStatus===st.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===md&&this.confirmAddress(d),d.failure===gd&&this.unconfirmAddress(d)}}finally{try{await i.close(s)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0}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=te(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 On=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 s=Ve(t,{maxDataLength:this.maxMessageSize}).pb(He),o=gc(e.remoteAddr);if(o==null)throw new wt(`Could not find IP address in connection address "${e.remoteAddr}"`);let{dialRequest:i}=await s.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=sc(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await s.write({dialResponse:{addrIdx:a,status:Rt.ResponseStatus.E_DIAL_REFUSED,dialStatus:st.UNUSED}},{signal:n});continue}let f=gc(c);if(f==null)throw new wt(`Could not find IP address in requested address "${c}"`);if(xn(f))throw new wt(`Requested address had private IP "${c}"`);f!==o&&await this.preventAmplificationAttack(s,a,{signal:n});let l=await this.dialClientBack(c,i.nonce,{signal:n});await s.write({dialResponse:{addrIdx:a,status:Rt.ResponseStatus.OK,dialStatus:l}},{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 s=Rn(3e4,1e5);await t.write({dialDataRequest:{addrIdx:e,numBytes:BigInt(s)}},n);let o=0;for(;o<s;){let{dialDataResponse:i}=await t.read(n);if(i==null)throw new wt("Did not receive DialDataResponse message on incoming dial request stream");o+=i.data.byteLength}}async dialClientBack(t,e,n){let s;try{s=await this.components.connectionManager.openConnection(t,{force:!0,...n})}catch(o){return this.log.error("failed to open connection to %a - %e",t,o),st.E_DIAL_ERROR}try{let o=await s.newStream(this.dialBackProtocol,n),i=Ve(o,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:e},$e,n),(await i.read(ee,n)).status!==ee.DialBackStatus.OK)throw new wt("DialBackResponse status was not OK");await s.close(n)}catch(o){return this.log.error("could not perform dial back - %e",o),s.abort(o),st.E_DIAL_BACK_ERROR}return st.OK}};function gc(r){return r.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var kn=class{client;server;constructor(t,e){let n=`/${e.protocolPrefix??Rs}/${Ps}/${"2"}/${cc}`,s=`/${e.protocolPrefix??Rs}/${Ps}/${"2"}/${uc}`;this.client=new Pn(t,{...e,dialRequestProtocol:n,dialBackProtocol:s}),this.server=new On(t,{...e,dialRequestProtocol:n,dialBackProtocol:s})}[Symbol.toStringTag]="@libp2p/autonat-v2";[kr]=["@libp2p/autonat"];get[Nr](){return["@libp2p/identify"]}async start(){await Ms(this.client,this.server)}async stop(){await Ks(this.client,this.server)}};function bd(r={}){return t=>new kn(t,r)}return Ac(yd);})();
2
+ "use strict";var Libp2PAutonatV2=(()=>{var iu=Object.create;var Gr=Object.defineProperty;var au=Object.getOwnPropertyDescriptor;var cu=Object.getOwnPropertyNames;var uu=Object.getPrototypeOf,fu=Object.prototype.hasOwnProperty;var ao=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)Gr(r,e,{get:t[e],enumerable:!0})},xi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of cu(t))!fu.call(r,o)&&o!==e&&Gr(r,o,{get:()=>t[o],enumerable:!(n=au(t,o))||n.enumerable});return r};var lu=(r,t,e)=>(e=r!=null?iu(uu(r)):{},xi(t||!r||!r.__esModule?Gr(e,"default",{value:r,enumerable:!0}):e,r)),du=r=>xi(Gr({},"__esModule",{value:!0}),r);var js=ao(We=>{"use strict";Object.defineProperty(We,"__esModule",{value:!0});We.Netmask4Impl=void 0;We.ip2long=Xe;We.long2ip=Nt;function Nt(r){let t=(r&-16777216)>>>24,e=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[t,e,n,o].join(".")}var Xl=48,Wl=97,Ql=65;function Jl(r){let t=0,e=10,n="9",o=0;r.length>1&&r[o]==="0"&&(r[o+1]==="x"||r[o+1]==="X"?(o+=2,e=16):"0"<=r[o+1]&&r[o+1]<="9"&&(o++,e=8,n="7"));let s=o;for(;o<r.length;){if("0"<=r[o]&&r[o]<=n)t=t*e+(r.charCodeAt(o)-Xl)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-Wl)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.charCodeAt(o)-Ql)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function Xe(r){let t=[];for(let e=0;e<=3&&r.length!==0;e++){if(e>0){if(r[0]!==".")throw new Error("Invalid IP");r=r.substring(1)}let[n,o]=Jl(r);r=r.substring(o),t.push(n)}if(r.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var $s=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=Xe(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(Xe(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Nt(this.netLong),this.mask=Nt(this.maskLong),this.hostmask=Nt(~this.maskLong),this.first=this.bitmask<=30?Nt(this.netLong+1):this.base,this.last=this.bitmask<=30?Nt(this.netLong+this.size-2):Nt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Nt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):(Xe(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(Nt(this.netLong+this.size*t),this.mask)}forEach(t){let e=Xe(this.first),n=Xe(this.last),o=0;for(;e<=n;)t(Nt(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};We.Netmask4Impl=$s});var Dc=ao(Qe=>{"use strict";Object.defineProperty(Qe,"__esModule",{value:!0});Qe.Netmask6Impl=void 0;Qe.ip6bigint=Gs;Qe.bigint2ip6=Ie;var td=js(),Zs=(1n<<128n)-1n;function Gs(r){let t=r.indexOf("%");t!==-1&&(r=r.substring(0,t));let e=r.lastIndexOf(":");if(e!==-1&&r.indexOf(".",e)!==-1){let n=r.substring(e+1),o=(0,td.ip2long)(n),s=r.substring(0,e+1)+"0:0";return Tc(s)&~0xffffffffn|BigInt(o)}return Tc(r)}function Tc(r){let t=r.indexOf("::"),e;if(t!==-1){let o=r.substring(0,t),s=r.substring(t+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");e=[...i,...Array(c).fill("0"),...a]}else e=r.split(":");if(e.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+e.length);let n=0n;for(let o=0;o<8;o++){let s=e[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Ie(r){if(r<0n||r>Zs)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(r&0xffffn)),r>>=16n;let e=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(e=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(e=o,n=s),e!==-1&&e+n===8&&e>0)return t.slice(0,e).map(a=>a.toString(16)).join(":")+"::";if(e===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(e>0){let i=t.slice(0,e).map(c=>c.toString(16)),a=t.slice(e+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var Ys=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Zs>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Gs(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Ie(this.netBigint),this.mask=Ie(this.maskBigint),this.hostmask=Ie(~this.maskBigint&Zs),this.first=this.base,this.last=Ie(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.last):(Gs(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(Ie(this.netBigint+e*BigInt(t)),this.bitmask)}forEach(t){let e=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;e<=o;)t(Ie(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};Qe.Netmask6Impl=Ys});var Lc=ao(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.long2ip=ce.ip2long=ce.Netmask=void 0;var Vn=js();Object.defineProperty(ce,"ip2long",{enumerable:!0,get:function(){return Vn.ip2long}});Object.defineProperty(ce,"long2ip",{enumerable:!0,get:function(){return Vn.long2ip}});var ed=Dc(),Xs=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new ed.Netmask6Impl(t,e):this._impl=new Vn.Netmask4Impl(t,e),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Vn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new r(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new r(t))),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let e=this._impl.next(t);return new r(e.base,e.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ce.Netmask=Xs});var yh={};bt(yh,{autoNATv2:()=>bh});var Mt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var lt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Yr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Xr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Et=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var ar=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var co=Symbol.for("@libp2p/peer-id");function wi(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Ei(...r){let t=[];for(let e of r)wi(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 Si(...r){let t=[];for(let e of r)wi(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()}))}function hu(r){return typeof r?.handleEvent=="function"}function pu(r){return(r!==!0&&r!==!1&&r?.once)??!1}var Wr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){let o=pu(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==e),this.#t.set(i.type,a))}hu(e)?e.handleEvent(i):e(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:o})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Qr=Symbol.for("@libp2p/service-capabilities"),Jr=Symbol.for("@libp2p/service-dependencies");var po={};bt(po,{base58btc:()=>G,base58flickr:()=>Eu});var Yh=new Uint8Array(0);function vi(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Kt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function _i(r){return new TextEncoder().encode(r)}function Ii(r){return new TextDecoder().decode(r)}function mu(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var E=0,h=0,b=0,S=g.length;b!==S&&g[b]===0;)b++,E++;for(var _=(S-b)*f+1>>>0,R=new Uint8Array(_);b!==S;){for(var D=g[b],k=0,C=_-1;(D!==0||k<h)&&C!==-1;C--,k++)D+=256*R[C]>>>0,R[C]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");h=k,b++}for(var B=_-h;B!==_&&R[B]===0;)B++;for(var P=c.repeat(E);B<_;++B)P+=r.charAt(R[B]);return P}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var E=0;if(g[E]!==" "){for(var h=0,b=0;g[E]===c;)h++,E++;for(var S=(g.length-E)*u+1>>>0,_=new Uint8Array(S);g[E];){var R=e[g.charCodeAt(E)];if(R===255)return;for(var D=0,k=S-1;(R!==0||D<b)&&k!==-1;k--,D++)R+=a*_[k]>>>0,_[k]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");b=D,E++}if(g[E]!==" "){for(var C=S-b;C!==S&&_[C]===0;)C++;for(var B=new Uint8Array(h+(S-C)),P=h;C!==S;)B[P++]=_[C++];return B}}}function p(g){var E=d(g);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:p}}var gu=mu,bu=gu,Bi=bu;var uo=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")}},fo=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 Ti(this,t)}},lo=class{decoders;constructor(t){this.decoders=t}or(t){return Ti(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 Ti(r,t){return new lo({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ho=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 uo(t,e,n),this.decoder=new fo(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function De({name:r,prefix:t,encode:e,decode:n}){return new ho(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Bi(e,r);return De({prefix:t,name:r,encode:n,decode:s=>Kt(o(s))})}function yu(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function xu(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function wu(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=wu(n);return De({prefix:t,name:r,encode(s){return xu(s,n,e)},decode(s){return yu(s,o,e,r)}})}var G=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Eu=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var mo={};bt(mo,{base32:()=>Xt,base32hex:()=>Iu,base32hexpad:()=>Bu,base32hexpadupper:()=>Tu,base32hexupper:()=>Au,base32pad:()=>vu,base32padupper:()=>_u,base32upper:()=>Su,base32z:()=>Du});var Xt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Su=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vu=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_u=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Iu=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Au=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Bu=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Tu=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Du=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var go={};bt(go,{base36:()=>cr,base36upper:()=>Lu});var cr=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Lu=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ru=Ri,Di=128,Cu=127,Ou=~Cu,ku=Math.pow(2,31);function Ri(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ku;)t[e++]=r&255|Di,r/=128;for(;r&Ou;)t[e++]=r&255|Di,r>>>=7;return t[e]=r|0,Ri.bytes=e-n+1,t}var Pu=bo,Fu=128,Li=127;function bo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw bo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Li)<<o:(i&Li)*Math.pow(2,o),o+=7}while(i>=Fu);return bo.bytes=s-n,e}var Nu=Math.pow(2,7),Uu=Math.pow(2,14),Mu=Math.pow(2,21),Ku=Math.pow(2,28),zu=Math.pow(2,35),qu=Math.pow(2,42),Vu=Math.pow(2,49),Hu=Math.pow(2,56),$u=Math.pow(2,63),ju=function(r){return r<Nu?1:r<Uu?2:r<Mu?3:r<Ku?4:r<zu?5:r<qu?6:r<Vu?7:r<Hu?8:r<$u?9:10},Zu={encode:Ru,decode:Pu,encodingLength:ju},Gu=Zu,ur=Gu;function fr(r,t=0){return[ur.decode(r,t),ur.decode.bytes]}function Le(r,t,e=0){return ur.encode(r,t,e),t}function Re(r){return ur.encodingLength(r)}function Oe(r,t){let e=t.byteLength,n=Re(r),o=n+Re(e),s=new Uint8Array(o+e);return Le(r,s,0),Le(e,s,n),s.set(t,o),new Ce(r,e,t,s)}function lr(r){let t=Kt(r),[e,n]=fr(t),[o,s]=fr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ce(e,o,i,t)}function Ci(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&vi(r.bytes,e.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Oi(r,t){let{bytes:e,version:n}=r;return n===0?Xu(e,yo(r),t??G.encoder):Wu(e,yo(r),t??Xt.encoder)}var ki=new WeakMap;function yo(r){let t=ki.get(r);if(t==null){let e=new Map;return ki.set(r,e),e}return t}var ct=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Qu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Oe(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&&Ci(t.multihash,n.multihash)}toString(t){return Oi(this,t)}toJSON(){return{"/":Oi(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??Pi(n,o,s.bytes))}else if(e[Ju]===!0){let{version:n,multihash:o,code:s}=e,i=lr(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!==dr)throw new Error(`Version 0 CID must use dag-pb (code: ${dr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Pi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,dr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Kt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Ce(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[l,d]=fr(t.subarray(e));return e+=d,l},o=n(),s=dr;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,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,e){let[n,o]=Yu(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return yo(s).set(n,t),s}};function Yu(r,t){switch(r[0]){case"Q":{let e=t??G;return[G.prefix,e.decode(`${G.prefix}${r}`)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case Xt.prefix:{let e=t??Xt;return[Xt.prefix,e.decode(r)]}case cr.prefix:{let e=t??cr;return[cr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Xu(r,t,e){let{prefix:n}=e;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Wu(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var dr=112,Qu=18;function Pi(r,t,e){let n=Re(r),o=n+Re(t),s=new Uint8Array(o+e.byteLength);return Le(r,s,0),Le(t,s,n),s.set(e,o),s}var Ju=Symbol.for("@ipld/js-cid/CID");var xo={};bt(xo,{identity:()=>At});var Fi=0,tf="identity",Ni=Kt;function ef(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 Oe(Fi,Ni(r))}var At={code:Fi,name:tf,encode:Ni,digest:ef};function dt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function yt(r=0){return new Uint8Array(r)}function mt(r=0){return new Uint8Array(r)}function zt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=mt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Mi=Symbol.for("@achingbrain/uint8arraylist");function Ui(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 en(r){return!!r?.[Mi]}var et=class r{bufs;length;[Mi]=!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(en(n)){e+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(en(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=Ui(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ui(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(en(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 zt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:zt(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,f=e>a&&e<=c;if(u&&f){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){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(!en(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=e;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){f=Math.max(1,d-a[p]);break}}if(f===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=mt(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=yt(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=yt(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=yt(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=mt(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=yt(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=yt(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=yt(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=yt(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=yt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!dt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var wo={};bt(wo,{base10:()=>rf});var rf=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Eo={};bt(Eo,{base16:()=>nf,base16upper:()=>of});var nf=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),of=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var So={};bt(So,{base2:()=>sf});var sf=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vo={};bt(vo,{base256emoji:()=>lf});var Ki=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}"),af=Ki.reduce((r,t,e)=>(r[e]=t,r),[]),cf=Ki.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function uf(r){return r.reduce((t,e)=>(t+=af[e],t),"")}function ff(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=cf[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var lf=De({prefix:"\u{1F680}",name:"base256emoji",encode:uf,decode:ff});var Io={};bt(Io,{base64:()=>df,base64pad:()=>hf,base64url:()=>_o,base64urlpad:()=>pf});var df=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hf=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_o=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pf=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ao={};bt(Ao,{base8:()=>mf});var mf=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Bo={};bt(Bo,{identity:()=>gf});var gf=De({prefix:"\0",name:"identity",encode:r=>Ii(r),decode:r=>_i(r)});var Cp=new TextEncoder,Op=new TextDecoder;var Lo={};bt(Lo,{sha256:()=>hr,sha512:()=>wf});var xf=20;function Do({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new To(r,t,e,n,o)}var To=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??xf,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?zi(n,this.code,e?.truncate):n.then(o=>zi(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function zi(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 Oe(t,r)}function Vi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var hr=Do({name:"sha2-256",code:18,encode:Vi("SHA-256")}),wf=Do({name:"sha2-512",code:19,encode:Vi("SHA-512")});var pr={...Bo,...So,...Ao,...wo,...Eo,...mo,...go,...po,...Io,...vo},$p={...Lo,...xo};function $i(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Hi=$i("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ro=$i("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=mt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ef={utf8:Hi,"utf-8":Hi,hex:pr.base16,latin1:Ro,ascii:Ro,binary:Ro,...pr},rn=Ef;function H(r,t="utf8"){let e=rn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function W(r,t="utf8"){let e=rn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Sf=parseInt("11111",2),Co=parseInt("10000000",2),vf=parseInt("01111111",2),ji={0:mr,1:mr,2:_f,3:Bf,4:Tf,5:Af,6:If,16:mr,22:mr,48:mr};function Oo(r,t={offset:0}){let e=r[t.offset]&Sf;if(t.offset++,ji[e]!=null)return ji[e](r,t);throw new Error("No decoder for tag "+e)}function gr(r,t){let e=0;if((r[t.offset]&Co)===Co){let n=r[t.offset]&vf,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 mr(r,t){gr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Oo(r,t);if(n===null)break;e.push(n)}return e}function _f(r,t){let e=gr(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 If(r,t){let e=gr(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 f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Af(r,t){return t.offset++,null}function Bf(r,t){let e=gr(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 Tf(r,t){let e=gr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Df(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new et;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function ko(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Df(r.byteLength);return new et(Uint8Array.from([t.byteLength|Co]),t)}function Zi(r){let t=new et,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new et(Uint8Array.from([2]),ko(t),t)}function Gi(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),ko(e),e)}function nn(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),ko(e),e)}async function Yi(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 Lf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Rf=Uint8Array.from([6,5,43,129,4,0,34]),Cf=Uint8Array.from([6,5,43,129,4,0,35]),Of={ext:!0,kty:"EC",crv:"P-256"},kf={ext:!0,kty:"EC",crv:"P-384"},Pf={ext:!0,kty:"EC",crv:"P-521"},Po=32,Fo=48,No=66;function Xi(r){let t=Oo(r);return Wi(t)}function Wi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Po*2+1)return n=W(t.subarray(e,e+Po),"base64url"),o=W(t.subarray(e+Po),"base64url"),new ke({...Of,key_ops:["verify"],x:n,y:o});if(t.byteLength===Fo*2+1)return n=W(t.subarray(e,e+Fo),"base64url"),o=W(t.subarray(e+Fo),"base64url"),new ke({...kf,key_ops:["verify"],x:n,y:o});if(t.byteLength===No*2+1)return n=W(t.subarray(e,e+No),"base64url"),o=W(t.subarray(e+No),"base64url"),new ke({...Pf,key_ops:["verify"],x:n,y:o});throw new lt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Qi(r){return nn([Zi(Uint8Array.from([1])),nn([Ff(r.crv)],160),nn([Gi(new et(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function Ff(r){if(r==="P-256")return Lf;if(r==="P-384")return Rf;if(r==="P-521")return Cf;throw new lt(`Invalid curve ${r}`)}var ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Qi(this.jwk)),this._raw}toMultihash(){return At.digest(Pe(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,e,n){return Yi(this.jwk,e,t,n)}};function Uo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Wt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${r}`)}}function xt(r,t,e=""){let n=Uo(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}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return r}function on(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Wt(r.outputLen),Wt(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Fe(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 sn(r,t){xt(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new RangeError('"digestInto() output" expected to be of length >='+e)}function Vt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function an(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Bt(r,t){return r<<32-t|r>>>t}var ta=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Nf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function cn(r){if(xt(r),ta)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Nf[r[e]];return t}var qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ji(r){if(r>=qt._0&&r<=qt._9)return r-qt._0;if(r>=qt.A&&r<=qt.F)return r-(qt.A-10);if(r>=qt.a&&r<=qt.f)return r-(qt.a-10)}function br(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(ta)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Ji(r.charCodeAt(s)),a=Ji(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Mo(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];xt(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 Ko(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function ea(r=32){Wt(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var zo=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ra(r,t,e){return r&t^~r&e}function na(r,t,e){return r&t^r&e^t&e}var yr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=an(this.buffer)}update(t){Fe(this),xt(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=an(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){Fe(this),sn(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=an(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],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()}},Ht=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var un=BigInt(4294967295),oa=BigInt(32);function Uf(r,t=!1){return t?{h:Number(r&un),l:Number(r>>oa&un)}:{h:Number(r>>oa&un)|0,l:Number(r&un)|0}}function sa(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}=Uf(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var qo=(r,t,e)=>r>>>e,Vo=(r,t,e)=>r<<32-e|t>>>e,le=(r,t,e)=>r>>>e|t<<32-e,de=(r,t,e)=>r<<32-e|t>>>e,xr=(r,t,e)=>r<<64-e|t>>>e-32,wr=(r,t,e)=>r>>>e-32|t<<64-e;function kt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var ia=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),aa=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ca=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ua=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,fa=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),la=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Kf=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]),Qt=new Uint32Array(64),Ho=class extends yr{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 l=0;l<16;l++,e+=4)Qt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=Qt[l-15],p=Qt[l-2],g=Bt(d,7)^Bt(d,18)^d>>>3,E=Bt(p,17)^Bt(p,19)^p>>>10;Qt[l]=E+Qt[l-7]+g+Qt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Bt(a,6)^Bt(a,11)^Bt(a,25),p=f+d+ra(a,c,u)+Kf[l]+Qt[l]|0,E=(Bt(n,2)^Bt(n,13)^Bt(n,22))+na(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+E|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,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Vt(Qt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}},$o=class extends Ho{A=Ht[0]|0;B=Ht[1]|0;C=Ht[2]|0;D=Ht[3]|0;E=Ht[4]|0;F=Ht[5]|0;G=Ht[6]|0;H=Ht[7]|0;constructor(){super(32)}};var da=sa(["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))),zf=da[0],qf=da[1],Jt=new Uint32Array(80),te=new Uint32Array(80),jo=class extends yr{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:f,Fh:l,Fl:d,Gh:p,Gl:g,Hh:E,Hl:h}=this;return[t,e,n,o,s,i,a,c,u,f,l,d,p,g,E,h]}set(t,e,n,o,s,i,a,c,u,f,l,d,p,g,E,h){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=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=g|0,this.Hh=E|0,this.Hl=h|0}process(t,e){for(let _=0;_<16;_++,e+=4)Jt[_]=t.getUint32(e),te[_]=t.getUint32(e+=4);for(let _=16;_<80;_++){let R=Jt[_-15]|0,D=te[_-15]|0,k=le(R,D,1)^le(R,D,8)^qo(R,D,7),C=de(R,D,1)^de(R,D,8)^Vo(R,D,7),B=Jt[_-2]|0,P=te[_-2]|0,q=le(B,P,19)^xr(B,P,61)^qo(B,P,6),F=de(B,P,19)^wr(B,P,61)^Vo(B,P,6),m=ca(C,F,te[_-7],te[_-16]),y=ua(m,k,q,Jt[_-7],Jt[_-16]);Jt[_]=y|0,te[_]=m|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:g,Gh:E,Gl:h,Hh:b,Hl:S}=this;for(let _=0;_<80;_++){let R=le(l,d,14)^le(l,d,18)^xr(l,d,41),D=de(l,d,14)^de(l,d,18)^wr(l,d,41),k=l&p^~l&E,C=d&g^~d&h,B=fa(S,D,C,qf[_],te[_]),P=la(B,b,R,k,zf[_],Jt[_]),q=B|0,F=le(n,o,28)^xr(n,o,34)^xr(n,o,39),m=de(n,o,28)^wr(n,o,34)^wr(n,o,39),y=n&s^n&a^s&a,v=o&i^o&c^i&c;b=E|0,S=h|0,E=p|0,h=g|0,p=l|0,g=d|0,{h:l,l:d}=kt(u|0,f|0,P|0,q|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let w=ia(q,m,v);n=aa(w,P,F,y),o=w|0}({h:n,l:o}=kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=kt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=kt(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:g}=kt(this.Fh|0,this.Fl|0,p|0,g|0),{h:E,l:h}=kt(this.Gh|0,this.Gl|0,E|0,h|0),{h:b,l:S}=kt(this.Hh|0,this.Hl|0,b|0,S|0),this.set(n,o,s,i,a,c,u,f,l,d,p,g,E,h,b,S)}roundClean(){Vt(Jt,te)}destroy(){this.destroyed=!0,Vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Zo=class extends jo{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var ha=Ko(()=>new $o,zo(1));var fn=Ko(()=>new Zo,zo(3));var M=(r,t,e)=>xt(r,t,e),Yo=Wt,Ne=cn,Q=(...r)=>Mo(...r),Ue=r=>br(r),he=Uo,Er=r=>ea(r),dn=BigInt(0),Go=BigInt(1);function Tt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function hn(r){if(typeof r=="bigint"){if(!ln(r))throw new RangeError("positive bigint expected, got "+r)}else Yo(r);return r}function Dt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+r)}}function Sr(r){let t=hn(r).toString(16);return t.length&1?"0"+t:t}function pa(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?dn:BigInt("0x"+r)}function pe(r){return pa(cn(r))}function Pt(r){return pa(cn(vr(xt(r)).reverse()))}function pn(r,t){if(Wt(t),t===0)throw new RangeError("zero length");r=hn(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return br(e.padStart(t*2,"0"))}function Xo(r,t){return pn(r,t).reverse()}function ma(r,t){if(r=M(r),t=M(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function vr(r){return Uint8Array.from(M(r))}function mn(r){if(typeof r!="string")throw new TypeError("ascii string expected, got "+typeof r);return Uint8Array.from(r,(t,e)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${r[e]}" with code ${n} at position ${e}`);return n})}var ln=r=>typeof r=="bigint"&&dn<=r;function Vf(r,t,e){return ln(r)&&ln(t)&&ln(e)&&t<=r&&r<e}function Me(r,t,e,n){if(!Vf(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Ke(r){if(r<dn)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>dn;r>>=Go,t+=1);return t}var _r=r=>(Go<<BigInt(r))-Go;function ga(r,t,e){if(Wt(r,"hashLen"),Wt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=h=>new Uint8Array(h),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...h)=>e(u,Q(c,...h)),p=(h=o)=>{u=d(s,h),c=d(),h.length!==0&&(u=d(i,h),c=d())},g=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let h=0,b=[];for(;h<t;){c=d();let S=c.slice();b.push(S),h+=c.length}return Q(...b)};return(h,b)=>{l(),p(h);let S;for(;(S=b(g()))===void 0;)p();return l(),S}}function Lt(r,t={},e={}){if(Object.prototype.toString.call(r)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(r,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=r[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`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)}var Wo=()=>{throw new Error("not implemented")};var st=BigInt(0),j=BigInt(1),me=BigInt(2),wa=BigInt(3),Ea=BigInt(4),Sa=BigInt(5),Hf=BigInt(7),va=BigInt(8),$f=BigInt(9),_a=BigInt(16);function Y(r,t){if(t<=st)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=st?e:t+e}function V(r,t,e){if(t<st)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >st;)n*=n,n%=e;return n}function ba(r,t){if(r===st)throw new Error("invert: expected non-zero number");if(t<=st)throw new Error("invert: expected positive modulus, got "+t);let e=Y(r,t),n=t,o=st,s=j,i=j,a=st;for(;e!==st;){let u=n/e,f=n-e*u,l=o-i*u,d=s-a*u;n=e,e=f,o=i,s=a,i=l,a=d}if(n!==j)throw new Error("invert: does not exist");return Y(o,t)}function Qo(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Ia(r,t){let e=r,n=(e.ORDER+j)/Ea,o=e.pow(t,n);return Qo(e,o,t),o}function jf(r,t){let e=r,n=(e.ORDER-Sa)/va,o=e.mul(t,me),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,me),s),c=e.mul(i,e.sub(a,e.ONE));return Qo(e,c,t),c}function Zf(r){let t=ze(r),e=Aa(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Hf)/_a;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),p=u.mul(f,s),g=u.eql(u.sqr(l),c),E=u.eql(u.sqr(d),c);f=u.cmov(f,l,g),l=u.cmov(p,d,E);let h=u.eql(u.sqr(l),c),b=u.cmov(f,l,h);return Qo(u,b,c),b})}function Aa(r){if(r<wa)throw new Error("sqrt is not defined for small field");let t=r-j,e=0;for(;t%me===st;)t/=me,e++;let n=me,o=ze(r);for(;ya(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ia;let s=o.pow(n,t),i=(t+j)/me;return function(c,u){let f=c;if(f.is0(u))return u;if(ya(f,u)!==1)throw new Error("Cannot find square root");let l=e,d=f.mul(f.ONE,s),p=f.pow(u,t),g=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))return f.ZERO;let E=1,h=f.sqr(p);for(;!f.eql(h,f.ONE);)if(E++,h=f.sqr(h),E===l)throw new Error("Cannot find square root");let b=j<<BigInt(l-E-1),S=f.pow(d,b);l=E,d=f.sqr(S),p=f.mul(p,d),g=f.mul(g,S)}return g}}function Gf(r){return r%Ea===wa?Ia:r%va===Sa?jf:r%_a===$f?Zf(r):Aa(r)}var $t=(r,t)=>(Y(r,t)&j)===j,Yf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Yf.reduce((n,o)=>(n[o]="function",n),t);if(Lt(r,e),Dt(r.BYTES,"BYTES"),Dt(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=j)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function Xf(r,t,e){let n=r;if(e<st)throw new Error("invalid exponent, negatives unsupported");if(e===st)return n.ONE;if(e===j)return t;let o=n.ONE,s=t;for(;e>st;)e&j&&(o=n.mul(o,s)),s=n.sqr(s),e>>=j;return o}function Ir(r,t,e=!1){let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function ya(r,t){let e=r,n=(e.ORDER-j)/me,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),a=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Wf(r,t){if(t!==void 0&&Yo(t),r<=st)throw new Error("invalid n length: expected positive n, got "+r);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=Ke(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${t})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var xa=new WeakMap,gn=class{ORDER;BITS;BYTES;isLE;ZERO=st;ONE=j;_lengths;_mod;constructor(t,e={}){if(t<=j)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=Wf(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return Y(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return st<=t&&t<this.ORDER}is0(t){return t===st}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&j)===j}neg(t){return Y(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Y(t*t,this.ORDER)}add(t,e){return Y(t+e,this.ORDER)}sub(t,e){return Y(t-e,this.ORDER)}mul(t,e){return Y(t*e,this.ORDER)}pow(t,e){return Xf(this,t,e)}div(t,e){return Y(t*ba(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 ba(t,this.ORDER)}sqrt(t){let e=xa.get(this);return e||xa.set(this,e=Gf(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?Xo(t,this.BYTES):pn(t,this.BYTES)}fromBytes(t,e=!1){M(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let 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?Pt(t):pe(t);if(a&&(c=Y(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Ir(this,t)}cmov(t,e,n){return Tt(n,"condition"),n?e:t}};Object.freeze(gn.prototype);function ze(r,t={}){return new gn(r,t)}function Ba(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=j)throw new Error("field order must be greater than 1");let t=Ke(r-j);return Math.ceil(t/8)}function ts(r){let t=Ba(r);return t+Math.ceil(t/2)}function es(r,t,e=!1){M(r);let n=r.length,o=Ba(t),s=Math.max(ts(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Pt(r):pe(r),a=Y(i,t-j)+j;return e?Xo(a,o):pn(a,o)}var qe=BigInt(0),ge=BigInt(1);function Ar(r,t){let e=t.negate();return r?e:t}function be(r,t){let e=Ir(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Ra(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function rs(r,t){Ra(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=_r(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ta(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+=ge);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,p=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:p,offsetF:u}}var ns=new WeakMap,Ca=new WeakMap;function os(r){return Ca.get(r)||1}function Da(r){if(r!==qe)throw new Error("invalid wNAF")}var Ve=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>qe;)e&ge&&(n=n.add(o)),o=o.double(),e>>=ge;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=rs(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=rs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:p}=Ta(n,a,i);n=c,f?s=s.add(Ar(d,e[p])):o=o.add(Ar(l,e[u]))}return Da(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=rs(t,this.bits);for(let i=0;i<s.windows&&n!==qe;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Ta(n,i,s);if(n=a,!u){let l=e[c];o=o.add(f?l.negate():l)}}return Da(n),o}getPrecomputes(t,e,n){let o=ns.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),ns.set(e,o))),o}cached(t,e,n){let o=os(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=os(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Ra(e,this.bits),Ca.set(t,e),ns.delete(t)}hasCache(t){return os(t)!==1}};function Oa(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>qe||n>qe;)e&ge&&(s=s.add(o)),n&ge&&(i=i.add(o)),o=o.double(),e>>=ge,n>>=ge;return{p1:s,p2:i}}function La(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jo(t),t}else return ze(r,{isLE:e})}function bn(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>qe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=La(t.p,e.Fp,n),s=La(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 yn(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var ee=BigInt(0),rt=BigInt(1),ss=BigInt(2),Qf=BigInt(8);function Jf(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 ka(r,t={}){let e=t,n=bn("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Lt(e,{},{uvRatio:"function"});let c=ss<<BigInt(s.BYTES*8)-rt,u=E=>o.create(E),f=e.uvRatio===void 0?(E,h)=>{try{return{isValid:!0,value:o.sqrt(o.div(E,h))}}catch{return{isValid:!1,value:ee}}}:e.uvRatio;if(!Jf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(E,h,b=!1){let S=b?rt:ee;return Me("coordinate "+E,h,S,c),h}function d(E){if(!(E instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,rt,u(i.Gx*i.Gy));static ZERO=new p(ee,rt,rt,ee);static Fp=o;static Fn=s;X;Y;Z;T;constructor(h,b,S,_){this.X=l("x",h),this.Y=l("y",b),this.Z=l("z",S,!0),this.T=l("t",_),Object.freeze(this)}static CURVE(){return i}static fromAffine(h){if(h instanceof p)throw new Error("extended point not allowed");let{x:b,y:S}=h||{};return l("x",b),l("y",S),new p(b,S,rt,u(b*S))}static fromBytes(h,b=!1){let S=o.BYTES,{a:_,d:R}=i;h=vr(M(h,S,"point")),Tt(b,"zip215");let D=vr(h),k=h[S-1];D[S-1]=k&-129;let C=Pt(D),B=b?c:o.ORDER;Me("point.y",C,ee,B);let P=u(C*C),q=u(P-rt),F=u(R*P-_),{isValid:m,value:y}=f(q,F);if(!m)throw new Error("bad point: invalid y coordinate");let v=(y&rt)===rt,w=(k&128)!==0;if(!b&&y===ee&&w)throw new Error("bad point: x=0 and x_0=1");return w!==v&&(y=u(-y)),p.fromAffine({x:y,y:C})}static fromHex(h,b=!1){return p.fromBytes(Ue(h),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,b=!0){return g.createCache(this,h),b||this.multiply(ss),this}assertValidity(){let h=this,{a:b,d:S}=i;if(h.is0())throw new Error("bad point: ZERO");let{X:_,Y:R,Z:D,T:k}=h,C=u(_*_),B=u(R*R),P=u(D*D),q=u(P*P),F=u(C*b),m=u(P*u(F+B)),y=u(q+u(S*u(C*B)));if(m!==y)throw new Error("bad point: equation left != right (1)");let v=u(_*R),w=u(D*k);if(v!==w)throw new Error("bad point: equation left != right (2)")}equals(h){d(h);let{X:b,Y:S,Z:_}=this,{X:R,Y:D,Z:k}=h,C=u(b*k),B=u(R*_),P=u(S*k),q=u(D*_);return C===B&&P===q}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:h}=i,{X:b,Y:S,Z:_}=this,R=u(b*b),D=u(S*S),k=u(ss*u(_*_)),C=u(h*R),B=b+S,P=u(u(B*B)-R-D),q=C+D,F=q-k,m=C-D,y=u(P*F),v=u(q*m),w=u(P*m),x=u(F*q);return new p(y,v,x,w)}add(h){d(h);let{a:b,d:S}=i,{X:_,Y:R,Z:D,T:k}=this,{X:C,Y:B,Z:P,T:q}=h,F=u(_*C),m=u(R*B),y=u(k*S*q),v=u(D*P),w=u((_+R)*(C+B)-F-m),x=v-y,I=v+y,T=u(m-b*F),A=u(w*x),L=u(I*T),O=u(w*T),U=u(x*I);return new p(A,L,U,O)}subtract(h){return d(h),this.add(h.negate())}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:S}=g.cached(this,h,_=>be(p,_));return be(p,[b,S])[0]}multiplyUnsafe(h){if(!s.isValid(h))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return h===ee?p.ZERO:this.is0()||h===rt?this:g.unsafe(this,h,b=>be(p,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return g.unsafe(this,i.n).is0()}toAffine(h){let b=this,S=h,{X:_,Y:R,Z:D}=b,k=b.is0();S==null&&(S=k?Qf:o.inv(D));let C=u(_*S),B=u(R*S),P=o.mul(D,S);if(k)return{x:ee,y:rt};if(P!==rt)throw new Error("invZ was invalid");return{x:C,y:B}}clearCofactor(){return a===rt?this:this.multiplyUnsafe(a)}toBytes(){let{x:h,y:b}=this.toAffine(),S=o.toBytes(b);return S[S.length-1]|=h&rt?128:0,S}toHex(){return Ne(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=new Ve(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var xn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Wo()}static fromHex(t){Wo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Ne(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.ep.precompute(t,e),this}};function Pa(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;Lt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Dt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Er:o.randomBytes,d=o.adjustScalarBytes===void 0?m=>m:o.adjustScalarBytes,p=o.domain===void 0?(m,y,v)=>{if(Tt(v,"phflag"),y.length||v)throw new Error("Contexts/pre-hash are not supported");return m}:o.domain;function g(m){return c.create(Pt(m))}function E(m){let y=C.secretKey;M(m,C.secretKey,"secretKey");let v=M(n(m),2*y,"hashedSecretKey"),w=d(v.slice(0,y)),x=v.slice(y,2*y),I=g(w);return{head:w,prefix:x,scalar:I}}function h(m){let{head:y,prefix:v,scalar:w}=E(m),x=i.multiply(w),I=x.toBytes();return{head:y,prefix:v,scalar:w,point:x,pointBytes:I}}function b(m){return h(m).pointBytes}function S(m=Uint8Array.of(),...y){let v=Q(...y);return g(n(p(v,M(m,void 0,"context"),!!s)))}function _(m,y,v={}){m=M(m,void 0,"message"),s&&(m=s(m));let{prefix:w,scalar:x,pointBytes:I}=h(y),T=S(v.context,w,m),A=i.multiply(T).toBytes(),L=S(v.context,A,I,m),O=c.create(T+L*x);if(!c.isValid(O))throw new Error("sign failed: invalid s");let U=Q(A,c.toBytes(O));return M(U,C.signature,"result")}let R={zip215:o.zip215};function D(m,y,v,w=R){let{context:x}=w,I=w.zip215===void 0?!!R.zip215:w.zip215,T=C.signature;m=M(m,T,"signature"),y=M(y,void 0,"message"),v=M(v,C.publicKey,"publicKey"),I!==void 0&&Tt(I,"zip215"),s&&(y=s(y));let A=T/2,L=m.subarray(0,A),O=Pt(m.subarray(A,T)),U,K,N;try{U=r.fromBytes(v,I),K=r.fromBytes(L,I),N=i.multiplyUnsafe(O)}catch{return!1}if(!I&&U.isSmallOrder())return!1;let X=S(x,L,v,y);return K.add(U.multiplyUnsafe(X)).subtract(N).clearCofactor().is0()}let k=a.BYTES,C={secretKey:k,publicKey:k,signature:2*k,seed:k};function B(m){return m=m===void 0?l(C.seed):m,M(m,C.seed,"seed")}function P(m){return he(m)&&m.length===C.secretKey}function q(m,y){try{return!!r.fromBytes(m,y===void 0?R.zip215:y)}catch{return!1}}let F={getExtendedPublicKey:h,randomSecretKey:B,isValidSecretKey:P,isValidPublicKey:q,toMontgomery(m){let{y}=r.fromBytes(m),v=C.publicKey,w=v===32;if(!w&&v!==57)throw new Error("only defined for 25519 and 448");let x=w?a.div(rt+y,rt-y):a.div(y-rt,y+rt);return a.toBytes(x)},toMontgomerySecret(m){let y=C.secretKey;M(m,y);let v=n(m.subarray(0,y));return d(v).subarray(0,y)}};return Object.freeze(C),Object.freeze(F),Object.freeze({keygen:yn(B,b),getPublicKey:b,sign:_,verify:D,utils:F,Point:r,lengths:C})}function Br(r,t){if(Dt(r),Dt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(r<0||r>2**(8*t)-1)throw new Error("invalid I2OSP input: "+r);let e=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)e[n]=r&255,r>>>=8;return new Uint8Array(e)}function tl(r,t){let e=new Uint8Array(r.length);for(let n=0;n<r.length;n++)e[n]=r[n]^t[n];return e}function el(r){if(!he(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?mn(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function is(r,t,e,n){M(r),Dt(e),t=el(t),t.length>255&&(t=n(Q(mn("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(e/o);if(e>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=Q(t,Br(t.length,1)),c=new Uint8Array(s),u=Br(e,2),f=new Array(i),l=n(Q(c,r,u,Br(0,1),a));f[0]=n(Q(l,Br(1,1),a));for(let p=1;p<i;p++){let g=[tl(l,f[p-1]),Br(p+1,1),a];f[p]=n(Q(...g))}return Q(...f).slice(0,e)}var Fa="HashToScalar-";var rl=BigInt(0),jt=BigInt(1),Na=BigInt(2);var nl=BigInt(5),ol=BigInt(8),He=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),fs={p:He,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ol,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function sl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=He,a=r*r%s*r%s,c=V(a,Na,s)*a%s,u=V(c,jt,s)*r%s,f=V(u,nl,s)*u%s,l=V(f,t,s)*f%s,d=V(l,e,s)*l%s,p=V(d,n,s)*d%s,g=V(p,o,s)*p%s,E=V(g,o,s)*p%s,h=V(E,t,s)*f%s;return{pow_p_5_8:V(h,Na,s)*r%s,b2:a}}function il(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var as=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ls(r,t){let e=He,n=Y(t*t*t,e),o=Y(n*n*t,e),s=sl(r*o).pow_p_5_8,i=Y(r*n*s,e),a=Y(t*i*i,e),c=i,u=Y(i*as,e),f=a===r,l=a===Y(-r,e),d=a===Y(-r*as,e);return f&&(i=c),(l||d)&&(i=u),$t(i,e)&&(i=Y(-i,e)),{isValid:f||l,value:i}}var ne=ka(fs,{uvRatio:ls}),re=ne.Fp,Ka=ne.Fn;function al(r){return Pa(ne,fn,Object.assign({adjustScalarBytes:il,zip215:!0},r))}var za=al({});var cs=as,cl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),ul=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),fl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ll=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ua=r=>ls(jt,r),dl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),us=r=>re.create(Pt(r)&dl);function Ma(r){let{d:t}=fs,e=He,n=b=>re.create(b),o=n(cs*r*r),s=n((o+jt)*fl),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=ls(s,a),f=n(u*r);$t(f,e)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-jt)*ll-a),d=u*u,p=n((u+u)*a),g=n(l*cl),E=n(jt-d),h=n(jt+d);return new ne(n(p*h),n(E*g),n(g*h),n(p*E))}var oe=class r extends xn{static BASE=new r(ne.BASE);static ZERO=new r(ne.ZERO);static Fp=re;static Fn=Ka;constructor(t){super(t)}static fromAffine(t){return new r(ne.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){xt(t,32);let{a:e,d:n}=fs,o=He,s=R=>re.create(R),i=us(t);if(!ma(re.toBytes(i),t)||$t(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(jt+e*a),u=s(jt-e*a),f=s(c*c),l=s(u*u),d=s(e*n*f-l),{isValid:p,value:g}=Ua(s(d*l)),E=s(g*u),h=s(g*E*d),b=s((i+i)*E);$t(b,o)&&(b=s(-b));let S=s(c*h),_=s(b*S);if(!p||$t(_,o)||S===rl)throw new Error("invalid ristretto255 encoding 2");return new r(new ne(b,S,jt,_))}static fromHex(t){return r.fromBytes(br(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=He,i=h=>re.create(h),a=i(i(n+e)*i(n-e)),c=i(t*e),u=i(c*c),{value:f}=Ua(i(a*u)),l=i(f*a),d=i(f*c),p=i(l*d*o),g;if($t(o*p,s)){let h=i(e*cs),b=i(t*cs);t=h,e=b,g=i(l*ul)}else g=d;$t(t*p,s)&&(e=i(-e));let E=i((n-e)*g);return $t(E,s)&&(E=i(-E)),re.toBytes(E)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>re.create(u),a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Object.freeze(oe.BASE);Object.freeze(oe.ZERO);Object.freeze(oe.prototype);Object.freeze(oe);var hl=Object.freeze({Point:oe,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=is(r,e,64,fn);return hl.deriveToCurve(n)},hashToScalar(r,t={DST:Fa}){let e=is(r,t.DST,64,fn);return Ka.create(Pt(e))},deriveToCurve(r){xt(r,64);let t=us(r.subarray(0,32)),e=Ma(t),n=us(r.subarray(32,64)),o=Ma(n);return new oe(e.add(o))}});var Tr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},wn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var qa={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new wn("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 En=qa;var Sn=32;var ds,pl=(async()=>{try{return await En.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ml(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await En.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await En.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 gl(r,t,e){return za.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Va(r,t,e){return ds==null&&(ds=await pl),ds?ml(r,t,e):gl(r,t,e)}function vn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var _n=class{type="Ed25519";raw;constructor(t){this.raw=hs(t,Sn)}toMultihash(){return At.digest(Pe(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Va(this.raw,e,t);return vn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function $a(r){return r=hs(r,Sn),new _n(r)}function hs(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new lt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var yl=Math.pow(2,7),xl=Math.pow(2,14),wl=Math.pow(2,21),ps=Math.pow(2,28),ms=Math.pow(2,35),gs=Math.pow(2,42),bs=Math.pow(2,49),z=128,ut=127;function gt(r){if(r<yl)return 1;if(r<xl)return 2;if(r<wl)return 3;if(r<ps)return 4;if(r<ms)return 5;if(r<gs)return 6;if(r<bs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $e(r,t,e=0){switch(gt(r)){case 8:t[e++]=r&255|z,r/=128;case 7:t[e++]=r&255|z,r/=128;case 6:t[e++]=r&255|z,r/=128;case 5:t[e++]=r&255|z,r/=128;case 4:t[e++]=r&255|z,r>>>=7;case 3:t[e++]=r&255|z,r>>>=7;case 2:t[e++]=r&255|z,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function El(r,t,e=0){switch(gt(r)){case 8:t.set(e++,r&255|z),r/=128;case 7:t.set(e++,r&255|z),r/=128;case 6:t.set(e++,r&255|z),r/=128;case 5:t.set(e++,r&255|z),r/=128;case 4:t.set(e++,r&255|z),r>>>=7;case 3:t.set(e++,r&255|z),r>>>=7;case 2:t.set(e++,r&255|z),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ys(r,t){let e=r[t],n=0;if(n+=e&ut,e<z||(e=r[t+1],n+=(e&ut)<<7,e<z)||(e=r[t+2],n+=(e&ut)<<14,e<z)||(e=r[t+3],n+=(e&ut)<<21,e<z)||(e=r[t+4],n+=(e&ut)*ps,e<z)||(e=r[t+5],n+=(e&ut)*ms,e<z)||(e=r[t+6],n+=(e&ut)*gs,e<z)||(e=r[t+7],n+=(e&ut)*bs,e<z))return n;throw new RangeError("Could not decode varint")}function Sl(r,t){let e=r.get(t),n=0;if(n+=e&ut,e<z||(e=r.get(t+1),n+=(e&ut)<<7,e<z)||(e=r.get(t+2),n+=(e&ut)<<14,e<z)||(e=r.get(t+3),n+=(e&ut)<<21,e<z)||(e=r.get(t+4),n+=(e&ut)*ps,e<z)||(e=r.get(t+5),n+=(e&ut)*ms,e<z)||(e=r.get(t+6),n+=(e&ut)*gs,e<z)||(e=r.get(t+7),n+=(e&ut)*bs,e<z))return n;throw new RangeError("Could not decode varint")}function ja(r,t,e=0){return t==null&&(t=mt(gt(r))),t instanceof Uint8Array?$e(r,t,e):El(r,t,e)}function Dr(r,t=0){return r instanceof Uint8Array?ys(r,t):Sl(r,t)}var xs=new Float32Array([-0]),se=new Uint8Array(xs.buffer);function Ga(r,t,e){xs[0]=r,t[e]=se[0],t[e+1]=se[1],t[e+2]=se[2],t[e+3]=se[3]}function Ya(r,t){return se[0]=r[t],se[1]=r[t+1],se[2]=r[t+2],se[3]=r[t+3],xs[0]}var ws=new Float64Array([-0]),ft=new Uint8Array(ws.buffer);function Xa(r,t,e){ws[0]=r,t[e]=ft[0],t[e+1]=ft[1],t[e+2]=ft[2],t[e+3]=ft[3],t[e+4]=ft[4],t[e+5]=ft[5],t[e+6]=ft[6],t[e+7]=ft[7]}function Wa(r,t){return ft[0]=r[t],ft[1]=r[t+1],ft[2]=r[t+2],ft[3]=r[t+3],ft[4]=r[t+4],ft[5]=r[t+5],ft[6]=r[t+6],ft[7]=r[t+7],ws[0]}var vl=BigInt(Number.MAX_SAFE_INTEGER),_l=BigInt(Number.MIN_SAFE_INTEGER),wt=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 ye;if(t<vl&&t>_l)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>Qa&&(o=0n,++n>Qa&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ye;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):ye}},ye=new wt(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var Qa=4294967296n;function Ja(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 tc(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 Es(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 Rt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function In(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Ss=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,Rt(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 Rt(this,4);return In(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return In(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=Ya(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=Wa(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 Rt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return tc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Rt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Rt(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 wt(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 Rt(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 Rt(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 Rt(this,8);let t=In(this.buf,this.pos+=4),e=In(this.buf,this.pos+=4);return new wt(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=ys(this.buf,this.pos);return this.pos+=gt(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 Lr(r){return new Ss(r instanceof Uint8Array?r:r.subarray())}function St(r,t,e){let n=Lr(r);return t.decode(n,void 0,e)}function vs(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return mt(i);o+i>t&&(n=mt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var xe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function _s(){}var As=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Il=vs();function Al(r){return globalThis.Buffer!=null?mt(r):Il(r)}var Cr=class{len;head;tail;states;constructor(){this.len=0,this.head=new xe(_s,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new xe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Bs((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(An,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=wt.fromBigInt(t);return this._push(An,e.length(),e)}uint64Number(t){return this._push($e,gt(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=wt.fromBigInt(t).zzEncode();return this._push(An,e.length(),e)}sint64Number(t){let e=wt.fromNumber(t).zzEncode();return this._push(An,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Is,1,t?1:0)}fixed32(t){return this._push(Rr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=wt.fromBigInt(t);return this._push(Rr,4,e.lo)._push(Rr,4,e.hi)}fixed64Number(t){let e=wt.fromNumber(t);return this._push(Rr,4,e.lo)._push(Rr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ga,4,t)}double(t){return this._push(Xa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Is,1,0):this.uint32(e)._push(Tl,e,t)}string(t){let e=Ja(t);return e!==0?this.uint32(e)._push(Es,e,t):this._push(Is,1,0)}fork(){return this.states=new As(this),this.head=this.tail=new xe(_s,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 xe(_s,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=Al(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Is(r,t,e){t[e]=r&255}function Bl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Bs=class extends xe{next;constructor(t,e){super(Bl,t,e),this.next=void 0}};function An(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Rr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Tl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Cr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Dl,t,r),this},Cr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ll,t,r),this});function Dl(r,t,e){t.set(r,e)}function Ll(r,t,e){r.length<40?Es(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(H(r),e)}function Ts(){return new Cr}function vt(r,t){let e=Ts();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*_t(r,t,e){let n=Lr(r);yield*t.stream(n,void 0,"$",e)}var Bn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Tn(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function we(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return Tn("enum",Bn.VARINT,e,n,o)}function It(r,t,e){return Tn("message",Bn.LENGTH_DELIMITED,r,t,e)}var Or=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ht;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ht||(ht={}));var Ds;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Ds||(Ds={}));(function(r){r.codec=()=>we(Ds)})(ht||(ht={}));var kr;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ht.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ht.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ht.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function e(s){return vt(s,r.codec())}r.encode=e;function n(s,i){return St(s,r.codec(),i)}r.decode=n;function o(s,i){return _t(s,r.codec(),i)}r.stream=o})(kr||(kr={}));var Ls;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ht.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ht.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ht.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function e(s){return vt(s,r.codec())}r.encode=e;function n(s,i){return St(s,r.codec(),i)}r.decode=n;function o(s,i){return _t(s,r.codec(),i)}r.stream=o})(Ls||(Ls={}));var Dn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(on(t),xt(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),Vt(o)}update(t){return Fe(this),this.iHash.update(t),this}digestInto(t){Fe(this),sn(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},rc=(()=>{let r=((t,e,n)=>new Dn(t,e).update(n).digest());return r.create=(t,e)=>new Dn(t,e),r})();var nc=(r,t)=>(r+(r>=0?t:-t)/oc)/t;function Cl(r,t,e){Me("scalar",r,Ft,e);let[[n,o],[s,i]]=t,a=nc(i*r,e),c=nc(-o*r,e),u=r-a*n-c*s,f=-a*o-c*i,l=u<Ft,d=f<Ft;l&&(u=-u),d&&(f=-f);let p=_r(Math.ceil(Ke(e)/2))+ie;if(u<Ft||u>=p||f<Ft||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Cs(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Rs(r,t){Lt(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Tt(e.lowS,"lowS"),Tt(e.prehash,"prehash"),e.format!==void 0&&Cs(e.format),e}var Os=class extends Error{constructor(t=""){super(t)}},Ct={Err:Os,_tlv:{encode:(r,t)=>{let{Err:e}=Ct;if(Dt(r,"tag"),r<0||r>255)throw new e("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=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}=Ct;t=M(t,void 0,"DER data");let n=0;if(r<0||r>255)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let 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 f of u)i=i<<8|f;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}=Ct;if(hn(r),r<Ft)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}=Ct;if(r.length<1)throw new t("invalid signature integer: empty");if(r[0]&128)throw new t("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return pe(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ct,o=M(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.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}=Ct,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Ct._tlv);Object.freeze(Ct._int);Object.freeze(Ct);var Ft=BigInt(0),ie=BigInt(1),oc=BigInt(2),Ln=BigInt(3),Ol=BigInt(4);function sc(r,t={}){let e=bn("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;Lt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=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 f=ac(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(F,m,y){if(u&&m.is0())return Uint8Array.of(0);let{x:v,y:w}=m.toAffine(),x=n.toBytes(v);if(Tt(y,"isCompressed"),y){l();let I=!n.isOdd(w);return Q(ic(I),x)}else return Q(Uint8Array.of(4),x,n.toBytes(w))}function p(F){M(F,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=f,v=F.length,w=F[0],x=F.subarray(1);if(u&&v===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(v===m&&(w===2||w===3)){let I=n.fromBytes(x);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let T=h(I),A;try{A=n.sqrt(T)}catch(U){let K=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+K)}l();let L=n.isOdd(A);return(w&1)===1!==L&&(A=n.neg(A)),{x:I,y:A}}else if(v===y&&w===4){let I=n.BYTES,T=n.fromBytes(x.subarray(0,I)),A=n.fromBytes(x.subarray(I,I*2));if(!b(T,A))throw new Error("bad point: is not on curve");return{x:T,y:A}}else throw new Error(`bad point: got length ${v}, expected compressed=${m} or uncompressed=${y}`)}let g=t.toBytes===void 0?d:t.toBytes,E=t.fromBytes===void 0?p:t.fromBytes;function h(F){let m=n.sqr(F),y=n.mul(m,F);return n.add(n.add(y,n.mul(F,s.a)),s.b)}function b(F,m){let y=n.sqr(m),v=h(F);return n.eql(y,v)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,Ln),Ol),_=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,_)))throw new Error("bad curve params: a or b");function R(F,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${F}`);return m}function D(F){if(!(F instanceof B))throw new Error("Weierstrass Point expected")}function k(F){if(!c||!c.basises)throw new Error("no endo");return Cl(F,c.basises,o.ORDER)}function C(F,m,y,v,w){return y=new B(n.mul(y.X,F),y.Y,y.Z),m=Ar(v,m),y=Ar(w,y),m.add(y)}class B{static BASE=new B(s.Gx,s.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,y,v){this.X=R("x",m),this.Y=R("y",y,!0),this.Z=R("z",v),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:y,y:v}=m||{};if(!m||!n.isValid(y)||!n.isValid(v))throw new Error("invalid affine point");if(m instanceof B)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(v)?B.ZERO:new B(y,v,n.ONE)}static fromBytes(m){let y=B.fromAffine(E(M(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return B.fromBytes(Ue(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return q.createCache(this,m),y||this.multiply(Ln),this}assertValidity(){let m=this;if(m.is0()){if(t.allowInfinityPoint&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}let{x:y,y:v}=m.toAffine();if(!n.isValid(y)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!b(y,v))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){D(m);let{X:y,Y:v,Z:w}=this,{X:x,Y:I,Z:T}=m,A=n.eql(n.mul(y,T),n.mul(x,w)),L=n.eql(n.mul(v,T),n.mul(I,w));return A&&L}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=s,v=n.mul(y,Ln),{X:w,Y:x,Z:I}=this,T=n.ZERO,A=n.ZERO,L=n.ZERO,O=n.mul(w,w),U=n.mul(x,x),K=n.mul(I,I),N=n.mul(w,x);return N=n.add(N,N),L=n.mul(w,I),L=n.add(L,L),T=n.mul(m,L),A=n.mul(v,K),A=n.add(T,A),T=n.sub(U,A),A=n.add(U,A),A=n.mul(T,A),T=n.mul(N,T),L=n.mul(v,L),K=n.mul(m,K),N=n.sub(O,K),N=n.mul(m,N),N=n.add(N,L),L=n.add(O,O),O=n.add(L,O),O=n.add(O,K),O=n.mul(O,N),A=n.add(A,O),K=n.mul(x,I),K=n.add(K,K),O=n.mul(K,N),T=n.sub(T,O),L=n.mul(K,U),L=n.add(L,L),L=n.add(L,L),new B(T,A,L)}add(m){D(m);let{X:y,Y:v,Z:w}=this,{X:x,Y:I,Z:T}=m,A=n.ZERO,L=n.ZERO,O=n.ZERO,U=s.a,K=n.mul(s.b,Ln),N=n.mul(y,x),X=n.mul(v,I),J=n.mul(w,T),tt=n.add(y,v),Z=n.add(x,I);tt=n.mul(tt,Z),Z=n.add(N,X),tt=n.sub(tt,Z),Z=n.add(y,w);let pt=n.add(x,T);return Z=n.mul(Z,pt),pt=n.add(N,J),Z=n.sub(Z,pt),pt=n.add(v,w),A=n.add(I,T),pt=n.mul(pt,A),A=n.add(X,J),pt=n.sub(pt,A),O=n.mul(U,Z),A=n.mul(K,J),O=n.add(A,O),A=n.sub(X,O),O=n.add(X,O),L=n.mul(A,O),X=n.add(N,N),X=n.add(X,N),J=n.mul(U,J),Z=n.mul(K,Z),X=n.add(X,J),J=n.sub(N,J),J=n.mul(U,J),Z=n.add(Z,J),N=n.mul(X,Z),L=n.add(L,N),N=n.mul(pt,Z),A=n.mul(tt,A),A=n.sub(A,N),N=n.mul(tt,X),O=n.mul(pt,O),O=n.add(O,N),new B(A,L,O)}subtract(m){return D(m),this.add(m.negate())}is0(){return this.equals(B.ZERO)}multiply(m){let{endo:y}=t;if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let v,w,x=I=>q.cached(this,I,T=>be(B,T));if(y){let{k1neg:I,k1:T,k2neg:A,k2:L}=k(m),{p:O,f:U}=x(T),{p:K,f:N}=x(L);w=U.add(N),v=C(y.beta,O,K,I,A)}else{let{p:I,f:T}=x(m);v=I,w=T}return be(B,[v,w])[0]}multiplyUnsafe(m){let{endo:y}=t,v=this,w=m;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Ft||v.is0())return B.ZERO;if(w===ie)return v;if(q.hasCache(this))return this.multiply(w);if(y){let{k1neg:x,k1:I,k2neg:T,k2:A}=k(w),{p1:L,p2:O}=Oa(B,v,I,A);return C(y.beta,L,O,x,T)}else return q.unsafe(v,w)}toAffine(m){let y=this,v=m,{X:w,Y:x,Z:I}=y;if(n.eql(I,n.ONE))return{x:w,y:x};let T=y.is0();v==null&&(v=T?n.ONE:n.inv(I));let A=n.mul(w,v),L=n.mul(x,v),O=n.mul(I,v);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:A,y:L}}isTorsionFree(){let{isTorsionFree:m}=t;return i===ie?!0:m?m(B,this):q.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===ie?this:m?m(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ie?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Tt(m,"isCompressed"),this.assertValidity(),g(B,this,m)}toHex(m=!0){return Ne(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,q=new Ve(B,t.endo?Math.ceil(P/2):P);return P>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function ic(r){return Uint8Array.of(r?2:3)}function ac(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function kl(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?Er:t.randomBytes,o=Object.assign(ac(r.Fp,e),{seed:Math.max(ts(e.ORDER),16)});function s(p){try{let g=e.fromBytes(p);return e.isValidNot0(g)}catch{return!1}}function i(p,g){let{publicKey:E,publicKeyUncompressed:h}=o;try{let b=p.length;return g===!0&&b!==E||g===!1&&b!==h?!1:!!r.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,es(M(p,o.seed,"seed"),e.ORDER)}function c(p,g=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(g)}function u(p){let{secretKey:g,publicKey:E,publicKeyUncompressed:h}=o,b=e._lengths;if(!he(p))return;let S=M(p,void 0,"key").length,_=S===E||S===h,R=S===g||!!b?.includes(S);if(!(_&&R))return _}function f(p,g,E=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(g)===!1)throw new Error("second arg must be public key");let h=e.fromBytes(p);return r.fromBytes(g).multiply(h).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=yn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:r,utils:l,lengths:o})}function cc(r,t,e={}){let n=t;on(n),Lt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?Er:e.randomBytes,s=e.hmac===void 0?(w,x)=>rc(n,w,x):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:p,lengths:g}=kl(r,e),E={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},h=c*oc+ie<i.ORDER;function b(w){let x=c>>ie;return w>x}function S(w,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return x}function _(){if(h)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(w,x){Cs(x);let I=g.signature,T=x==="compact"?I:x==="recovered"?I+1:void 0;return M(w,T)}class D{r;s;recovery;constructor(x,I,T){if(this.r=S("r",x),this.s=S("s",I),T!=null){if(_(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(x,I=E.format){R(x,I);let T;if(I==="der"){let{r:U,s:K}=Ct.toSig(M(x));return new D(U,K)}I==="recovered"&&(T=x[0],I="compact",x=x.subarray(1));let A=g.signature/2,L=x.subarray(0,A),O=x.subarray(A,A*2);return new D(a.fromBytes(L),a.fromBytes(O),T)}static fromHex(x,I){return this.fromBytes(Ue(x),I)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new D(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:T}=this,A=this.assertRecovery(),L=A===2||A===3?I+c:I;if(!i.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(L),U=r.fromBytes(Q(ic((A&1)===0),O)),K=a.inv(L),N=C(M(x,void 0,"msgHash")),X=a.create(-N*K),J=a.create(T*K),tt=r.BASE.multiplyUnsafe(X).add(U.multiplyUnsafe(J));if(tt.is0())throw new Error("invalid recovery: point at infinify");return tt.assertValidity(),tt}hasHighS(){return b(this.s)}toBytes(x=E.format){if(Cs(x),x==="der")return Ue(Ct.hexFromSig(this));let{r:I,s:T}=this,A=a.toBytes(I),L=a.toBytes(T);return x==="recovered"?(_(),Q(Uint8Array.of(this.assertRecovery()),A,L)):Q(A,L)}toHex(x){return Ne(this.toBytes(x))}}Object.freeze(D.prototype),Object.freeze(D);let k=e.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=pe(x),T=x.length*8-u;return T>0?I>>BigInt(T):I}:e.bits2int,C=e.bits2int_modN===void 0?function(x){return a.create(k(x))}:e.bits2int_modN,B=_r(u);function P(w){return Me("num < 2^"+u,w,Ft,B),a.toBytes(w)}function q(w,x){return M(w,void 0,"message"),x?M(n(w),void 0,"prehashed message"):w}function F(w,x,I){let{lowS:T,prehash:A,extraEntropy:L}=Rs(I,E);w=q(w,A);let O=C(w),U=a.fromBytes(x);if(!a.isValidNot0(U))throw new Error("invalid private key");let K=[P(U),P(O)];if(L!=null&&L!==!1){let tt=L===!0?o(g.secretKey):L;K.push(M(tt,void 0,"extraEntropy"))}let N=Q(...K),X=O;function J(tt){let Z=k(tt);if(!a.isValidNot0(Z))return;let pt=a.inv(Z),Te=r.BASE.multiply(Z).toAffine(),ir=a.create(Te.x);if(ir===Ft)return;let Zr=a.create(pt*a.create(X+ir*U));if(Zr===Ft)return;let bi=(Te.x===ir?0:2)|Number(Te.y&ie),yi=Zr;return T&&b(Zr)&&(yi=a.neg(Zr),bi^=1),new D(ir,yi,h?void 0:bi)}return{seed:N,k2sig:J}}function m(w,x,I={}){let{seed:T,k2sig:A}=F(w,x,I);return ga(n.outputLen,a.BYTES,s)(T,A).toBytes(I.format)}function y(w,x,I,T={}){let{lowS:A,prehash:L,format:O}=Rs(T,E);if(I=M(I,void 0,"publicKey"),x=q(x,L),!he(w)){let U=w instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}R(w,O);try{let U=D.fromBytes(w,O),K=r.fromBytes(I);if(A&&U.hasHighS())return!1;let{r:N,s:X}=U,J=C(x),tt=a.inv(X),Z=a.create(J*tt),pt=a.create(N*tt),Te=r.BASE.multiplyUnsafe(Z).add(K.multiplyUnsafe(pt));return Te.is0()?!1:a.create(Te.x)===N}catch{return!1}}function v(w,x,I={}){let{prehash:T}=Rs(I,E);return x=q(x,T),D.fromBytes(w,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:p,lengths:g,Point:r,sign:m,verify:y,recoverPublicKey:v,Signature:D,hash:n})}var Ps={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Pl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var uc=BigInt(2);function Fl(r){let t=Ps.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,f=u*u*r%t,l=V(f,e,t)*f%t,d=V(l,e,t)*f%t,p=V(d,uc,t)*u%t,g=V(p,o,t)*p%t,E=V(g,s,t)*g%t,h=V(E,a,t)*E%t,b=V(h,c,t)*h%t,S=V(b,a,t)*E%t,_=V(S,e,t)*f%t,R=V(_,i,t)*g%t,D=V(R,n,t)*u%t,k=V(D,uc,t);if(!ks.eql(ks.sqr(k),r))throw new Error("Cannot find square root");return k}var ks=ze(Ps.p,{sqrt:Fl}),Nl=sc(Ps,{Fp:ks,endo:Pl}),je=cc(Nl,ha);function fc(r,t,e,n){let o=hr.digest(e instanceof Uint8Array?e:e.subarray());if(vn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),je.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Tr(String(s))});try{return n?.signal?.throwIfAborted(),je.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new Tr(String(s))}}var Rn=class{type="secp256k1";raw;_key;constructor(t){this._key=dc(t),this.raw=lc(this._key)}toMultihash(){return At.digest(Pe(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return fc(this._key,e,t,n)}};function hc(r){return new Rn(r)}function lc(r){return je.Point.fromBytes(r).toBytes()}function dc(r){try{return je.Point.fromBytes(r),r}catch(t){throw new Yr(String(t))}}function pc(r){let{Type:t,Data:e}=kr.decode(r.digest),n=e??new Uint8Array;switch(t){case ht.Ed25519:return $a(n);case ht.secp256k1:return hc(n);case ht.ECDSA:return Xi(n);default:throw new ar}}function Pe(r){return kr.encode({Type:ht[r.type],Data:r.raw})}var mc=Symbol.for("nodejs.util.inspect.custom"),Ul=114,Pr=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()})`}[co]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(Ul,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[mc](){return`PeerId(${this.toString()})`}},Cn=class extends Pr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},On=class extends Pr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},kn=class extends Pr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ml=2336,Pn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(H(this.url))}[mc](){return`PeerId(${this.url})`}[co]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(Ml,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=W(t)),t.toString()===this.toString())}};function gc(r){if(zl(r))return new Cn({multihash:r});if(Kl(r))try{let t=pc(r);if(t.type==="Ed25519")return new On({multihash:r,publicKey:t});if(t.type==="secp256k1")return new kn({multihash:r,publicKey:t})}catch{let e=W(r.digest);return new Pn(new URL(e))}throw new Xr("Supplied PeerID Multihash is invalid")}function Kl(r){return r.code===At.code}function zl(r){return r.code===hr.code}function Fs(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 Fn(r){let t=lr(G.decode(`z${r}`));return gc(t)}var Nn=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 Fs(this.set.entries(),t=>{let e=Fn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Fn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Fs(this.set.values(),t=>Fn(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 Ns(){return new Nn}var Us={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},bc={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},yc=new globalThis.TextEncoder;function ql(r,t){let e=Us[t],n=bc[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Vl(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Us[t],o=bc[t],s=r;for(;s.length>0;){let i=yc.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 Ms(r,{size:t=32,utf8Buffer:e}={}){if(!Us[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 Vl(r,t,e);r=yc.encode(r)}return ql(r,t)}var Fr={hash:r=>Number(Ms(r,{size:32})),hashV:(r,t)=>Hl(Fr.hash(r,t))};function Hl(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),H(t,"base16")}var Ks=64,Ot=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Ks)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=yt(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?dt(this.fp,t.fp):!1}};function Ee(r,t){return Math.floor(Math.random()*(t-r))+r}var Se=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Ot))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Ot))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 Ot))throw new TypeError("Invalid Fingerprint");let e=Ee(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Ot))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var $l=500,Nr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Fr,this.seed=t.seed??Ee(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=H(t));let e=new Ot(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 Se(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Se(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[Ee(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Se(this.bucketSize));for(let a=0;a<$l;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 Se(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=H(t));let e=new Ot(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 Ot(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}},jl={1:.5,2:.84,4:.95,8:.98};function Zl(r=.001){return r>.002?2:r>1e-5?4:8}function xc(r,t=.001){let e=Zl(t),n=jl[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Ks);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??Fr,this.seed=t.seed??Ee(0,Math.pow(2,10)),this.filterSeries=[new Nr({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 Nr({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 zs(r,t=.001,e){return new Un({...xc(r,t),...e??{}})}function ae(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 lt(`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 Mn=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 f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,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 wc=45,Gl=15,Ze=new Mn;function Kn(r){if(!(r.length>Gl))return Ze.new(r).parseWith(()=>Ze.readIPv4Addr())}function zn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>wc))return Ze.new(r).parseWith(()=>Ze.readIPv6Addr())}function Ge(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>wc)return;let e=Ze.new(r).parseWith(()=>Ze.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 Ec(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 Sc(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 qs(r){switch(r.length){case ve:return r.join(".");case _e:{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 vc(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 _c(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var ve=4,_e=16,ny=parseInt("0xFFFF",16),Yl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ur(r,t){t.length===_e&&r.length===ve&&Ec(t,0,11)&&(t=t.slice(12)),t.length===ve&&r.length===_e&&Sc(r,Yl,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 Ic(r,t){if(typeof t=="string"&&(t=Ge(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 Vs(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=ve,o=Kn(t);if(o==null&&(n=_e,o=zn(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=Hs(s,8*n);return{network:Ur(o,i),mask:i}}function Hs(r,t){if(t!==8*ve&&t!==8*_e)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 Mr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Vs(t));else{let n=Ge(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=Ge(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Hs(o,8*n.length);this.network=Ur(n,this.mask)}}contains(t){return Ic({network:this.network,mask:this.mask},t)}toString(){let t=vc(this.mask),e=t!==-1?String(t):_c(this.mask);return qs(this.network)+"/"+e}};function Ac(r,t){return new Mr(r).contains(t)}function Bc(r){try{let t=ae(r);return t.type==="ip6"?Ac("2000::/3",t.host):!1}catch{return!1}}function Ye(r){return!!Kn(r)}function qn(r){return!!zn(r)}var Rc=lu(Lc(),1),rd=["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"],nd=rd.map(r=>new Rc.Netmask(r));function Ws(r){for(let t of nd)if(t.contains(r))return!0;return!1}function od(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function sd(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 Ws(o)}function id(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function ad(r){let t=r.split(":"),e=t[t.length-1];return Ws(e)}function cd(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(Ye(r))return Ws(r);if(od(r))return sd(r);if(id(r))return ad(r);if(qn(r))return cd(r)}function Cc(r){try{let t=ae(r);switch(t.type){case"ip4":case"ip6":return Hn(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function Je(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var $n=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}},tr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new $n(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 $n(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 Qs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function jn(r={}){return ud(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 ud(r,t){t=t??{};let e=t.onEnd,n=new tr,o,s,i,a=Je(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,b)=>{s=S=>{s=null,n.push(S);try{h(r(n))}catch(_){b(_)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Je()})}},u=h=>s!=null?s(h):(n.push(h),o),f=h=>(n=new tr,s!=null?s({error:h}):(n.push({error:h}),o)),l=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:h})},d=h=>i?o:(i=!0,h!=null?f(h):u({done:!0})),p=()=>(n=new tr,d(),{done:!0}),g=h=>(d(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:g,push:l,end:d,get readableLength(){return n.size},onEmpty:async h=>{let b=h?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let S,_;b!=null&&(S=new Promise((R,D)=>{_=()=>{D(new Qs)},b.addEventListener("abort",_)}));try{await Promise.race([a.promise,S])}finally{_!=null&&b!=null&&b?.removeEventListener("abort",_)}}},e==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(h){return E.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return E.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(h){return E.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return E.readableLength},onEmpty:h=>E.onEmpty(h)},o}var Js=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Oc=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function ti(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,f=new Promise((l,d)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){d(Oc(i));return}if(i&&(c=()=>{d(Oc(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,d),e===Number.POSITIVE_INFINITY)return;let p=new Js;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(g){d(g)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?d(o):(p.message=o??`Promise timed out after ${e} milliseconds`,d(p))},e)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var fd=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 ld(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:f}=fd(r),l=async(...p)=>{let g=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(g))return}catch(E){n(),i(E);return}c.push(g),e.count===c.length&&(n(),s(c))},d=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)f(p,l);for(let p of e.rejectionEvents)a.includes(p)||f(p,d)};for(let p of a)u(p,l);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=ti(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function er(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=ld(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Kr(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 Zn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Ae=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function dd(r){return r.reason}async function zr(r,t,e){if(t==null)return r;let n=e?.translateError??dd;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 Gn=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=Je(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Mt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function hd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Yn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=hd(),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 Mt),this.cleanup())}async join(t){let e=new Gn(t);return this.recipients.push(e),t?.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await zr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:e=>{this.recipients.forEach(n=>{n.onProgress?.(e)})}}),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 Xn=class extends Wr{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=Kr(this.emitEmpty.bind(this),1),this.emitIdle=Kr(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 Zn;let n=new Yn(t,e);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(e).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Mt)}),this.clear()}async onEmpty(t){this.size!==0&&await er(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await er(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await er(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=jn({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 Mt("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 qr(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 it=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Zt=class extends Error{static name="ValidationError";name="ValidationError"},Wn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Qn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function ri(r){return t=>W(t,r)}function ni(r){return t=>H(t,r)}function rr(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 kc(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 zt([e,o],e.length+o.length)}function Pc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Xt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Be(n);return zt([e,o],e.length+o.length)}function oi(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=W(t,"base32"),o=rr(e);return`${n}:${o}`}var si=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 it("Invalid byte value in IP address");t[n]=o}),t},Fc=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Ye(e[n]),i;s&&(i=si(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 it("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Nc=function(r){if(r.byteLength!==4)throw new it("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Uc=function(r){if(r.byteLength!==16)throw new it("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 it(`Invalid IPv6 address "${e}"`)}};function Mc(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new it(`Invalid IPv6 address "${r}"`)}}var ei=Object.values(pr).map(r=>r.decoder),pd=(function(){let r=ei[0].or(ei[1]);return ei.slice(2).forEach(t=>r=r.or(t)),r})();function Kc(r){return pd.decode(r)}function zc(r){return t=>r.encoder.encode(t)}function md(r){if(parseInt(r).toString()!==r)throw new Zt("Value must be an integer")}function gd(r){if(r<0)throw new Zt("Value must be a positive integer, or zero")}function bd(r){return t=>{if(t>r)throw new Zt(`Value must be smaller than or equal to ${r}`)}}function yd(...r){return t=>{for(let e of r)e(t)}}var Vr=yd(md,gd,bd(65535));var nt=-1,ii=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 Qn(`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)}))}},Gt=new ii,nh=[{code:4,name:"ip4",size:32,valueToBytes:si,bytesToValue:Nc,validate:r=>{if(!Ye(r))throw new Zt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Be,bytesToValue:rr,validate:Vr},{code:273,name:"udp",size:16,valueToBytes:Be,bytesToValue:rr,validate:Vr},{code:33,name:"dccp",size:16,valueToBytes:Be,bytesToValue:rr,validate:Vr},{code:41,name:"ip6",size:128,valueToBytes:Fc,bytesToValue:Uc,stringToValue:Mc,validate:r=>{if(!qn(r))throw new Zt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:nt},{code:43,name:"ipcidr",size:8,bytesToValue:ri("base10"),valueToBytes:ni("base10")},{code:53,name:"dns",size:nt},{code:54,name:"dns4",size:nt},{code:55,name:"dns6",size:nt},{code:56,name:"dnsaddr",size:nt},{code:132,name:"sctp",size:16,valueToBytes:Be,bytesToValue:rr,validate:Vr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:nt,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:nt,bytesToValue:ri("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ni("base58btc")(r):ct.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:oi,valueToBytes:kc},{code:445,name:"onion3",size:296,bytesToValue:oi,valueToBytes:Pc},{code:446,name:"garlic64",size:nt},{code:447,name:"garlic32",size:nt},{code:448,name:"tls"},{code:449,name:"sni",size:nt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:nt,bytesToValue:zc(_o),valueToBytes:Kc},{code:480,name:"http"},{code:481,name:"http-path",size:nt,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:nt}];nh.forEach(r=>{Gt.addProtocol(r)});function qc(r){let t=[],e=0;for(;e<r.length;){let n=Dr(r,e),o=Gt.getProtocol(n),s=gt(n),i=oh(o,r,e+s),a=0;i>0&&o.size===nt&&(a=gt(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let f=e+s+a,l=r.subarray(f,f+i);u.value=o.bytesToValue?.(l)??W(l)}t.push(u),e+=c}return t}function Vc(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Gt.getProtocol(n.code),s=gt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??H(n.value),a=i.byteLength,o.size===nt&&(c=gt(a)));let u=new Uint8Array(s+c+a),f=0;$e(n.code,u,f),f+=s,i!=null&&(o.size===nt&&($e(a,u,f),f+=c),u.set(i,f)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return zt(e,t)}function Hc(r){if(r.charAt(0)!=="/")throw new it('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=Gt.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 it(`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 it(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new it("Incomplete multiaddr");return t}function $c(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Gt.getProtocol(t.code);if(e==null)throw new it(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function oh(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Dr(t,e)}var sh=Symbol.for("nodejs.util.inspect.custom"),ui=Symbol.for("@multiformats/multiaddr");function ih(r){if(r==null&&(r="/"),jc(r))return r.getComponents();if(r instanceof Uint8Array)return qc(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Hc(r);if(Array.isArray(r))return r;throw new it("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Jn=class r{[ui]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=ih(t),e.validate!==!1&&ah(this)}get bytes(){return this.#r==null&&(this.#r=Vc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=$c(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 Wn(`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 dt(this.bytes,t.bytes)}[sh](){return`Multiaddr(${this.toString()})`}};function ah(r){r.getComponents().forEach(t=>{let e=Gt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function jc(r){return!!r?.[ui]}function Zc(r){return new Jn(r)}var ch=4194304,to=class extends Error{static name="UnwrappedError";name="UnwrappedError"},li=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},di=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},hi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function uh(r){return typeof r?.closeRead=="function"}function fh(r){return typeof r?.close=="function"}function fi(r){return uh(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:fh(r)?r.status!=="open":!1}function lh(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function dh(r,t){let e=t?.maxBufferSize??ch,n=new et,o,s=!1;if(!lh(r))throw new lt("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>e){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(s===!0)throw new to("Stream was unwrapped");if(fi(r)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Ae(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await zr(o.promise,f?.signal),fi(r)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let d=f?.bytes??n.byteLength;if(n.byteLength<d){if(fi(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Ae(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(f)}let p=n.sublist(0,d);return n.consume(d),p},async write(f,l){if(s===!0)throw new to("Stream was unwrapped");r.send(f)||await er(r,"drain",{signal:l?.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 hh(r,t={}){let e=dh(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=gt(t.maxDataLength));let n=t?.lengthDecoder??Dr,o=t?.lengthEncoder??ja;return{async read(i){let a=-1,c=new et;for(;;){let f=await e.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new li("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new hi(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new di(`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 Ae(`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 Ae(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new et(o(i.byteLength),i),a)},async writeV(i,a){let c=new et(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function nr(r,t){let e=hh(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 eo=class extends Xn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Gc(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal},f;e?.timeout!=null&&(f=qr([o.signal,AbortSignal.timeout(e.timeout)]),u.signal=f),s=!0,Promise.resolve().then(async()=>{await r(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Kr(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 pi=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 Yc(r){let{name:t,metrics:e}=r,n;return e!=null?n=new pi({name:t,metrics:e}):n=new Map,n}var mi="libp2p",gi="autonat";var Xc="dial-request",Wc="dial-back",Qc=200n*1024n,Jc=4096;var or;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s={...s},s.dialDataResponse!=null&&(s.dialDataRequest=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialDataRequest!=null&&(s.dialDataResponse=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialResponse!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialRequest=void 0),s.dialRequest!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialResponse=void 0),s.dialRequest!=null&&(i.uint32(10),Hr.codec().encode(s.dialRequest,i)),s.dialResponse!=null&&(i.uint32(18),Ut.codec().encode(s.dialResponse,i)),s.dialDataRequest!=null&&(i.uint32(26),$r.codec().encode(s.dialDataRequest,i)),s.dialDataResponse!=null&&(i.uint32(34),jr.codec().encode(s.dialDataResponse,i)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.dialRequest=Hr.codec().decode(s,s.uint32(),{limits:a.limits?.dialRequest});break}case 2:{c.dialResponse=Ut.codec().decode(s,s.uint32(),{limits:a.limits?.dialResponse});break}case 3:{c.dialDataRequest=$r.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataRequest});break}case 4:{c.dialDataResponse=jr.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}return c.dialDataResponse!=null&&(delete c.dialDataRequest,delete c.dialResponse,delete c.dialRequest),c.dialDataRequest!=null&&(delete c.dialDataResponse,delete c.dialResponse,delete c.dialRequest),c.dialResponse!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialRequest),c.dialRequest!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialResponse),c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield*Hr.codec().stream(s,s.uint32(),`${a}.dialRequest`,{limits:c.limits?.dialRequest});break}case 2:{yield*Ut.codec().stream(s,s.uint32(),`${a}.dialResponse`,{limits:c.limits?.dialResponse});break}case 3:{yield*$r.codec().stream(s,s.uint32(),`${a}.dialDataRequest`,{limits:c.limits?.dialDataRequest});break}case 4:{yield*jr.codec().stream(s,s.uint32(),`${a}.dialDataResponse`,{limits:c.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}})),t);function e(s){return vt(s,r.codec())}r.encode=e;function n(s,i){return St(s,r.codec(),i)}r.decode=n;function o(s,i){return _t(s,r.codec(),i)}r.stream=o})(or||(or={}));var Hr;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.addrs!=null&&s.addrs.length>0)for(let c of s.addrs)i.uint32(10),i.bytes(c);s.nonce!=null&&s.nonce!==0n&&(i.uint32(17),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrs:[],nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(a.limits?.addrs!=null&&c.addrs.length===a.limits.addrs)throw new Or('Decode error - repeated field "addrs" had too many elements');c.addrs.push(s.bytes());break}case 2:{c.nonce=s.fixed64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={addrs:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(c.limits?.addrs!=null&&u.addrs===c.limits.addrs)throw new Or('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${a}.addrs[]`,index:u.addrs,value:s.bytes()},u.addrs++;break}case 2:{yield{field:`${a}.nonce`,value:s.fixed64()};break}default:{s.skipType(l&7);break}}}})),t);function e(s){return vt(s,r.codec())}r.encode=e;function n(s,i){return St(s,r.codec(),i)}r.decode=n;function o(s,i){return _t(s,r.codec(),i)}r.stream=o})(Hr||(Hr={}));var $r;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.addrIdx!=null&&s.addrIdx!==0&&(i.uint32(8),i.uint32(s.addrIdx)),s.numBytes!=null&&s.numBytes!==0n&&(i.uint32(16),i.uint64(s.numBytes)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrIdx:0,numBytes:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.addrIdx=s.uint32();break}case 2:{c.numBytes=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.addrIdx`,value:s.uint32()};break}case 2:{yield{field:`${a}.numBytes`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),t);function e(s){return vt(s,r.codec())}r.encode=e;function n(s,i){return St(s,r.codec(),i)}r.decode=n;function o(s,i){return _t(s,r.codec(),i)}r.stream=o})($r||($r={}));var at;(function(r){r.UNUSED="UNUSED",r.E_DIAL_ERROR="E_DIAL_ERROR",r.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",r.OK="OK"})(at||(at={}));var ro;(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"})(ro||(ro={}));(function(r){r.codec=()=>we(ro)})(at||(at={}));var Ut;(function(r){let t;(function(a){a.E_INTERNAL_ERROR="E_INTERNAL_ERROR",a.E_REQUEST_REJECTED="E_REQUEST_REJECTED",a.E_DIAL_REFUSED="E_DIAL_REFUSED",a.OK="OK"})(t=r.ResponseStatus||(r.ResponseStatus={}));let e;(function(a){a[a.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",a[a.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",a[a.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",a[a.OK=200]="OK"})(e||(e={})),(function(a){a.codec=()=>we(e)})(t=r.ResponseStatus||(r.ResponseStatus={}));let n;r.codec=()=>(n==null&&(n=It((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&e[a.status]!==0&&(c.uint32(8),r.ResponseStatus.codec().encode(a.status,c)),a.addrIdx!=null&&a.addrIdx!==0&&(c.uint32(16),c.uint32(a.addrIdx)),a.dialStatus!=null&&ro[a.dialStatus]!==0&&(c.uint32(24),at.codec().encode(a.dialStatus,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:at.UNUSED},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{f.status=r.ResponseStatus.codec().decode(a);break}case 2:{f.addrIdx=a.uint32();break}case 3:{f.dialStatus=at.codec().decode(a);break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{yield{field:`${u}.status`,value:r.ResponseStatus.codec().decode(a)};break}case 2:{yield{field:`${u}.addrIdx`,value:a.uint32()};break}case 3:{yield{field:`${u}.dialStatus`,value:at.codec().decode(a)};break}default:{a.skipType(d&7);break}}}})),n);function o(a){return vt(a,r.codec())}r.encode=o;function s(a,c){return St(a,r.codec(),c)}r.decode=s;function i(a,c){return _t(a,r.codec(),c)}r.stream=i})(Ut||(Ut={}));var jr;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.data!=null&&s.data.byteLength>0&&(i.uint32(10),i.bytes(s.data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={data:yt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.data=s.bytes():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.data`,value:s.bytes()}:s.skipType(f&7)}})),t);function e(s){return vt(s,r.codec())}r.encode=e;function n(s,i){return St(s,r.codec(),i)}r.decode=n;function o(s,i){return _t(s,r.codec(),i)}r.stream=o})(jr||(jr={}));var sr;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.nonce!=null&&s.nonce!==0n&&(i.uint32(9),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.nonce=s.fixed64():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.nonce`,value:s.fixed64()}:s.skipType(f&7)}})),t);function e(s){return vt(s,r.codec())}r.encode=e;function n(s,i){return St(s,r.codec(),i)}r.decode=n;function o(s,i){return _t(s,r.codec(),i)}r.stream=o})(sr||(sr={}));var ue;(function(r){let t;(function(a){a.OK="OK"})(t=r.DialBackStatus||(r.DialBackStatus={}));let e;(function(a){a[a.OK=0]="OK"})(e||(e={})),(function(a){a.codec=()=>we(e)})(t=r.DialBackStatus||(r.DialBackStatus={}));let n;r.codec=()=>(n==null&&(n=It((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&e[a.status]!==0&&(c.uint32(8),r.DialBackStatus.codec().encode(a.status,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.OK},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?f.status=r.DialBackStatus.codec().decode(a):a.skipType(d&7)}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?yield{field:`${u}.status`,value:r.DialBackStatus.codec().decode(a)}:a.skipType(d&7)}})),n);function o(a){return vt(a,r.codec())}r.encode=o;function s(a,c){return St(a,r.codec(),c)}r.decode=s;function i(a,c){return _t(a,r.codec(),c)}r.stream=i})(ue||(ue={}));function no(r,t){return Math.round(Math.random()*(t-r)+r)}var mh=4,gh=8,oo=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=Yc({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=Gc(this.findRandomPeers.bind(this),6e4),this.addressFilter=zs(1024),this.queue=new eo({concurrency:3,maxSize:50}),this.maxDialDataBytes=e.maxDialDataBytes??Qc,this.dialDataChunkSize=e.dialDataChunkSize??Jc,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[Qr]=["@libp2p/autonat"];get[Jr](){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=qr([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=nr(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read(sr,{signal:n});if(!this.nonces.has(s.nonce))throw new Et("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:ue.DialBackStatus.OK},ue),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())||ae(s.multiaddr).type==="ip6"&&(!e||!Bc(s.multiaddr))||Cc(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:Ns(),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})=>ae(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=qr([i.signal,AbortSignal.timeout(this.timeout)]),c=BigInt(no(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=nr(i).pb(or);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),g=BigInt(this.dialDataChunkSize);for(let E=0n;E<u.dialDataRequest.numBytes;E+=g)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!==Ut.ResponseStatus.OK)return;let l=s[u.dialResponse.addrIdx];if(l==null){this.log.trace("peer dialed unknown address");continue}let d=this.dialResults.get(l.toString());if(d==null){this.log.trace("peer reported %a as %s but there is no result object",l,u.dialResponse.status);continue}if(d.networkSegments.includes(e)){this.log.trace("%a results already included network segment %s",l,e);continue}if(d.result!=null){this.log.trace("already resolved result for %a, ignoring response from",l,t.remotePeer);continue}if(d.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,l);continue}if(d.verifyingPeers.add(t.remotePeer),d.networkSegments.push(e),u.dialResponse.dialStatus===at.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===at.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,d.multiaddr),d.failure++;else if(u.dialResponse.dialStatus===at.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===mh&&this.confirmAddress(d),d.failure===gh&&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=ae(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 lt(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};var so=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=nr(t,{maxDataLength:this.maxMessageSize}).pb(or),s=ou(e.remoteAddr);if(s==null)throw new Et(`Could not find IP address in connection address "${e.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new Et("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new Et("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=Zc(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:Ut.ResponseStatus.E_DIAL_REFUSED,dialStatus:at.UNUSED}},{signal:n});continue}let f=ou(c);if(f==null)throw new Et(`Could not find IP address in requested address "${c}"`);if(Hn(f))throw new Et(`Requested address had private IP "${c}"`);f!==s&&await this.preventAmplificationAttack(o,a,{signal:n});let l=await this.dialClientBack(c,i.nonce,{signal:n});await o.write({dialResponse:{addrIdx:a,status:Ut.ResponseStatus.OK,dialStatus:l}},{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=no(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 Et("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),at.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=nr(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:e},sr,n),(await i.read(ue,n)).status!==ue.DialBackStatus.OK)throw new Et("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),at.E_DIAL_BACK_ERROR}return at.OK}};function ou(r){return r.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var io=class{client;server;constructor(t,e){let n=`/${e.protocolPrefix??mi}/${gi}/${"2"}/${Xc}`,o=`/${e.protocolPrefix??mi}/${gi}/${"2"}/${Wc}`;this.client=new oo(t,{...e,dialRequestProtocol:n,dialBackProtocol:o}),this.server=new so(t,{...e,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[Qr]=["@libp2p/autonat"];get[Jr](){return["@libp2p/identify"]}async start(){await Ei(this.client,this.server)}async stop(){await Si(this.client,this.server)}};function bh(r={}){return t=>new io(t,r)}return du(yh);})();
3
3
  /*! Bundled license information:
4
4
 
5
- @noble/hashes/utils.js:
6
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7
-
8
5
  @noble/curves/utils.js:
9
6
  @noble/curves/abstract/modular.js:
10
7
  @noble/curves/abstract/curve.js: