@libp2p/autonat 3.0.14 → 3.0.15-90100be0c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +8 -8
- package/dist/typedoc-urls.json +0 -8
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PAutonat=(()=>{var Ga=Object.create;var Er=Object.defineProperty;var Za=Object.getOwnPropertyDescriptor;var Ya=Object.getOwnPropertyNames;var Xa=Object.getPrototypeOf,Wa=Object.prototype.hasOwnProperty;var Qa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)Er(r,e,{get:t[e],enumerable:!0})},ws=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ya(t))!Wa.call(r,o)&&o!==e&&Er(r,o,{get:()=>t[o],enumerable:!(n=Za(t,o))||n.enumerable});return r};var Ja=(r,t,e)=>(e=r!=null?Ga(Xa(r)):{},ws(t||!r||!r.__esModule?Er(e,"default",{value:r,enumerable:!0}):e,r)),tc=r=>ws(Er({},"__esModule",{value:!0}),r);var _a=Qa(gr=>{(function(){var r,t,e,n,o,s,i,c;c=function(a){var u,d,l,f;return u=(a&255<<24)>>>24,d=(a&255<<16)>>>16,l=(a&65280)>>>8,f=a&255,[u,d,l,f].join(".")},i=function(a){var u,d,l,f,p,m;for(u=[],l=f=0;f<=3&&a.length!==0;l=++f){if(l>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}m=t(a),p=m[0],d=m[1],a=a.substring(d),u.push(p)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(a){return a.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(a){var u,d,l,f,p;for(f=0,u=10,d="9",l=0,a.length>1&&a[l]==="0"&&(a[l+1]==="x"||a[l+1]==="X"?(l+=2,u=16):"0"<=a[l+1]&&a[l+1]<="9"&&(l++,u=8,d="7")),p=l;l<a.length;){if("0"<=a[l]&&a[l]<=d)f=f*u+(e(a[l])-n)>>>0;else if(u===16)if("a"<=a[l]&&a[l]<="f")f=f*u+(10+e(a[l])-s)>>>0;else if("A"<=a[l]&&a[l]<="F")f=f*u+(10+e(a[l])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");l++}if(l===p)throw new Error("empty octet");return[f,l]},r=(function(){function a(u,d){var l,f,p,m;if(typeof u!="string")throw new Error("Missing `net' parameter");if(d||(m=u.split("/",2),u=m[0],d=m[1]),d||(d=32),typeof d=="string"&&d.indexOf(".")>-1){try{this.maskLong=i(d)}catch(S){throw l=S,new Error("Invalid mask: "+d)}for(f=p=32;p>=0;f=--p)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;break}}else if(d||d===0)this.bitmask=parseInt(d,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(S){throw l=S,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+d);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var d,l,f;for(f=i(this.first),l=i(this.last),d=0;f<=l;)u(c(f),f,d),d++,f++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a})(),gr.ip2long=i,gr.long2ip=c,gr.Netmask=r}).call(gr)});var Ql={};bt(Ql,{autoNAT:()=>Wl});var Tt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ft=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Sr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var vr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var qe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Sn=Symbol.for("@libp2p/peer-id");var _r=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Es=Symbol.for("@libp2p/service-capabilities"),Ss=Symbol.for("@libp2p/service-dependencies");var Ln={};bt(Ln,{base58btc:()=>X,base58flickr:()=>ac});var Td=new Uint8Array(0);function vs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Bt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function _s(r){return new TextEncoder().encode(r)}function As(r){return new TextDecoder().decode(r)}function ec(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var S=0,x=0,h=0,g=m.length;h!==g&&m[h]===0;)h++,S++;for(var b=(g-h)*d+1>>>0,_=new Uint8Array(b);h!==g;){for(var L=m[h],C=0,U=b-1;(L!==0||C<x)&&U!==-1;U--,C++)L+=256*_[U]>>>0,_[U]=L%c>>>0,L=L/c>>>0;if(L!==0)throw new Error("Non-zero carry");x=C,h++}for(var A=b-x;A!==b&&_[A]===0;)A++;for(var v=a.repeat(S);A<b;++A)v+=r.charAt(_[A]);return v}function f(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var S=0;if(m[S]!==" "){for(var x=0,h=0;m[S]===a;)x++,S++;for(var g=(m.length-S)*u+1>>>0,b=new Uint8Array(g);m[S];){var _=e[m.charCodeAt(S)];if(_===255)return;for(var L=0,C=g-1;(_!==0||L<h)&&C!==-1;C--,L++)_+=c*b[C]>>>0,b[C]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");h=L,S++}if(m[S]!==" "){for(var U=g-h;U!==g&&b[U]===0;)U++;for(var A=new Uint8Array(x+(g-U)),v=x;U!==g;)A[v++]=b[U++];return A}}}function p(m){var S=f(m);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:p}}var rc=ec,nc=rc,Ls=nc;var vn=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")}},_n=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 Ts(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return Ts(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 Ts(r,t){return new An({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var In=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 vn(t,e,n),this.decoder=new _n(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ge({name:r,prefix:t,encode:e,decode:n}){return new In(r,t,e,n)}function Ht({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ls(e,r);return ge({prefix:t,name:r,encode:n,decode:s=>Bt(o(s))})}function oc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let d=t[r[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|d,i+=e,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=e||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function sc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function ic(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=ic(n);return ge({prefix:t,name:r,encode(s){return sc(s,n,e)},decode(s){return oc(s,o,e,r)}})}var X=Ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ac=Ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Tn={};bt(Tn,{base32:()=>$t,base32hex:()=>lc,base32hexpad:()=>hc,base32hexpadupper:()=>pc,base32hexupper:()=>dc,base32pad:()=>uc,base32padupper:()=>fc,base32upper:()=>cc,base32z:()=>mc});var $t=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cc=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),uc=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),fc=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),lc=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),dc=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hc=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),pc=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),mc=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Bn={};bt(Bn,{base36:()=>ze,base36upper:()=>gc});var ze=Ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gc=Ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var bc=Cs,Bs=128,yc=127,xc=~yc,wc=Math.pow(2,31);function Cs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=wc;)t[e++]=r&255|Bs,r/=128;for(;r&xc;)t[e++]=r&255|Bs,r>>>=7;return t[e]=r|0,Cs.bytes=e-n+1,t}var Ec=Dn,Sc=128,Ds=127;function Dn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw Dn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ds)<<o:(i&Ds)*Math.pow(2,o),o+=7}while(i>=Sc);return Dn.bytes=s-n,e}var vc=Math.pow(2,7),_c=Math.pow(2,14),Ac=Math.pow(2,21),Ic=Math.pow(2,28),Lc=Math.pow(2,35),Tc=Math.pow(2,42),Bc=Math.pow(2,49),Dc=Math.pow(2,56),Cc=Math.pow(2,63),Rc=function(r){return r<vc?1:r<_c?2:r<Ac?3:r<Ic?4:r<Lc?5:r<Tc?6:r<Bc?7:r<Dc?8:r<Cc?9:10},Pc={encode:bc,decode:Ec,encodingLength:Rc},Oc=Pc,Ve=Oc;function He(r,t=0){return[Ve.decode(r,t),Ve.decode.bytes]}function be(r,t,e=0){return Ve.encode(r,t,e),t}function ye(r){return Ve.encodingLength(r)}function we(r,t){let e=t.byteLength,n=ye(r),o=n+ye(e),s=new Uint8Array(o+e);return be(r,s,0),be(e,s,n),s.set(t,o),new xe(r,e,t,s)}function te(r){let t=Bt(r),[e,n]=He(t),[o,s]=He(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new xe(e,o,i,t)}function Rs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&vs(r.bytes,e.bytes)}}var xe=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ps(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return kc(e,Cn(r),t??X.encoder);default:return Uc(e,Cn(r),t??$t.encoder)}}var Os=new WeakMap;function Cn(r){let t=Os.get(r);if(t==null){let e=new Map;return Os.set(r,e),e}return t}var at=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==$e)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Mc)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=we(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Rs(t.multihash,n.multihash)}toString(t){return Ps(this,t)}toJSON(){return{"/":Ps(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Ns(n,o,s.bytes))}else if(e[Kc]===!0){let{version:n,multihash:o,code:s}=e,i=te(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==$e)throw new Error(`Version 0 CID must use dag-pb (code: ${$e}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ns(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,$e,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Bt(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 xe(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,f]=He(t.subarray(e));return e+=f,l},o=n(),s=$e;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),u=e+a,d=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:d,size:u}}static parse(t,e){let[n,o]=Nc(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 Cn(s).set(n,t),s}};function Nc(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 $t.prefix:{let e=t??$t;return[$t.prefix,e.decode(r)]}case ze.prefix:{let e=t??ze;return[ze.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function kc(r,t,e){let{prefix:n}=e;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Uc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var $e=112,Mc=18;function Ns(r,t,e){let n=ye(r),o=n+ye(t),s=new Uint8Array(o+e.byteLength);return be(r,s,0),be(t,s,n),s.set(e,o),s}var Kc=Symbol.for("@ipld/js-cid/CID");var Rn={};bt(Rn,{identity:()=>xt});var ks=0,Fc="identity",Us=Bt;function qc(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 we(ks,Us(r))}var xt={code:ks,name:Fc,encode:Us,digest:qc};function lt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function wt(r=0){return new Uint8Array(r)}function pt(r=0){return new Uint8Array(r)}function Dt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=pt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ks=Symbol.for("@achingbrain/uint8arraylist");function Ms(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Ir(r){return!!r?.[Ks]}var J=class r{bufs;length;[Ks]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Ir(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(Ir(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ms(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ms(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Ir(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Dt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Dt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,d=e>c&&e<=a;if(u&&d){if(t===c&&e===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(d){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ir(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 c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let l=e;l<=a;l+=d){d=0;for(let f=u;f>=0;f--){let p=this.get(l+f);if(n[f]!==p){d=Math.max(1,f-c[p]);break}}if(d===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 o=wt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=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 o=wt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!lt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Pn={};bt(Pn,{base10:()=>zc});var zc=Ht({prefix:"9",name:"base10",alphabet:"0123456789"});var On={};bt(On,{base16:()=>Vc,base16upper:()=>Hc});var Vc=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Hc=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Nn={};bt(Nn,{base2:()=>$c});var $c=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var kn={};bt(kn,{base256emoji:()=>Xc});var Fs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),jc=Fs.reduce((r,t,e)=>(r[e]=t,r),[]),Gc=Fs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Zc(r){return r.reduce((t,e)=>(t+=jc[e],t),"")}function Yc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Gc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Xc=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Zc,decode:Yc});var Mn={};bt(Mn,{base64:()=>Wc,base64pad:()=>Qc,base64url:()=>Un,base64urlpad:()=>Jc});var Wc=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qc=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Un=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jc=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Kn={};bt(Kn,{base8:()=>tu});var tu=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fn={};bt(Fn,{identity:()=>eu});var eu=ge({prefix:"\0",name:"identity",encode:r=>As(r),decode:r=>_s(r)});var lh=new TextEncoder,dh=new TextDecoder;var Vn={};bt(Vn,{sha256:()=>je,sha512:()=>su});var ou=20;function zn({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new qn(r,t,e,n,o)}var qn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??ou,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?qs(n,this.code,e?.truncate):n.then(o=>qs(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function qs(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return we(t,r)}function Vs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var je=zn({name:"sha2-256",code:18,encode:Vs("SHA-256")}),su=zn({name:"sha2-512",code:19,encode:Vs("SHA-512")});var Ge={...Fn,...Nn,...Kn,...Pn,...On,...Tn,...Bn,...Ln,...Mn,...kn},_h={...Vn,...Rn};function $s(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Hs=$s("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Hn=$s("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=pt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),iu={utf8:Hs,"utf-8":Hs,hex:Ge.base16,latin1:Hn,ascii:Hn,binary:Hn,...Ge},Lr=iu;function $(r,t="utf8"){let e=Lr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Q(r,t="utf8"){let e=Lr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var au=parseInt("11111",2),$n=parseInt("10000000",2),cu=parseInt("01111111",2),js={0:Ze,1:Ze,2:uu,3:du,4:hu,5:lu,6:fu,16:Ze,22:Ze,48:Ze};function jn(r,t={offset:0}){let e=r[t.offset]&au;if(t.offset++,js[e]!=null)return js[e](r,t);throw new Error("No decoder for tag "+e)}function Ye(r,t){let e=0;if((r[t.offset]&$n)===$n){let n=r[t.offset]&cu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Ze(r,t){Ye(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=jn(r,t);if(n===null)break;e.push(n)}return e}function uu(r,t){let e=Ye(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function fu(r,t){let e=Ye(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let d=0;for(let l=0;l<a.length;l++)d+=a[l]<<l*7;c+=`.${d}`,a=[]}}return c}function lu(r,t){return t.offset++,null}function du(r,t){let e=Ye(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function hu(r,t){let e=Ye(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function pu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new J;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Gn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=pu(r.byteLength);return new J(Uint8Array.from([t.byteLength|$n]),t)}function Gs(r){let t=new J,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new J(Uint8Array.from([2]),Gn(t),t)}function Zs(r){let t=Uint8Array.from([0]),e=new J(t,r);return new J(Uint8Array.from([3]),Gn(e),e)}function Tr(r,t=48){let e=new J;for(let n of r)e.append(n);return new J(Uint8Array.from([t]),Gn(e),e)}async function Ys(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var mu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),gu=Uint8Array.from([6,5,43,129,4,0,34]),bu=Uint8Array.from([6,5,43,129,4,0,35]),yu={ext:!0,kty:"EC",crv:"P-256"},xu={ext:!0,kty:"EC",crv:"P-384"},wu={ext:!0,kty:"EC",crv:"P-521"},Zn=32,Yn=48,Xn=66;function Xs(r){let t=jn(r);return Ws(t)}function Ws(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Zn*2+1)return n=Q(t.subarray(e,e+Zn),"base64url"),o=Q(t.subarray(e+Zn),"base64url"),new Ee({...yu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=Q(t.subarray(e,e+Yn),"base64url"),o=Q(t.subarray(e+Yn),"base64url"),new Ee({...xu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Xn*2+1)return n=Q(t.subarray(e,e+Xn),"base64url"),o=Q(t.subarray(e+Xn),"base64url"),new Ee({...wu,key_ops:["verify"],x:n,y:o});throw new ft(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Qs(r){return Tr([Gs(Uint8Array.from([1])),Tr([Eu(r.crv)],160),Tr([Zs(new J(Uint8Array.from([4]),$(r.x??"","base64url"),$(r.y??"","base64url")))],161)]).subarray()}function Eu(r){if(r==="P-256")return mu;if(r==="P-384")return gu;if(r==="P-521")return bu;throw new ft(`Invalid curve ${r}`)}var Ee=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Qs(this.jwk)),this._raw}toMultihash(){return xt.digest(Se(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,e,n){return Ys(this.jwk,e,t,n)}};function ee(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function It(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function M(r,t,e=""){let n=ee(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return r}function Br(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");It(r.outputLen),It(r.blockLen)}function ve(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function ti(r,t){M(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function Rt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Dr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Et(r,t){return r<<32-t|r>>>t}var ei=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Su=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Pt(r){if(M(r),ei)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Su[r[e]];return t}var Ct={_0:48,_9:57,A:65,F:70,a:97,f:102};function Js(r){if(r>=Ct._0&&r<=Ct._9)return r-Ct._0;if(r>=Ct.A&&r<=Ct.F)return r-(Ct.A-10);if(r>=Ct.a&&r<=Ct.f)return r-(Ct.a-10)}function Ot(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ei)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Js(r.charCodeAt(s)),c=Js(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function mt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];M(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 Wn(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function _e(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 Qn=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ri(r,t,e){return r&t^~r&e}function ni(r,t,e){return r&t^r&e^t&e}var Xe=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Dr(this.buffer)}update(t){ve(this),M(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Dr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ve(this),ti(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Rt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=Dr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,d[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:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Cr=BigInt(4294967295),oi=BigInt(32);function vu(r,t=!1){return t?{h:Number(r&Cr),l:Number(r>>oi&Cr)}:{h:Number(r>>oi&Cr)|0,l:Number(r&Cr)|0}}function si(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=vu(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Jn=(r,t,e)=>r>>>e,to=(r,t,e)=>r<<32-e|t>>>e,re=(r,t,e)=>r>>>e|t<<32-e,ne=(r,t,e)=>r<<32-e|t>>>e,We=(r,t,e)=>r<<64-e|t>>>e-32,Qe=(r,t,e)=>r>>>e-32|t<<64-e;function Lt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var ii=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ai=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ci=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ui=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,fi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),li=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Au=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Gt=new Uint32Array(64),eo=class extends Xe{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)Gt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let f=Gt[l-15],p=Gt[l-2],m=Et(f,7)^Et(f,18)^f>>>3,S=Et(p,17)^Et(p,19)^p>>>10;Gt[l]=S+Gt[l-7]+m+Gt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:d}=this;for(let l=0;l<64;l++){let f=Et(c,6)^Et(c,11)^Et(c,25),p=d+f+ri(c,a,u)+Au[l]+Gt[l]|0,S=(Et(n,2)^Et(n,13)^Et(n,22))+ni(n,o,s)|0;d=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+S|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,s,i,c,a,u,d)}roundClean(){Rt(Gt)}destroy(){this.set(0,0,0,0,0,0,0,0),Rt(this.buffer)}},ro=class extends eo{A=Nt[0]|0;B=Nt[1]|0;C=Nt[2]|0;D=Nt[3]|0;E=Nt[4]|0;F=Nt[5]|0;G=Nt[6]|0;H=Nt[7]|0;constructor(){super(32)}};var di=si(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Iu=di[0],Lu=di[1],Zt=new Uint32Array(80),Yt=new Uint32Array(80),no=class extends Xe{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:d,Fh:l,Fl:f,Gh:p,Gl:m,Hh:S,Hl:x}=this;return[t,e,n,o,s,i,c,a,u,d,l,f,p,m,S,x]}set(t,e,n,o,s,i,c,a,u,d,l,f,p,m,S,x){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=f|0,this.Gh=p|0,this.Gl=m|0,this.Hh=S|0,this.Hl=x|0}process(t,e){for(let b=0;b<16;b++,e+=4)Zt[b]=t.getUint32(e),Yt[b]=t.getUint32(e+=4);for(let b=16;b<80;b++){let _=Zt[b-15]|0,L=Yt[b-15]|0,C=re(_,L,1)^re(_,L,8)^Jn(_,L,7),U=ne(_,L,1)^ne(_,L,8)^to(_,L,7),A=Zt[b-2]|0,v=Yt[b-2]|0,N=re(A,v,19)^We(A,v,61)^Jn(A,v,6),K=ne(A,v,19)^Qe(A,v,61)^to(A,v,6),R=ci(U,K,Yt[b-7],Yt[b-16]),w=ui(R,C,N,Zt[b-7],Zt[b-16]);Zt[b]=w|0,Yt[b]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:d,Eh:l,El:f,Fh:p,Fl:m,Gh:S,Gl:x,Hh:h,Hl:g}=this;for(let b=0;b<80;b++){let _=re(l,f,14)^re(l,f,18)^We(l,f,41),L=ne(l,f,14)^ne(l,f,18)^Qe(l,f,41),C=l&p^~l&S,U=f&m^~f&x,A=fi(g,L,U,Lu[b],Yt[b]),v=li(A,h,_,C,Iu[b],Zt[b]),N=A|0,K=re(n,o,28)^We(n,o,34)^We(n,o,39),R=ne(n,o,28)^Qe(n,o,34)^Qe(n,o,39),w=n&s^n&c^s&c,E=o&i^o&a^i&a;h=S|0,g=x|0,S=p|0,x=m|0,p=l|0,m=f|0,{h:l,l:f}=Lt(u|0,d|0,v|0,N|0),u=c|0,d=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=ii(N,R,E);n=ai(y,v,K,w),o=y|0}({h:n,l:o}=Lt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Lt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Lt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:d}=Lt(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:f}=Lt(this.Eh|0,this.El|0,l|0,f|0),{h:p,l:m}=Lt(this.Fh|0,this.Fl|0,p|0,m|0),{h:S,l:x}=Lt(this.Gh|0,this.Gl|0,S|0,x|0),{h,l:g}=Lt(this.Hh|0,this.Hl|0,h|0,g|0),this.set(n,o,s,i,c,a,u,d,l,f,p,m,S,x,h,g)}roundClean(){Rt(Zt,Yt)}destroy(){Rt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},oo=class extends no{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var hi=Wn(()=>new ro,Qn(1));var pi=Wn(()=>new oo,Qn(3));var io=BigInt(0),so=BigInt(1);function kt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function mi(r){if(typeof r=="bigint"){if(!Rr(r))throw new Error("positive bigint expected, got "+r)}else It(r);return r}function Je(r){let t=mi(r).toString(16);return t.length&1?"0"+t:t}function gi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?io:BigInt("0x"+r)}function Ae(r){return gi(Pt(r))}function oe(r){return gi(Pt(Or(M(r)).reverse()))}function Pr(r,t){It(t),r=mi(r);let e=Ot(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function ao(r,t){return Pr(r,t).reverse()}function Or(r){return Uint8Array.from(r)}var Rr=r=>typeof r=="bigint"&&io<=r;function Tu(r,t,e){return Rr(r)&&Rr(t)&&Rr(e)&&t<=r&&r<e}function tr(r,t,e,n){if(!Tu(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function co(r){let t;for(t=0;r>io;r>>=so,t+=1);return t}var er=r=>(so<<BigInt(r))-so;function bi(r,t,e){if(It(r,"hashLen"),It(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=x=>new Uint8Array(x),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,a=n(r),u=n(r),d=0,l=()=>{a.fill(1),u.fill(0),d=0},f=(...x)=>e(u,mt(a,...x)),p=(x=o)=>{u=f(s,x),a=f(),x.length!==0&&(u=f(i,x),a=f())},m=()=>{if(d++>=c)throw new Error("drbg: tried max amount of iterations");let x=0,h=[];for(;x<t;){a=f();let g=a.slice();h.push(g),x+=a.length}return mt(...h)};return(x,h)=>{l(),p(x);let g;for(;!(g=h(m()));)p();return l(),g}}function Xt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,c){let a=r[s];if(c&&a===void 0)return;let u=typeof a;if(u!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([c,a])=>n(c,a,i));o(t,!1),o(e,!0)}function Ie(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var dt=BigInt(0),tt=BigInt(1),se=BigInt(2),wi=BigInt(3),Ei=BigInt(4),Si=BigInt(5),Bu=BigInt(7),vi=BigInt(8),Du=BigInt(9),_i=BigInt(16);function W(r,t){let e=r%t;return e>=dt?e:t+e}function H(r,t,e){let n=r;for(;t-- >dt;)n*=n,n%=e;return n}function yi(r,t){if(r===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=dt,s=tt,i=tt,c=dt;for(;e!==dt;){let u=n/e,d=n%e,l=o-i*u,f=s-c*u;n=e,e=d,o=i,s=c,i=l,c=f}if(n!==tt)throw new Error("invert: does not exist");return W(o,t)}function fo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function Ai(r,t){let e=(r.ORDER+tt)/Ei,n=r.pow(t,e);return fo(r,n,t),n}function Cu(r,t){let e=(r.ORDER-Si)/vi,n=r.mul(t,se),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,se),o),c=r.mul(s,r.sub(i,r.ONE));return fo(r,c,t),c}function Ru(r){let t=Le(r),e=Ii(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Bu)/_i;return(c,a)=>{let u=c.pow(a,i),d=c.mul(u,n),l=c.mul(u,o),f=c.mul(u,s),p=c.eql(c.sqr(d),a),m=c.eql(c.sqr(l),a);u=c.cmov(u,d,p),d=c.cmov(f,l,m);let S=c.eql(c.sqr(d),a),x=c.cmov(u,d,S);return fo(c,x,a),x}}function Ii(r){if(r<wi)throw new Error("sqrt is not defined for small field");let t=r-tt,e=0;for(;t%se===dt;)t/=se,e++;let n=se,o=Le(r);for(;xi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ai;let s=o.pow(n,t),i=(t+tt)/se;return function(a,u){if(a.is0(u))return u;if(xi(a,u)!==1)throw new Error("Cannot find square root");let d=e,l=a.mul(a.ONE,s),f=a.pow(u,t),p=a.pow(u,i);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let m=1,S=a.sqr(f);for(;!a.eql(S,a.ONE);)if(m++,S=a.sqr(S),m===d)throw new Error("Cannot find square root");let x=tt<<BigInt(d-m-1),h=a.pow(l,x);d=m,l=a.sqr(h),f=a.mul(f,l),p=a.mul(p,h)}return p}}function Pu(r){return r%Ei===wi?Ai:r%vi===Si?Cu:r%_i===Du?Ru(r):Ii(r)}var Li=(r,t)=>(W(r,t)&tt)===tt,Ou=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function lo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Ou.reduce((n,o)=>(n[o]="function",n),t);return Xt(r,e),r}function Nu(r,t,e){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(e===dt)return r.ONE;if(e===tt)return t;let n=r.ONE,o=t;for(;e>dt;)e&tt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=tt;return n}function rr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function xi(r,t){let e=(r.ORDER-tt)/se,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function ku(r,t){t!==void 0&&It(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var uo=class{ORDER;BITS;BYTES;isLE;ZERO=dt;ONE=tt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=dt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=ku(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return dt<=t&&t<this.ORDER}is0(t){return t===dt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&tt)===tt}neg(t){return W(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return W(t*t,this.ORDER)}add(t,e){return W(t+e,this.ORDER)}sub(t,e){return W(t-e,this.ORDER)}mul(t,e){return W(t*e,this.ORDER)}pow(t,e){return Nu(this,t,e)}div(t,e){return W(t*yi(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return yi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Pu(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?ao(t,this.BYTES):Pr(t,this.BYTES)}fromBytes(t,e=!1){M(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=s?oe(t):Ae(t);if(c&&(a=W(a,i)),!e&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return rr(this,t)}cmov(t,e,n){return n?e:t}};function Le(r,t={}){return new uo(r,t)}function Ti(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 ho(r){let t=Ti(r);return t+Math.ceil(t/2)}function po(r,t,e=!1){M(r);let n=r.length,o=Ti(t),s=ho(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?oe(r):Ae(r),c=W(i,t-tt)+tt;return e?ao(c,o):Pr(c,o)}var Te=BigInt(0),ie=BigInt(1);function nr(r,t){let e=t.negate();return r?e:t}function ae(r,t){let e=rr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Ri(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function mo(r,t){Ri(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=er(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Bi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=ie);let u=t*n,d=u+Math.abs(c)-1,l=c===0,f=c<0,p=t%2!==0;return{nextN:a,offset:d,isZero:l,isNeg:f,isNegF:p,offsetF:u}}var go=new WeakMap,Pi=new WeakMap;function bo(r){return Pi.get(r)||1}function Di(r){if(r!==Te)throw new Error("invalid wNAF")}var Be=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Te;)e&ie&&(n=n.add(o)),o=o.double(),e>>=ie;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=mo(e,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=mo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:d,isNeg:l,isNegF:f,offsetF:p}=Bi(n,c,i);n=a,d?s=s.add(nr(f,e[p])):o=o.add(nr(l,e[u]))}return Di(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=mo(t,this.bits);for(let i=0;i<s.windows&&n!==Te;i++){let{nextN:c,offset:a,isZero:u,isNeg:d}=Bi(n,i,s);if(n=c,!u){let l=e[a];o=o.add(d?l.negate():l)}}return Di(n),o}getPrecomputes(t,e,n){let o=go.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),go.set(e,o))),o}cached(t,e,n){let o=bo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=bo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Ri(e,this.bits),Pi.set(t,e),go.delete(t)}hasCache(t){return bo(t)!==1}};function Oi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Te||n>Te;)e&ie&&(s=s.add(o)),n&ie&&(i=i.add(o)),o=o.double(),e>>=ie,n>>=ie;return{p1:s,p2:i}}function Ci(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return lo(t),t}else return Le(r,{isLE:e})}function Nr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Te))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ci(t.p,e.Fp,n),s=Ci(t.n,e.Fn,n),c=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function kr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Wt=BigInt(0),et=BigInt(1),yo=BigInt(2),Uu=BigInt(8);function Mu(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),c=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,c)}function Ni(r,t={}){let e=Nr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;Xt(t,{},{uvRatio:"function"});let c=yo<<BigInt(o.BYTES*8)-et,a=x=>n.create(x),u=t.uvRatio||((x,h)=>{try{return{isValid:!0,value:n.sqrt(n.div(x,h))}}catch{return{isValid:!1,value:Wt}}});if(!Mu(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(x,h,g=!1){let b=g?et:Wt;return tr("coordinate "+x,h,b,c),h}function l(x){if(!(x instanceof m))throw new Error("EdwardsPoint expected")}let f=Ie((x,h)=>{let{X:g,Y:b,Z:_}=x,L=x.is0();h==null&&(h=L?Uu:n.inv(_));let C=a(g*h),U=a(b*h),A=n.mul(_,h);if(L)return{x:Wt,y:et};if(A!==et)throw new Error("invZ was invalid");return{x:C,y:U}}),p=Ie(x=>{let{a:h,d:g}=s;if(x.is0())throw new Error("bad point: ZERO");let{X:b,Y:_,Z:L,T:C}=x,U=a(b*b),A=a(_*_),v=a(L*L),N=a(v*v),K=a(U*h),R=a(v*a(K+A)),w=a(N+a(g*a(U*A)));if(R!==w)throw new Error("bad point: equation left != right (1)");let E=a(b*_),y=a(L*C);if(E!==y)throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(s.Gx,s.Gy,et,a(s.Gx*s.Gy));static ZERO=new m(Wt,et,et,Wt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(h,g,b,_){this.X=d("x",h),this.Y=d("y",g),this.Z=d("z",b,!0),this.T=d("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){if(h instanceof m)throw new Error("extended point not allowed");let{x:g,y:b}=h||{};return d("x",g),d("y",b),new m(g,b,et,a(g*b))}static fromBytes(h,g=!1){let b=n.BYTES,{a:_,d:L}=s;h=Or(M(h,b,"point")),kt(g,"zip215");let C=Or(h),U=h[b-1];C[b-1]=U&-129;let A=oe(C),v=g?c:n.ORDER;tr("point.y",A,Wt,v);let N=a(A*A),K=a(N-et),R=a(L*N-_),{isValid:w,value:E}=u(K,R);if(!w)throw new Error("bad point: invalid y coordinate");let y=(E&et)===et,I=(U&128)!==0;if(!g&&E===Wt&&I)throw new Error("bad point: x=0 and x_0=1");return I!==y&&(E=a(-E)),m.fromAffine({x:E,y:A})}static fromHex(h,g=!1){return m.fromBytes(Ot(h),g)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,g=!0){return S.createCache(this,h),g||this.multiply(yo),this}assertValidity(){p(this)}equals(h){l(h);let{X:g,Y:b,Z:_}=this,{X:L,Y:C,Z:U}=h,A=a(g*U),v=a(L*_),N=a(b*U),K=a(C*_);return A===v&&N===K}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:h}=s,{X:g,Y:b,Z:_}=this,L=a(g*g),C=a(b*b),U=a(yo*a(_*_)),A=a(h*L),v=g+b,N=a(a(v*v)-L-C),K=A+C,R=K-U,w=A-C,E=a(N*R),y=a(K*w),I=a(N*w),T=a(R*K);return new m(E,y,T,I)}add(h){l(h);let{a:g,d:b}=s,{X:_,Y:L,Z:C,T:U}=this,{X:A,Y:v,Z:N,T:K}=h,R=a(_*A),w=a(L*v),E=a(U*b*K),y=a(C*N),I=a((_+L)*(A+v)-R-w),T=y-E,D=y+E,P=a(w-g*R),B=a(I*T),O=a(D*P),k=a(I*P),j=a(T*D);return new m(B,O,j,k)}subtract(h){return this.add(h.negate())}multiply(h){if(!o.isValidNot0(h))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:g,f:b}=S.cached(this,h,_=>ae(m,_));return ae(m,[g,b])[0]}multiplyUnsafe(h,g=m.ZERO){if(!o.isValid(h))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return h===Wt?m.ZERO:this.is0()||h===et?this:S.unsafe(this,h,b=>ae(m,b),g)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return S.unsafe(this,s.n).is0()}toAffine(h){return f(this,h)}clearCofactor(){return i===et?this:this.multiplyUnsafe(i)}toBytes(){let{x:h,y:g}=this.toAffine(),b=n.toBytes(g);return b[b.length-1]|=h&et?128:0,b}toHex(){return Pt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let S=new Be(m,o.BITS);return m.BASE.precompute(8),m}function ki(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Xt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,c=e.randomBytes||_e,a=e.adjustScalarBytes||(A=>A),u=e.domain||((A,v,N)=>{if(kt(N,"phflag"),v.length||N)throw new Error("Contexts/pre-hash are not supported");return A});function d(A){return i.create(oe(A))}function l(A){let v=b.secretKey;M(A,b.secretKey,"secretKey");let N=M(t(A),2*v,"hashedSecretKey"),K=a(N.slice(0,v)),R=N.slice(v,2*v),w=d(K);return{head:K,prefix:R,scalar:w}}function f(A){let{head:v,prefix:N,scalar:K}=l(A),R=o.multiply(K),w=R.toBytes();return{head:v,prefix:N,scalar:K,point:R,pointBytes:w}}function p(A){return f(A).pointBytes}function m(A=Uint8Array.of(),...v){let N=mt(...v);return d(t(u(N,M(A,void 0,"context"),!!n)))}function S(A,v,N={}){A=M(A,void 0,"message"),n&&(A=n(A));let{prefix:K,scalar:R,pointBytes:w}=f(v),E=m(N.context,K,A),y=o.multiply(E).toBytes(),I=m(N.context,y,w,A),T=i.create(E+I*R);if(!i.isValid(T))throw new Error("sign failed: invalid s");let D=mt(y,i.toBytes(T));return M(D,b.signature,"result")}let x={zip215:!0};function h(A,v,N,K=x){let{context:R,zip215:w}=K,E=b.signature;A=M(A,E,"signature"),v=M(v,void 0,"message"),N=M(N,b.publicKey,"publicKey"),w!==void 0&&kt(w,"zip215"),n&&(v=n(v));let y=E/2,I=A.subarray(0,y),T=oe(A.subarray(y,E)),D,P,B;try{D=r.fromBytes(N,w),P=r.fromBytes(I,w),B=o.multiplyUnsafe(T)}catch{return!1}if(!w&&D.isSmallOrder())return!1;let O=m(R,P.toBytes(),D.toBytes(),v);return P.add(D.multiplyUnsafe(O)).subtract(B).clearCofactor().is0()}let g=s.BYTES,b={secretKey:g,publicKey:g,signature:2*g,seed:g};function _(A=c(b.seed)){return M(A,b.seed,"seed")}function L(A){return ee(A)&&A.length===i.BYTES}function C(A,v){try{return!!r.fromBytes(A,v)}catch{return!1}}let U={getExtendedPublicKey:f,randomSecretKey:_,isValidSecretKey:L,isValidPublicKey:C,toMontgomery(A){let{y:v}=r.fromBytes(A),N=b.publicKey,K=N===32;if(!K&&N!==57)throw new Error("only defined for 25519 and 448");let R=K?s.div(et+v,et-v):s.div(v-et,v+et);return s.toBytes(R)},toMontgomerySecret(A){let v=b.secretKey;M(A,v);let N=t(A.subarray(0,v));return a(N).subarray(0,v)}};return Object.freeze({keygen:kr(_,p),getPublicKey:p,sign:S,verify:h,utils:U,Point:r,lengths:b})}var Ku=BigInt(1),Ui=BigInt(2);var Fu=BigInt(5),qu=BigInt(8),xo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),zu={p:xo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:qu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Vu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=xo,c=r*r%s*r%s,a=H(c,Ui,s)*c%s,u=H(a,Ku,s)*r%s,d=H(u,Fu,s)*u%s,l=H(d,t,s)*d%s,f=H(l,e,s)*l%s,p=H(f,n,s)*f%s,m=H(p,o,s)*p%s,S=H(m,o,s)*p%s,x=H(S,t,s)*d%s;return{pow_p_5_8:H(x,Ui,s)*r%s,b2:c}}function Hu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Mi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function $u(r,t){let e=xo,n=W(t*t*t,e),o=W(n*n*t,e),s=Vu(r*o).pow_p_5_8,i=W(r*n*s,e),c=W(t*i*i,e),a=i,u=W(i*Mi,e),d=c===r,l=c===W(-r,e),f=c===W(-r*Mi,e);return d&&(i=a),(l||f)&&(i=u),Li(i,e)&&(i=W(-i,e)),{isValid:d||l,value:i}}var ju=Ni(zu,{uvRatio:$u});function Gu(r){return ki(ju,pi,Object.assign({adjustScalarBytes:Hu},r))}var Ki=Gu({});var or=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Ur=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Fi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Ur("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 Mr=Fi;var Kr=32;var wo,Zu=(async()=>{try{return await Mr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Yu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Mr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Mr.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 Xu(r,t,e){return Ki.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function qi(r,t,e){return wo==null&&(wo=await Zu),wo?Yu(r,t,e):Xu(r,t,e)}function Fr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var qr=class{type="Ed25519";raw;constructor(t){this.raw=Eo(t,Kr)}toMultihash(){return xt.digest(Se(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=qi(this.raw,e,t);return Fr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Vi(r){return r=Eo(r,Kr),new qr(r)}function Eo(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 Qu=Math.pow(2,7),Ju=Math.pow(2,14),tf=Math.pow(2,21),So=Math.pow(2,28),vo=Math.pow(2,35),_o=Math.pow(2,42),Ao=Math.pow(2,49),q=128,ct=127;function gt(r){if(r<Qu)return 1;if(r<Ju)return 2;if(r<tf)return 3;if(r<So)return 4;if(r<vo)return 5;if(r<_o)return 6;if(r<Ao)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function De(r,t,e=0){switch(gt(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ef(r,t,e=0){switch(gt(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Io(r,t){let e=r[t],n=0;if(n+=e&ct,e<q||(e=r[t+1],n+=(e&ct)<<7,e<q)||(e=r[t+2],n+=(e&ct)<<14,e<q)||(e=r[t+3],n+=(e&ct)<<21,e<q)||(e=r[t+4],n+=(e&ct)*So,e<q)||(e=r[t+5],n+=(e&ct)*vo,e<q)||(e=r[t+6],n+=(e&ct)*_o,e<q)||(e=r[t+7],n+=(e&ct)*Ao,e<q))return n;throw new RangeError("Could not decode varint")}function rf(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<q||(e=r.get(t+1),n+=(e&ct)<<7,e<q)||(e=r.get(t+2),n+=(e&ct)<<14,e<q)||(e=r.get(t+3),n+=(e&ct)<<21,e<q)||(e=r.get(t+4),n+=(e&ct)*So,e<q)||(e=r.get(t+5),n+=(e&ct)*vo,e<q)||(e=r.get(t+6),n+=(e&ct)*_o,e<q)||(e=r.get(t+7),n+=(e&ct)*Ao,e<q))return n;throw new RangeError("Could not decode varint")}function Hi(r,t,e=0){return t==null&&(t=pt(gt(r))),t instanceof Uint8Array?De(r,t,e):ef(r,t,e)}function sr(r,t=0){return r instanceof Uint8Array?Io(r,t):rf(r,t)}var Lo=new Float32Array([-0]),Qt=new Uint8Array(Lo.buffer);function ji(r,t,e){Lo[0]=r,t[e]=Qt[0],t[e+1]=Qt[1],t[e+2]=Qt[2],t[e+3]=Qt[3]}function Gi(r,t){return Qt[0]=r[t],Qt[1]=r[t+1],Qt[2]=r[t+2],Qt[3]=r[t+3],Lo[0]}var To=new Float64Array([-0]),ut=new Uint8Array(To.buffer);function Zi(r,t,e){To[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function Yi(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],To[0]}var nf=BigInt(Number.MAX_SAFE_INTEGER),of=BigInt(Number.MIN_SAFE_INTEGER),yt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ce;if(t<nf&&t>of)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Xi&&(o=0n,++n>Xi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ce;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):ce}},ce=new yt(0,0);ce.toBigInt=function(){return 0n};ce.zzEncode=ce.zzDecode=function(){return this};ce.length=function(){return 1};var Xi=4294967296n;function Wi(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Qi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Bo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function St(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function zr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Do=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,St(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw St(this,4);return zr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw St(this,4);return zr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw St(this,4);let t=Gi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw St(this,4);let t=Yi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw St(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Qi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw St(this,t);this.pos+=t}else do if(this.pos>=this.len)throw St(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new yt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw St(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw St(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw St(this,8);let t=zr(this.buf,this.pos+=4),e=zr(this.buf,this.pos+=4);return new yt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Io(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 ir(r){return new Do(r instanceof Uint8Array?r:r.subarray())}function Ut(r,t,e){let n=ir(r);return t.decode(n,void 0,e)}function Co(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return pt(i);o+i>t&&(n=pt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var ue=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ro(){}var Oo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},sf=Co();function af(r){return globalThis.Buffer!=null?pt(r):sf(r)}var cr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ue(Ro,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ue(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new No((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(Vr,10,yt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=yt.fromBigInt(t);return this._push(Vr,e.length(),e)}uint64Number(t){return this._push(De,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=yt.fromBigInt(t).zzEncode();return this._push(Vr,e.length(),e)}sint64Number(t){let e=yt.fromNumber(t).zzEncode();return this._push(Vr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Po,1,t?1:0)}fixed32(t){return this._push(ar,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=yt.fromBigInt(t);return this._push(ar,4,e.lo)._push(ar,4,e.hi)}fixed64Number(t){let e=yt.fromNumber(t);return this._push(ar,4,e.lo)._push(ar,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ji,4,t)}double(t){return this._push(Zi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Po,1,0):this.uint32(e)._push(uf,e,t)}string(t){let e=Wi(t);return e!==0?this.uint32(e)._push(Bo,e,t):this._push(Po,1,0)}fork(){return this.states=new Oo(this),this.head=this.tail=new ue(Ro,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 ue(Ro,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=af(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Po(r,t,e){t[e]=r&255}function cf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var No=class extends ue{next;constructor(t,e){super(cf,t,e),this.next=void 0}};function Vr(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 ar(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 uf(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(ff,t,r),this},cr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(lf,t,r),this});function ff(r,t,e){t.set(r,e)}function lf(r,t,e){r.length<40?Bo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function ko(){return new cr}function Mt(r,t){let e=ko();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*Kt(r,t,e){let n=ir(r);yield*t.stream(n,void 0,"$",e)}var Hr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function $r(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function Ce(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,c){let a=t(i);c.int32(a)},n=function(i){let c=i.int32();return t(c)},o=function*(i){let c=i.int32();yield t(c)};return $r("enum",Hr.VARINT,e,n,o)}function Ft(r,t,e){return $r("message",Hr.LENGTH_DELIMITED,r,t,e)}var ur=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 Uo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Uo||(Uo={}));(function(r){r.codec=()=>Ce(Uo)})(ht||(ht={}));var fr;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((s,i,c={})=>{c.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)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let d=s.uint32();switch(d>>>3){case 1:{a.Type=ht.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return a},function*(s,i,c,a={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${c}.Type`,value:ht.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Mt(s,r.codec())}r.encode=e;function n(s,i){return Ut(s,r.codec(),i)}r.decode=n;function o(s,i){return Kt(s,r.codec(),i)}r.stream=o})(fr||(fr={}));var Mo;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((s,i,c={})=>{c.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)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let d=s.uint32();switch(d>>>3){case 1:{a.Type=ht.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return a},function*(s,i,c,a={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${c}.Type`,value:ht.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Mt(s,r.codec())}r.encode=e;function n(s,i){return Ut(s,r.codec(),i)}r.decode=n;function o(s,i){return Kt(s,r.codec(),i)}r.stream=o})(Mo||(Mo={}));var jr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Br(t),M(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Rt(o)}update(t){return ve(this),this.iHash.update(t),this}digestInto(t){ve(this),M(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ko=(r,t,e)=>new jr(r,t).update(e).digest();Ko.create=(r,t)=>new jr(r,t);var ta=(r,t)=>(r+(r>=0?t:-t)/ea)/t;function hf(r,t,e){let[[n,o],[s,i]]=t,c=ta(i*r,e),a=ta(-o*r,e),u=r-c*n-a*s,d=-c*o-a*i,l=u<qt,f=d<qt;l&&(u=-u),f&&(d=-d);let p=er(Math.ceil(co(e)/2))+Re;if(u<qt||u>=p||d<qt||d>=p)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:l,k1:u,k2neg:f,k2:d}}function qo(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Fo(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return kt(e.lowS,"lowS"),kt(e.prehash,"prehash"),e.format!==void 0&&qo(e.format),e}var zo=class extends Error{constructor(t=""){super(t)}},Jt={Err:zo,_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,o=Je(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Je(o.length/2|128):"";return Je(r)+s+o+t},decode(r,t){let{Err:e}=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 o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of u)i=i<<8|d;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Jt;if(r<qt)throw new t("integer: negative integers are not allowed");let e=Je(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=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 Ae(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Jt,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:c,l:a}=n.decode(2,s),{v:u,l:d}=n.decode(2,a);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=Jt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},qt=BigInt(0),Re=BigInt(1),ea=BigInt(2),Gr=BigInt(3),pf=BigInt(4);function ra(r,t={}){let e=Nr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:c}=s;Xt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=oa(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(R,w,E){let{x:y,y:I}=w.toAffine(),T=n.toBytes(y);if(kt(E,"isCompressed"),E){d();let D=!n.isOdd(I);return mt(na(D),T)}else return mt(Uint8Array.of(4),T,n.toBytes(I))}function f(R){M(R,void 0,"Point");let{publicKey:w,publicKeyUncompressed:E}=u,y=R.length,I=R[0],T=R.subarray(1);if(y===w&&(I===2||I===3)){let D=n.fromBytes(T);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let P=S(D),B;try{B=n.sqrt(P)}catch(j){let V=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}d();let O=n.isOdd(B);return(I&1)===1!==O&&(B=n.neg(B)),{x:D,y:B}}else if(y===E&&I===4){let D=n.BYTES,P=n.fromBytes(T.subarray(0,D)),B=n.fromBytes(T.subarray(D,D*2));if(!x(P,B))throw new Error("bad point: is not on curve");return{x:P,y:B}}else throw new Error(`bad point: got length ${y}, expected compressed=${w} or uncompressed=${E}`)}let p=t.toBytes||l,m=t.fromBytes||f;function S(R){let w=n.sqr(R),E=n.mul(w,R);return n.add(n.add(E,n.mul(R,s.a)),s.b)}function x(R,w){let E=n.sqr(w),y=S(R);return n.eql(E,y)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let h=n.mul(n.pow(s.a,Gr),pf),g=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(h,g)))throw new Error("bad curve params: a or b");function b(R,w,E=!1){if(!n.isValid(w)||E&&n.is0(w))throw new Error(`bad point coordinate ${R}`);return w}function _(R){if(!(R instanceof v))throw new Error("Weierstrass Point expected")}function L(R){if(!a||!a.basises)throw new Error("no endo");return hf(R,a.basises,o.ORDER)}let C=Ie((R,w)=>{let{X:E,Y:y,Z:I}=R;if(n.eql(I,n.ONE))return{x:E,y};let T=R.is0();w==null&&(w=T?n.ONE:n.inv(I));let D=n.mul(E,w),P=n.mul(y,w),B=n.mul(I,w);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:D,y:P}}),U=Ie(R=>{if(R.is0()){if(t.allowInfinityPoint&&!n.is0(R.Y))return;throw new Error("bad point: ZERO")}let{x:w,y:E}=R.toAffine();if(!n.isValid(w)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!x(w,E))throw new Error("bad point: equation left != right");if(!R.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(R,w,E,y,I){return E=new v(n.mul(E.X,R),E.Y,E.Z),w=nr(y,w),E=nr(I,E),w.add(E)}class v{static BASE=new v(s.Gx,s.Gy,n.ONE);static ZERO=new v(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(w,E,y){this.X=b("x",w),this.Y=b("y",E,!0),this.Z=b("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(w){let{x:E,y}=w||{};if(!w||!n.isValid(E)||!n.isValid(y))throw new Error("invalid affine point");if(w instanceof v)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(y)?v.ZERO:new v(E,y,n.ONE)}static fromBytes(w){let E=v.fromAffine(m(M(w,void 0,"point")));return E.assertValidity(),E}static fromHex(w){return v.fromBytes(Ot(w))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,E=!0){return K.createCache(this,w),E||this.multiply(Gr),this}assertValidity(){U(this)}hasEvenY(){let{y:w}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(w)}equals(w){_(w);let{X:E,Y:y,Z:I}=this,{X:T,Y:D,Z:P}=w,B=n.eql(n.mul(E,P),n.mul(T,I)),O=n.eql(n.mul(y,P),n.mul(D,I));return B&&O}negate(){return new v(this.X,n.neg(this.Y),this.Z)}double(){let{a:w,b:E}=s,y=n.mul(E,Gr),{X:I,Y:T,Z:D}=this,P=n.ZERO,B=n.ZERO,O=n.ZERO,k=n.mul(I,I),j=n.mul(T,T),V=n.mul(D,D),F=n.mul(I,T);return F=n.add(F,F),O=n.mul(I,D),O=n.add(O,O),P=n.mul(w,O),B=n.mul(y,V),B=n.add(P,B),P=n.sub(j,B),B=n.add(j,B),B=n.mul(P,B),P=n.mul(F,P),O=n.mul(y,O),V=n.mul(w,V),F=n.sub(k,V),F=n.mul(w,F),F=n.add(F,O),O=n.add(k,k),k=n.add(O,k),k=n.add(k,V),k=n.mul(k,F),B=n.add(B,k),V=n.mul(T,D),V=n.add(V,V),k=n.mul(V,F),P=n.sub(P,k),O=n.mul(V,j),O=n.add(O,O),O=n.add(O,O),new v(P,B,O)}add(w){_(w);let{X:E,Y:y,Z:I}=this,{X:T,Y:D,Z:P}=w,B=n.ZERO,O=n.ZERO,k=n.ZERO,j=s.a,V=n.mul(s.b,Gr),F=n.mul(E,T),G=n.mul(y,D),nt=n.mul(I,P),At=n.add(E,y),Z=n.add(T,D);At=n.mul(At,Z),Z=n.add(F,G),At=n.sub(At,Z),Z=n.add(E,I);let it=n.add(T,P);return Z=n.mul(Z,it),it=n.add(F,nt),Z=n.sub(Z,it),it=n.add(y,I),B=n.add(D,P),it=n.mul(it,B),B=n.add(G,nt),it=n.sub(it,B),k=n.mul(j,Z),B=n.mul(V,nt),k=n.add(B,k),B=n.sub(G,k),k=n.add(G,k),O=n.mul(B,k),G=n.add(F,F),G=n.add(G,F),nt=n.mul(j,nt),Z=n.mul(V,Z),G=n.add(G,nt),nt=n.sub(F,nt),nt=n.mul(j,nt),Z=n.add(Z,nt),F=n.mul(G,Z),O=n.add(O,F),F=n.mul(it,Z),B=n.mul(At,B),B=n.sub(B,F),F=n.mul(At,G),k=n.mul(it,k),k=n.add(k,F),new v(B,O,k)}subtract(w){return this.add(w.negate())}is0(){return this.equals(v.ZERO)}multiply(w){let{endo:E}=t;if(!o.isValidNot0(w))throw new Error("invalid scalar: out of range");let y,I,T=D=>K.cached(this,D,P=>ae(v,P));if(E){let{k1neg:D,k1:P,k2neg:B,k2:O}=L(w),{p:k,f:j}=T(P),{p:V,f:F}=T(O);I=j.add(F),y=A(E.beta,k,V,D,B)}else{let{p:D,f:P}=T(w);y=D,I=P}return ae(v,[y,I])[0]}multiplyUnsafe(w){let{endo:E}=t,y=this;if(!o.isValid(w))throw new Error("invalid scalar: out of range");if(w===qt||y.is0())return v.ZERO;if(w===Re)return y;if(K.hasCache(this))return this.multiply(w);if(E){let{k1neg:I,k1:T,k2neg:D,k2:P}=L(w),{p1:B,p2:O}=Oi(v,y,T,P);return A(E.beta,B,O,I,D)}else return K.unsafe(y,w)}toAffine(w){return C(this,w)}isTorsionFree(){let{isTorsionFree:w}=t;return i===Re?!0:w?w(v,this):K.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:w}=t;return i===Re?this:w?w(v,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(w=!0){return kt(w,"isCompressed"),this.assertValidity(),p(v,this,w)}toHex(w=!0){return Pt(this.toBytes(w))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,K=new Be(v,t.endo?Math.ceil(N/2):N);return v.BASE.precompute(8),v}function na(r){return Uint8Array.of(r?2:3)}function oa(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function mf(r,t={}){let{Fn:e}=r,n=t.randomBytes||_e,o=Object.assign(oa(r.Fp,e),{seed:ho(e.ORDER)});function s(p){try{let m=e.fromBytes(p);return e.isValidNot0(m)}catch{return!1}}function i(p,m){let{publicKey:S,publicKeyUncompressed:x}=o;try{let h=p.length;return m===!0&&h!==S||m===!1&&h!==x?!1:!!r.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return po(M(p,o.seed,"seed"),e.ORDER)}function a(p,m=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(m)}function u(p){let{secretKey:m,publicKey:S,publicKeyUncompressed:x}=o;if(!ee(p)||"_lengths"in e&&e._lengths||m===S)return;let h=M(p,void 0,"key").length;return h===S||h===x}function d(p,m,S=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(m)===!1)throw new Error("second arg must be public key");let x=e.fromBytes(p);return r.fromBytes(m).multiply(x).toBytes(S)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},f=kr(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:d,keygen:f,Point:r,utils:l,lengths:o})}function sa(r,t,e={}){Br(t),Xt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||_e,o=e.hmac||((E,y)=>Ko(t,E,y)),{Fp:s,Fn:i}=r,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:p}=mf(r,e),m={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},S=c*ea<s.ORDER;function x(E){let y=c>>Re;return E>y}function h(E,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return y}function g(){if(S)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function b(E,y){qo(y);let I=p.signature,T=y==="compact"?I:y==="recovered"?I+1:void 0;return M(E,T)}class _{r;s;recovery;constructor(y,I,T){if(this.r=h("r",y),this.s=h("s",I),T!=null){if(g(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(y,I=m.format){b(y,I);let T;if(I==="der"){let{r:O,s:k}=Jt.toSig(M(y));return new _(O,k)}I==="recovered"&&(T=y[0],I="compact",y=y.subarray(1));let D=p.signature/2,P=y.subarray(0,D),B=y.subarray(D,D*2);return new _(i.fromBytes(P),i.fromBytes(B),T)}static fromHex(y,I){return this.fromBytes(Ot(y),I)}assertRecovery(){let{recovery:y}=this;if(y==null)throw new Error("invalid recovery id: must be present");return y}addRecoveryBit(y){return new _(this.r,this.s,y)}recoverPublicKey(y){let{r:I,s:T}=this,D=this.assertRecovery(),P=D===2||D===3?I+c:I;if(!s.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let B=s.toBytes(P),O=r.fromBytes(mt(na((D&1)===0),B)),k=i.inv(P),j=C(M(y,void 0,"msgHash")),V=i.create(-j*k),F=i.create(T*k),G=r.BASE.multiplyUnsafe(V).add(O.multiplyUnsafe(F));if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return x(this.s)}toBytes(y=m.format){if(qo(y),y==="der")return Ot(Jt.hexFromSig(this));let{r:I,s:T}=this,D=i.toBytes(I),P=i.toBytes(T);return y==="recovered"?(g(),mt(Uint8Array.of(this.assertRecovery()),D,P)):mt(D,P)}toHex(y){return Pt(this.toBytes(y))}}let L=e.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let I=Ae(y),T=y.length*8-a;return T>0?I>>BigInt(T):I},C=e.bits2int_modN||function(y){return i.create(L(y))},U=er(a);function A(E){return tr("num < 2^"+a,E,qt,U),i.toBytes(E)}function v(E,y){return M(E,void 0,"message"),y?M(t(E),void 0,"prehashed message"):E}function N(E,y,I){let{lowS:T,prehash:D,extraEntropy:P}=Fo(I,m);E=v(E,D);let B=C(E),O=i.fromBytes(y);if(!i.isValidNot0(O))throw new Error("invalid private key");let k=[A(O),A(B)];if(P!=null&&P!==!1){let G=P===!0?n(p.secretKey):P;k.push(M(G,void 0,"extraEntropy"))}let j=mt(...k),V=B;function F(G){let nt=L(G);if(!i.isValidNot0(nt))return;let At=i.inv(nt),Z=r.BASE.multiply(nt).toAffine(),it=i.create(Z.x);if(it===qt)return;let wr=i.create(At*i.create(V+it*O));if(wr===qt)return;let ys=(Z.x===it?0:2)|Number(Z.y&Re),xs=wr;return T&&x(wr)&&(xs=i.neg(wr),ys^=1),new _(it,xs,S?void 0:ys)}return{seed:j,k2sig:F}}function K(E,y,I={}){let{seed:T,k2sig:D}=N(E,y,I);return bi(t.outputLen,i.BYTES,o)(T,D).toBytes(I.format)}function R(E,y,I,T={}){let{lowS:D,prehash:P,format:B}=Fo(T,m);if(I=M(I,void 0,"publicKey"),y=v(y,P),!ee(E)){let O=E instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}b(E,B);try{let O=_.fromBytes(E,B),k=r.fromBytes(I);if(D&&O.hasHighS())return!1;let{r:j,s:V}=O,F=C(y),G=i.inv(V),nt=i.create(F*G),At=i.create(j*G),Z=r.BASE.multiplyUnsafe(nt).add(k.multiplyUnsafe(At));return Z.is0()?!1:i.create(Z.x)===j}catch{return!1}}function w(E,y,I={}){let{prehash:T}=Fo(I,m);return y=v(y,T),_.fromBytes(E,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:p,Point:r,sign:K,verify:R,recoverPublicKey:w,Signature:_,hash:t})}var Ho={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},gf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ia=BigInt(2);function bf(r){let t=Ho.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=r*r*r%t,d=u*u*r%t,l=H(d,e,t)*d%t,f=H(l,e,t)*d%t,p=H(f,ia,t)*u%t,m=H(p,o,t)*p%t,S=H(m,s,t)*m%t,x=H(S,c,t)*S%t,h=H(x,a,t)*x%t,g=H(h,c,t)*S%t,b=H(g,e,t)*d%t,_=H(b,i,t)*m%t,L=H(_,n,t)*u%t,C=H(L,ia,t);if(!Vo.eql(Vo.sqr(C),r))throw new Error("Cannot find square root");return C}var Vo=Le(Ho.p,{sqrt:bf}),yf=ra(Ho,{Fp:Vo,endo:gf}),Pe=sa(yf,hi);function aa(r,t,e,n){let o=je.digest(e instanceof Uint8Array?e:e.subarray());if(Fr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Pe.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new or(String(s))});try{return n?.signal?.throwIfAborted(),Pe.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new or(String(s))}}var Zr=class{type="secp256k1";raw;_key;constructor(t){this._key=ua(t),this.raw=ca(this._key)}toMultihash(){return xt.digest(Se(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){return aa(this._key,e,t,n)}};function fa(r){return new Zr(r)}function ca(r){return Pe.Point.fromBytes(r).toBytes()}function ua(r){try{return Pe.Point.fromBytes(r),r}catch(t){throw new Sr(String(t))}}function la(r){let{Type:t,Data:e}=fr.decode(r.digest),n=e??new Uint8Array;switch(t){case ht.Ed25519:return Vi(n);case ht.secp256k1:return fa(n);case ht.ECDSA:return Xs(n);default:throw new qe}}function Se(r){return fr.encode({Type:ht[r.type],Data:r.raw})}var da=Symbol.for("nodejs.util.inspect.custom"),xf=114,lr=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()})`}[Sn]=!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(xf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[da](){return`PeerId(${this.toString()})`}},Yr=class extends lr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Xr=class extends lr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Wr=class extends lr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},wf=2336,Qr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=xt.digest($(this.url))}[da](){return`PeerId(${this.url})`}[Sn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(wf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Q(t)),t.toString()===this.toString())}};function Jr(r){if(Sf(r))return new Yr({multihash:r});if(Ef(r))try{let t=la(r);if(t.type==="Ed25519")return new Xr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Wr({multihash:r,publicKey:t})}catch{let e=Q(r.digest);return new Qr(new URL(e))}throw new vr("Supplied PeerID Multihash is invalid")}function Ef(r){return r.code===xt.code}function Sf(r){return r.code===je.code}function $o(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 tn(r){let t=te(X.decode(`z${r}`));return Jr(t)}var en=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 $o(this.set.entries(),t=>{let e=tn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=tn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return $o(this.set.values(),t=>tn(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 jo(){return new en}var Go={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ha={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},pa=new globalThis.TextEncoder;function vf(r,t){let e=Go[t],n=ha[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function _f(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Go[t],o=ha[t],s=r;for(;s.length>0;){let i=pa.encodeInto(s,e);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(e[c]),o=BigInt.asUintN(t,o*n)}return o}function Zo(r,{size:t=32,utf8Buffer:e}={}){if(!Go[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 _f(r,t,e);r=pa.encode(r)}return vf(r,t)}var dr={hash:r=>Number(Zo(r,{size:32})),hashV:(r,t)=>Af(dr.hash(r,t))};function Af(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),$(t,"base16")}var Yo=64,vt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Yo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=wt(o);for(let c=0;c<i.length;c++)i[c]=s[c];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?lt(this.fp,t.fp):!1}};function fe(r,t){return Math.floor(Math.random()*(t-r))+r}var le=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");let e=fe(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var If=500,hr=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??dr,this.seed=t.seed??fe(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=$(t));let e=new vt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new le(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new le(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[fe(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new le(this.bucketSize));for(let c=0;c<If;c++){let a=this.buckets[i].swap(e);if(a!=null&&(i=(i^a.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new le(this.bucketSize)),this.buckets[i].add(a)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=$(t));let e=new vt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=$(t));let e=new vt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Lf={1:.5,2:.84,4:.95,8:.98};function Tf(r=.001){return r>.002?2:r>1e-5?4:8}function ma(r,t=.001){let e=Tf(t),n=Lf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Yo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var rn=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??dr,this.seed=t.seed??fe(0,Math.pow(2,10)),this.filterSeries=[new hr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=$(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new hr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=$(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=$(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function Xo(r,t=.001,e){return new rn({...ma(r,t),...e??{}})}function _t(r){let t=r.getComponents(),e={},n=0;if(t[n]?.name==="ip6zone"&&(e.zone=`${t[n].value}`,n++),t[n].name==="ip4"||t[n].name==="ip6"||t[n].name==="dns"||t[n].name==="dns4"||t[n].name==="dns6"?(e.type=t[n].name,e.host=t[n].value,n++):t[n].name==="dnsaddr"&&(e.type=t[n].name,e.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(e.protocol=t[n].name==="tcp"?"tcp":"udp",e.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(e.type==="ip4"?e.cidr=parseInt(`${t[n].value}`):e.type==="ip6"&&(e.cidr=`${t[n].value}`),n++),e.type==null||e.host==null)throw new ft(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e}var nn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let f=Number.parseInt(l,t);if(!Number.isNaN(f))return f});if(d===void 0)break;if(s*=t,s+=d,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return e.set(s.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ga=45,Bf=15,Oe=new nn;function on(r){if(!(r.length>Bf))return Oe.new(r).parseWith(()=>Oe.readIPv4Addr())}function sn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ga))return Oe.new(r).parseWith(()=>Oe.readIPv6Addr())}function Ne(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>ga)return;let e=Oe.new(r).parseWith(()=>Oe.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function ba(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function ya(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Wo(r){switch(r.length){case de:return r.join(".");case he:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function xa(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function wa(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var de=4,he=16,Rg=parseInt("0xFFFF",16),Df=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function pr(r,t){t.length===he&&r.length===de&&ba(t,0,11)&&(t=t.slice(12)),t.length===de&&r.length===he&&ya(r,Df,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function Ea(r,t){if(typeof t=="string"&&(t=Ne(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Qo(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=de,o=on(t);if(o==null&&(n=he,o=sn(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=Jo(s,8*n);return{network:pr(o,i),mask:i}}function Jo(r,t){if(t!==8*de&&t!==8*he)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}=Qo(t));else{let n=Ne(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=Ne(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Jo(o,8*n.length);this.network=pr(n,this.mask)}}contains(t){return Ea({network:this.network,mask:this.mask},t)}toString(){let t=xa(this.mask),e=t!==-1?String(t):wa(this.mask);return Wo(this.network)+"/"+e}};function Sa(r,t){return new mr(r).contains(t)}function va(r){try{let t=_t(r);switch(t.type){case"ip6":return Sa("2000::/3",t.host);default:return!1}}catch{return!1}}function ke(r){return!!on(r)}function an(r){return!!sn(r)}var Aa=Ja(_a(),1),Cf=["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"],Rf=Cf.map(r=>new Aa.Netmask(r));function ts(r){for(let t of Rf)if(t.contains(r))return!0;return!1}function Pf(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Of(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 ts(o)}function Nf(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function kf(r){let t=r.split(":"),e=t[t.length-1];return ts(e)}function Uf(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Ia(r){if(ke(r))return ts(r);if(Pf(r))return Of(r);if(Nf(r))return kf(r);if(an(r))return Uf(r)}function es(r){try{let t=_t(r);switch(t.type){case"ip4":case"ip6":return Ia(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function Ue(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var cn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Me=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new cn(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 cn(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 rs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function un(r={}){return Mf(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 Mf(r,t){t=t??{};let e=t.onEnd,n=new Me,o,s,i,c=Ue(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,h)=>{s=g=>{s=null,n.push(g);try{x(r(n))}catch(b){h(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Ue()})}},u=x=>s!=null?s(x):(n.push(x),o),d=x=>(n=new Me,s!=null?s({error:x}):(n.push({error:x}),o)),l=x=>{if(i)return o;if(t?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:x})},f=x=>i?o:(i=!0,x!=null?d(x):u({done:!0})),p=()=>(n=new Me,f(),{done:!0}),m=x=>(f(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:p,throw:m,push:l,end:f,get readableLength(){return n.size},onEmpty:async x=>{let h=x?.signal;if(h?.throwIfAborted(),n.isEmpty())return;let g,b;h!=null&&(g=new Promise((_,L)=>{b=()=>{L(new rs)},h.addEventListener("abort",b)}));try{await Promise.race([c.promise,g])}finally{b!=null&&h!=null&&h?.removeEventListener("abort",b)}}},e==null)return o;let S=o;return o={[Symbol.asyncIterator](){return this},next(){return S.next()},throw(x){return S.throw(x),e!=null&&(e(x),e=void 0),{done:!0}},return(){return S.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(x){return S.end(x),e!=null&&(e(x),e=void 0),o},get readableLength(){return S.readableLength},onEmpty:x=>S.onEmpty(x)},o}var ns=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},La=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function os(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,c,a,d=new Promise((l,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){f(La(i));return}if(i&&(a=()=>{f(La(i))},i.addEventListener("abort",a,{once:!0})),r.then(l,f),e===Number.POSITIVE_INFINITY)return;let p=new ns;c=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){f(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?f(o):(p.message=o??`Promise timed out after ${e} milliseconds`,f(p))},e)}).finally(()=>{d.clear(),a&&i&&i.removeEventListener("abort",a)});return d.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},d}var Kf=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 Ff(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let c=[t].flat(),a=[],{addListener:u,removeListener:d}=Kf(r),l=async(...p)=>{let m=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(m))return}catch(S){n(),i(S);return}a.push(m),e.count===a.length&&(n(),s(a))},f=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of c)d(p,l);for(let p of e.rejectionEvents)c.includes(p)||d(p,f)};for(let p of c)u(p,l);for(let p of e.rejectionEvents)c.includes(p)||u(p,f);e.signal&&e.signal.addEventListener("abort",()=>{f(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(a)});if(o.cancel=n,typeof e.timeout=="number"){let s=os(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Ke(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=Ff(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function br(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 fn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},pe=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function qf(r){return r.reason}async function yr(r,t,e){if(t==null)return r;let n=e?.translateError??qf;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 ln=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Ue(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Tt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function zf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var dn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=zf(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Tt),this.cleanup())}async join(t={}){let e=new ln(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 yr(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 hn=class extends _r{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=br(this.emitEmpty.bind(this),1),this.emitIdle=br(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 fn;let n=new dn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Tt)}),this.clear()}async onEmpty(t){this.size!==0&&await Ke(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await Ke(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Ke(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=un({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),e.end(a)},o=a=>{a.detail!=null&&e.push(a.detail)},s=a=>{n(a.detail.error)},i=()=>{n()},c=()=>{n(new Tt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",c);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",c),n()}}};function pn(r){let t=new globalThis.AbortController;function e(){let s=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}var st=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},zt=class extends Error{static name="ValidationError";name="ValidationError"},mn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},gn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function is(r){return t=>Q(t,r)}function as(r){return t=>$(t,r)}function Fe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function me(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Ta(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=$(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=me(n);return Dt([e,o],e.length+o.length)}function Ba(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=$t.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=me(n);return Dt([e,o],e.length+o.length)}function cs(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=Q(t,"base32"),o=Fe(e);return`${n}:${o}`}var us=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new st("Invalid byte value in IP address");t[n]=o}),t},Da=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ke(e[n]),i;s&&(i=us(e[n]),e[n]=Q(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,Q(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new st("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ca=function(r){if(r.byteLength!==4)throw new st("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Ra=function(r){if(r.byteLength!==16)throw new st("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${e}"`)}};function Pa(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${r}"`)}}var ss=Object.values(Ge).map(r=>r.decoder),Vf=(function(){let r=ss[0].or(ss[1]);return ss.slice(2).forEach(t=>r=r.or(t)),r})();function Oa(r){return Vf.decode(r)}function Na(r){return t=>r.encoder.encode(t)}function Hf(r){if(parseInt(r).toString()!==r)throw new zt("Value must be an integer")}function $f(r){if(r<0)throw new zt("Value must be a positive integer, or zero")}function jf(r){return t=>{if(t>r)throw new zt(`Value must be smaller than or equal to ${r}`)}}function Gf(...r){return t=>{for(let e of r)e(t)}}var xr=Gf(Hf,$f,jf(65535));var rt=-1,fs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new gn(`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)}))}},Vt=new fs,Pl=[{code:4,name:"ip4",size:32,valueToBytes:us,bytesToValue:Ca,validate:r=>{if(!ke(r))throw new zt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:me,bytesToValue:Fe,validate:xr},{code:273,name:"udp",size:16,valueToBytes:me,bytesToValue:Fe,validate:xr},{code:33,name:"dccp",size:16,valueToBytes:me,bytesToValue:Fe,validate:xr},{code:41,name:"ip6",size:128,valueToBytes:Da,bytesToValue:Ra,stringToValue:Pa,validate:r=>{if(!an(r))throw new zt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:rt},{code:43,name:"ipcidr",size:8,bytesToValue:is("base10"),valueToBytes:as("base10")},{code:53,name:"dns",size:rt},{code:54,name:"dns4",size:rt},{code:55,name:"dns6",size:rt},{code:56,name:"dnsaddr",size:rt},{code:132,name:"sctp",size:16,valueToBytes:me,bytesToValue:Fe,validate:xr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:rt,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:rt,bytesToValue:is("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?as("base58btc")(r):at.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:cs,valueToBytes:Ta},{code:445,name:"onion3",size:296,bytesToValue:cs,valueToBytes:Ba},{code:446,name:"garlic64",size:rt},{code:447,name:"garlic32",size:rt},{code:448,name:"tls"},{code:449,name:"sni",size:rt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:rt,bytesToValue:Na(Un),valueToBytes:Oa},{code:480,name:"http"},{code:481,name:"http-path",size:rt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:rt}];Pl.forEach(r=>{Vt.addProtocol(r)});function ka(r){let t=[],e=0;for(;e<r.length;){let n=sr(r,e),o=Vt.getProtocol(n),s=gt(n),i=Ol(o,r,e+s),c=0;i>0&&o.size===rt&&(c=gt(i));let a=s+c+i,u={code:n,name:o.name,bytes:r.subarray(e,e+a)};if(i>0){let d=e+s+c,l=r.subarray(d,d+i);u.value=o.bytesToValue?.(l)??Q(l)}t.push(u),e+=a}return t}function Ua(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Vt.getProtocol(n.code),s=gt(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??$(n.value),c=i.byteLength,o.size===rt&&(a=gt(c)));let u=new Uint8Array(s+a+c),d=0;De(n.code,u,d),d+=s,i!=null&&(o.size===rt&&(De(c,u,d),d+=a),u.set(i,d)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return Dt(e,t)}function Ma(r){if(r.charAt(0)!=="/")throw new st('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let c=s===r.length-1;if(i==="/"||c){let a=Vt.getProtocol(o);if(e==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",e="protocol";continue}else if(c)throw new st(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new st(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new st("Incomplete multiaddr");return t}function Ka(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Vt.getProtocol(t.code);if(e==null)throw new st(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Ol(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:sr(t,e)}var Nl=Symbol.for("nodejs.util.inspect.custom"),ls=Symbol.for("@multiformats/multiaddr");function kl(r){if(r==null&&(r="/"),Fa(r))return r.getComponents();if(r instanceof Uint8Array)return ka(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Ma(r);if(Array.isArray(r))return r;throw new st("Must be a string, Uint8Array, Component[], or another Multiaddr")}var yn=class r{[ls]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=kl(t),e.validate!==!1&&Ul(this)}get bytes(){return this.#r==null&&(this.#r=Ua(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Ka(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 mn(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return lt(this.bytes,t.bytes)}[Nl](){return`Multiaddr(${this.toString()})`}};function Ul(r){r.getComponents().forEach(t=>{let e=Vt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function Fa(r){return!!r?.[ls]}function qa(r){return new yn(r)}var Ml=4194304,xn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},hs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ps=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ms=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Kl(r){return typeof r?.closeRead=="function"}function Fl(r){return typeof r?.close=="function"}function ds(r){return Kl(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:Fl(r)?r.status!=="open":!1}function ql(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function zl(r,t){let e=t?.maxBufferSize??Ml,n=new J,o,s=!1;if(!ql(r))throw new ft("Argument should be a Stream or a Multiaddr");let i=d=>{if(n.append(d.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 c=d=>{d.error!=null?o?.reject(d.error):o?.resolve()};r.addEventListener("close",c);let a=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(d){if(s===!0)throw new xn("Stream was unwrapped");if(ds(r)){if(n.byteLength===0&&d?.bytes==null)return null;if(d?.bytes!=null&&n.byteLength<d.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new pe(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let l=d?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await yr(o.promise,d?.signal),ds(r)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let f=d?.bytes??n.byteLength;if(n.byteLength<f){if(ds(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,f),new pe(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return u.read(d)}let p=n.sublist(0,f);return n.consume(f),p},async write(d,l){if(s===!0)throw new xn("Stream was unwrapped");r.send(d)||await Ke(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",c),r.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function Vl(r,t={}){let e=zl(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=gt(t.maxDataLength));let n=t?.lengthDecoder??sr,o=t?.lengthEncoder??Hi;return{async read(i){let c=-1,a=new J;for(;;){let d=await e.read({...i,bytes:1});if(d==null)break;a.append(d);try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new hs("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new ms(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new ps(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await e.read({...i,bytes:c});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",c),new pe(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new pe(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(i,c){await e.write(new J(o(i.byteLength),i),c)},async writeV(i,c){let a=new J(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(a,c)},unwrap(){return e.unwrap()}}}function gs(r,t){let e=Vl(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var wn=class extends hn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function za(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal},d;e?.timeout!=null&&(d=pn([o.signal,AbortSignal.timeout(e.timeout)]),u.signal=d),s=!0,Promise.resolve().then(async()=>{await r(u)}).catch(()=>{}).finally(()=>{d!=null&&(d.aborted?d.clear():d.addEventListener("abort",()=>{d.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let c=br(i,e?.debounce??100),a=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{e??={},e.timeout=u},run:()=>{s||(clearTimeout(n),c())},start:()=>{a||(a=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),a=!1}}}var bs=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Va(r){let{name:t,metrics:e}=r,n;return e!=null?n=new bs({name:t,metrics:e}):n=new Map,n}var Ha="libp2p",$a="autonat",ja="1.0.0";var z;(function(r){let t;(function(f){f.DIAL="DIAL",f.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(f){f[f.DIAL=0]="DIAL",f[f.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),(function(f){f.codec=()=>Ce(e)})(t=r.MessageType||(r.MessageType={}));let n;(function(f){f.OK="OK",f.E_DIAL_ERROR="E_DIAL_ERROR",f.E_DIAL_REFUSED="E_DIAL_REFUSED",f.E_BAD_REQUEST="E_BAD_REQUEST",f.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(f){f[f.OK=0]="OK",f[f.E_DIAL_ERROR=100]="E_DIAL_ERROR",f[f.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",f[f.E_BAD_REQUEST=200]="E_BAD_REQUEST",f[f.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(f){f.codec=()=>Ce(o)})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(f){let p;f.codec=()=>(p==null&&(p=Ft((h,g,b={})=>{if(b.lengthDelimited!==!1&&g.fork(),h.id!=null&&(g.uint32(10),g.bytes(h.id)),h.addrs!=null&&h.addrs.length>0)for(let _ of h.addrs)g.uint32(18),g.bytes(_);b.lengthDelimited!==!1&&g.ldelim()},(h,g,b={})=>{let _={addrs:[]},L=g==null?h.len:h.pos+g;for(;h.pos<L;){let C=h.uint32();switch(C>>>3){case 1:{_.id=h.bytes();break}case 2:{if(b.limits?.addrs!=null&&_.addrs.length===b.limits.addrs)throw new ur('Decode error - repeated field "addrs" had too many elements');_.addrs.push(h.bytes());break}default:{h.skipType(C&7);break}}}return _},function*(h,g,b,_={}){let L={addrs:0},C=g==null?h.len:h.pos+g;for(;h.pos<C;){let U=h.uint32();switch(U>>>3){case 1:{yield{field:`${b}.id`,value:h.bytes()};break}case 2:{if(_.limits?.addrs!=null&&L.addrs===_.limits.addrs)throw new ur('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${b}.addrs[]`,index:L.addrs,value:h.bytes()},L.addrs++;break}default:{h.skipType(U&7);break}}}})),p);function m(h){return Mt(h,f.codec())}f.encode=m;function S(h,g){return Ut(h,f.codec(),g)}f.decode=S;function x(h,g){return Kt(h,f.codec(),g)}f.stream=x})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(f){let p;f.codec=()=>(p==null&&(p=Ft((h,g,b={})=>{b.lengthDelimited!==!1&&g.fork(),h.peer!=null&&(g.uint32(10),r.PeerInfo.codec().encode(h.peer,g)),b.lengthDelimited!==!1&&g.ldelim()},(h,g,b={})=>{let _={},L=g==null?h.len:h.pos+g;for(;h.pos<L;){let C=h.uint32();switch(C>>>3){case 1:{_.peer=r.PeerInfo.codec().decode(h,h.uint32(),{limits:b.limits?.peer});break}default:{h.skipType(C&7);break}}}return _},function*(h,g,b,_={}){let L=g==null?h.len:h.pos+g;for(;h.pos<L;){let C=h.uint32();switch(C>>>3){case 1:{yield*r.PeerInfo.codec().stream(h,h.uint32(),`${b}.peer`,{limits:_.limits?.peer});break}default:{h.skipType(C&7);break}}}})),p);function m(h){return Mt(h,f.codec())}f.encode=m;function S(h,g){return Ut(h,f.codec(),g)}f.decode=S;function x(h,g){return Kt(h,f.codec(),g)}f.stream=x})(i=r.Dial||(r.Dial={}));let c;(function(f){let p;f.codec=()=>(p==null&&(p=Ft((h,g,b={})=>{b.lengthDelimited!==!1&&g.fork(),h.status!=null&&(g.uint32(8),r.ResponseStatus.codec().encode(h.status,g)),h.statusText!=null&&(g.uint32(18),g.string(h.statusText)),h.addr!=null&&(g.uint32(26),g.bytes(h.addr)),b.lengthDelimited!==!1&&g.ldelim()},(h,g,b={})=>{let _={},L=g==null?h.len:h.pos+g;for(;h.pos<L;){let C=h.uint32();switch(C>>>3){case 1:{_.status=r.ResponseStatus.codec().decode(h);break}case 2:{_.statusText=h.string();break}case 3:{_.addr=h.bytes();break}default:{h.skipType(C&7);break}}}return _},function*(h,g,b,_={}){let L=g==null?h.len:h.pos+g;for(;h.pos<L;){let C=h.uint32();switch(C>>>3){case 1:{yield{field:`${b}.status`,value:r.ResponseStatus.codec().decode(h)};break}case 2:{yield{field:`${b}.statusText`,value:h.string()};break}case 3:{yield{field:`${b}.addr`,value:h.bytes()};break}default:{h.skipType(C&7);break}}}})),p);function m(h){return Mt(h,f.codec())}f.encode=m;function S(h,g){return Ut(h,f.codec(),g)}f.decode=S;function x(h,g){return Kt(h,f.codec(),g)}f.stream=x})(c=r.DialResponse||(r.DialResponse={}));let a;r.codec=()=>(a==null&&(a=Ft((f,p,m={})=>{m.lengthDelimited!==!1&&p.fork(),f.type!=null&&(p.uint32(8),r.MessageType.codec().encode(f.type,p)),f.dial!=null&&(p.uint32(18),r.Dial.codec().encode(f.dial,p)),f.dialResponse!=null&&(p.uint32(26),r.DialResponse.codec().encode(f.dialResponse,p)),m.lengthDelimited!==!1&&p.ldelim()},(f,p,m={})=>{let S={},x=p==null?f.len:f.pos+p;for(;f.pos<x;){let h=f.uint32();switch(h>>>3){case 1:{S.type=r.MessageType.codec().decode(f);break}case 2:{S.dial=r.Dial.codec().decode(f,f.uint32(),{limits:m.limits?.dial});break}case 3:{S.dialResponse=r.DialResponse.codec().decode(f,f.uint32(),{limits:m.limits?.dialResponse});break}default:{f.skipType(h&7);break}}}return S},function*(f,p,m,S={}){let x=p==null?f.len:f.pos+p;for(;f.pos<x;){let h=f.uint32();switch(h>>>3){case 1:{yield{field:`${m}.type`,value:r.MessageType.codec().decode(f)};break}case 2:{yield*r.Dial.codec().stream(f,f.uint32(),`${m}.dial`,{limits:S.limits?.dial});break}case 3:{yield*r.DialResponse.codec().stream(f,f.uint32(),`${m}.dialResponse`,{limits:S.limits?.dialResponse});break}default:{f.skipType(h&7);break}}}})),a);function u(f){return Mt(f,r.codec())}r.encode=u;function d(f,p){return Ut(f,r.codec(),p)}r.decode=d;function l(f,p){return Kt(f,r.codec(),p)}r.stream=l})(z||(z={}));var Yl=4,Xl=8,En=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${e.protocolPrefix??Ha}/${$a}/${ja}`,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=Va({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=za(this.findRandomPeers.bind(this),6e4),this.addressFilter=Xo(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Es]=["@libp2p/autonat"];get[Ss](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,e)=>{this.handleIncomingAutonatStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=pn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,e){let n=AbortSignal.timeout(this.timeout);try{let o=gs(t,{maxDataLength:this.maxMessageSize}).pb(z),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,e,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(l=>_t(l).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,c=s.peer;if(c?.id==null)return this.log.error("peerId missing from message"),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let l=te(c.id);i=Jr(l)}catch(l){return this.log.error("invalid PeerId - %e",l),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let a=c.addrs.map(l=>qa(l)).filter(l=>{try{let f=_t(l);return es(l)?!1:f.host!==_t(e.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",l,e.remoteAddr),!1):o.includes(f.host)?!1:this.components.transportManager.dialTransportForMultiaddr(l)==null?(this.log.trace("not dialing %a - transport unsupported",l),!1):!0}catch{return!1}}).map(l=>(l.getComponents().find(f=>f.code===421)?.value==null&&(l=l.encapsulate(`/p2p/${i.toString()}`)),l));if(a.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",a.map(l=>l.toString()).join(", "),i);let u="",d=a[0];for(let l of a){let f;d=l;try{if(f=await this.components.connectionManager.openConnection(l,n),!f.remoteAddr.equals(l))throw this.log.error("tried to dial %a but dialed %a",l,f.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,l),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.OK,addr:f.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),u=p.message}finally{f!=null&&await f.close()}}return{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:d.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||_t(o.multiaddr).type==="ip6"&&(!e||!va(o.multiaddr))||es(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let c=o.expires<Date.now();if(c&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:jo(),queue:new wn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>_t(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let c=gs(i).pb(z),[,a]=await Promise.all([c.write({type:z.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),c.read({signal:s})]);if(a.type!==z.MessageType.DIAL_RESPONSE||a.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,a);return}let u=a.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==z.ResponseStatus.OK&&u!==z.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,a.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),u===z.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===z.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Yl&&this.confirmAddress(o),o.failure===Xl&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(c){i.abort(c)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=_t(t);switch(e.type){case"ip4":return e.host.split(".")[0].padStart(3,"0");case"ip6":return e.host.split(":")[0].padStart(4,"0");default:throw new ft(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function Wl(r={}){return t=>new En(t,r)}return tc(Ql);})();
|
|
2
|
+
"use strict";var Libp2PAutonat=(()=>{var cc=Object.create;var Ar=Object.defineProperty;var uc=Object.getOwnPropertyDescriptor;var fc=Object.getOwnPropertyNames;var lc=Object.getPrototypeOf,dc=Object.prototype.hasOwnProperty;var Ln=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)Ar(r,e,{get:t[e],enumerable:!0})},Ps=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of fc(t))!dc.call(r,o)&&o!==e&&Ar(r,o,{get:()=>t[o],enumerable:!(n=uc(t,o))||n.enumerable});return r};var hc=(r,t,e)=>(e=r!=null?cc(lc(r)):{},Ps(t||!r||!r.__esModule?Ar(e,"default",{value:r,enumerable:!0}):e,r)),pc=r=>Ps(Ar({},"__esModule",{value:!0}),r);var cs=Ln(qe=>{"use strict";Object.defineProperty(qe,"__esModule",{value:!0});qe.Netmask4Impl=void 0;qe.ip2long=Fe;qe.long2ip=Lt;function Lt(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 $f=48,jf=97,Gf=65;function Zf(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)-$f)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-jf)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.charCodeAt(o)-Gf)>>>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 Fe(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]=Zf(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 as=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=Fe(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=(Fe(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=Lt(this.netLong),this.mask=Lt(this.maskLong),this.hostmask=Lt(~this.maskLong),this.first=this.bitmask<=30?Lt(this.netLong+1):this.base,this.last=this.bitmask<=30?Lt(this.netLong+this.size-2):Lt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Lt(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):(Fe(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(Lt(this.netLong+this.size*t),this.mask)}forEach(t){let e=Fe(this.first),n=Fe(this.last),o=0;for(;e<=n;)t(Lt(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};qe.Netmask4Impl=as});var Ma=Ln(ze=>{"use strict";Object.defineProperty(ze,"__esModule",{value:!0});ze.Netmask6Impl=void 0;ze.ip6bigint=fs;ze.bigint2ip6=ge;var Yf=cs(),us=(1n<<128n)-1n;function fs(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,Yf.ip2long)(n),s=r.substring(0,e+1)+"0:0";return Ua(s)&~0xffffffffn|BigInt(o)}return Ua(r)}function Ua(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 ge(r){if(r<0n||r>us)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 ls=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=us>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=fs(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=ge(this.netBigint),this.mask=ge(this.maskBigint),this.hostmask=ge(~this.maskBigint&us),this.first=this.base,this.last=ge(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):(fs(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(ge(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(ge(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};ze.Netmask6Impl=ls});var Ka=Ln(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.long2ip=ee.ip2long=ee.Netmask=void 0;var hn=cs();Object.defineProperty(ee,"ip2long",{enumerable:!0,get:function(){return hn.ip2long}});Object.defineProperty(ee,"long2ip",{enumerable:!0,get:function(){return hn.long2ip}});var Xf=Ma(),ds=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 Xf.Netmask6Impl(t,e):this._impl=new hn.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 hn.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()}};ee.Netmask=ds});var yd={};bt(yd,{autoNAT:()=>bd});var Tt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ft=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Br=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Lr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ge=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Tn=Symbol.for("@libp2p/peer-id");var Tr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Os=Symbol.for("@libp2p/service-capabilities"),ks=Symbol.for("@libp2p/service-dependencies");var On={};bt(On,{base58btc:()=>X,base58flickr:()=>Ec});var Zd=new Uint8Array(0);function Ns(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 Dt(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 Us(r){return new TextEncoder().encode(r)}function Ms(r){return new TextDecoder().decode(r)}function mc(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),l=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function h(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var v=0,x=0,f=0,g=m.length;f!==g&&m[f]===0;)f++,v++;for(var b=(g-f)*d+1>>>0,_=new Uint8Array(b);f!==g;){for(var B=m[f],C=0,U=b-1;(B!==0||C<x)&&U!==-1;U--,C++)B+=256*_[U]>>>0,_[U]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");x=C,f++}for(var I=b-x;I!==b&&_[I]===0;)I++;for(var S=c.repeat(v);I<b;++I)S+=r.charAt(_[I]);return S}function u(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var v=0;if(m[v]!==" "){for(var x=0,f=0;m[v]===c;)x++,v++;for(var g=(m.length-v)*l+1>>>0,b=new Uint8Array(g);m[v];){var _=e[m.charCodeAt(v)];if(_===255)return;for(var B=0,C=g-1;(_!==0||B<f)&&C!==-1;C--,B++)_+=a*b[C]>>>0,b[C]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");f=B,v++}if(m[v]!==" "){for(var U=g-f;U!==g&&b[U]===0;)U++;for(var I=new Uint8Array(x+(g-U)),S=x;U!==g;)I[S++]=b[U++];return I}}}function p(m){var v=u(m);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:u,decode:p}}var gc=mc,bc=gc,Fs=bc;var Dn=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")}},Cn=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 qs(this,t)}},Rn=class{decoders;constructor(t){this.decoders=t}or(t){return qs(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 qs(r,t){return new Rn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Pn=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 Dn(t,e,n),this.decoder=new Cn(t,e,o)}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 Pn(r,t,e,n)}function $t({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Fs(e,r);return xe({prefix:t,name:r,encode:n,decode:s=>Dt(o(s))})}function yc(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 l=0;l<o;++l){let d=t[r[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function xc(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 wc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=wc(n);return xe({prefix:t,name:r,encode(s){return xc(s,n,e)},decode(s){return yc(s,o,e,r)}})}var X=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ec=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kn={};bt(kn,{base32:()=>jt,base32hex:()=>Ic,base32hexpad:()=>Bc,base32hexpadupper:()=>Lc,base32hexupper:()=>Ac,base32pad:()=>vc,base32padupper:()=>_c,base32upper:()=>Sc,base32z:()=>Tc});var jt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Sc=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vc=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_c=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ic=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ac=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Bc=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Lc=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Tc=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Nn={};bt(Nn,{base36:()=>Ze,base36upper:()=>Dc});var Ze=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Dc=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cc=Hs,zs=128,Rc=127,Pc=~Rc,Oc=Math.pow(2,31);function Hs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Oc;)t[e++]=r&255|zs,r/=128;for(;r&Pc;)t[e++]=r&255|zs,r>>>=7;return t[e]=r|0,Hs.bytes=e-n+1,t}var kc=Un,Nc=128,Vs=127;function Un(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Un.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Vs)<<o:(i&Vs)*Math.pow(2,o),o+=7}while(i>=Nc);return Un.bytes=s-n,e}var Uc=Math.pow(2,7),Mc=Math.pow(2,14),Kc=Math.pow(2,21),Fc=Math.pow(2,28),qc=Math.pow(2,35),zc=Math.pow(2,42),Vc=Math.pow(2,49),Hc=Math.pow(2,56),$c=Math.pow(2,63),jc=function(r){return r<Uc?1:r<Mc?2:r<Kc?3:r<Fc?4:r<qc?5:r<zc?6:r<Vc?7:r<Hc?8:r<$c?9:10},Gc={encode:Cc,decode:kc,encodingLength:jc},Zc=Gc,Ye=Zc;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),o=n+Ee(e),s=new Uint8Array(o+e);return we(r,s,0),we(e,s,n),s.set(t,o),new Se(r,e,t,s)}function re(r){let t=Dt(r),[e,n]=Xe(t),[o,s]=Xe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Se(e,o,i,t)}function $s(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ns(r.bytes,e.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function js(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Xc(e,Mn(r),t??X.encoder);default:return Wc(e,Mn(r),t??jt.encoder)}}var Gs=new WeakMap;function Mn(r){let t=Gs.get(r);if(t==null){let e=new Map;return Gs.set(r,e),e}return t}var at=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==We)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Qc)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&&$s(t.multihash,n.multihash)}toString(t){return js(this,t)}toJSON(){return{"/":js(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Zs(n,o,s.bytes))}else if(e[Jc]===!0){let{version:n,multihash:o,code:s}=e,i=re(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==We)throw new Error(`Version 0 CID must use dag-pb (code: ${We}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Zs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,We,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Dt(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 Se(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,u]=Xe(t.subarray(e));return e+=u,h},o=n(),s=We;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),l=e+c,d=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:l}}static parse(t,e){let[n,o]=Yc(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 Mn(s).set(n,t),s}};function Yc(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 jt.prefix:{let e=t??jt;return[jt.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 Xc(r,t,e){let{prefix:n}=e;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Wc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var We=112,Qc=18;function Zs(r,t,e){let n=Ee(r),o=n+Ee(t),s=new Uint8Array(o+e.byteLength);return we(r,s,0),we(t,s,n),s.set(e,o),s}var Jc=Symbol.for("@ipld/js-cid/CID");var Kn={};bt(Kn,{identity:()=>xt});var Ys=0,tu="identity",Xs=Dt;function eu(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(Ys,Xs(r))}var xt={code:Ys,name:tu,encode:Xs,digest:eu};function lt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function wt(r=0){return new Uint8Array(r)}function pt(r=0){return new Uint8Array(r)}function Ct(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=pt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Qs=Symbol.for("@achingbrain/uint8arraylist");function Ws(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Cr(r){return!!r?.[Qs]}var J=class r{bufs;length;[Qs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Cr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Cr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ws(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ws(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Cr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Ct(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Ct(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 l=t>=a&&t<c,d=e>a&&e<=c;if(l&&d){if(t===a&&e===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Cr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,d;for(let h=e;h<=c;h+=d){d=0;for(let u=l;u>=0;u--){let p=this.get(h+u);if(n[u]!==p){d=Math.max(1,u-a[p]);break}}if(d===0)return h}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=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 o=wt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=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 o=wt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!lt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Fn={};bt(Fn,{base10:()=>ru});var ru=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var qn={};bt(qn,{base16:()=>nu,base16upper:()=>ou});var nu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ou=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zn={};bt(zn,{base2:()=>su});var su=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vn={};bt(Vn,{base256emoji:()=>fu});var Js=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}"),iu=Js.reduce((r,t,e)=>(r[e]=t,r),[]),au=Js.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function cu(r){return r.reduce((t,e)=>(t+=iu[e],t),"")}function uu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=au[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var fu=xe({prefix:"\u{1F680}",name:"base256emoji",encode:cu,decode:uu});var $n={};bt($n,{base64:()=>lu,base64pad:()=>du,base64url:()=>Hn,base64urlpad:()=>hu});var lu=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),du=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Hn=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hu=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var jn={};bt(jn,{base8:()=>pu});var pu=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Gn={};bt(Gn,{identity:()=>mu});var mu=xe({prefix:"\0",name:"identity",encode:r=>Ms(r),decode:r=>Us(r)});var Ch=new TextEncoder,Rh=new TextDecoder;var Xn={};bt(Xn,{sha256:()=>Qe,sha512:()=>xu});var yu=20;function Yn({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Zn(r,t,e,n,o)}var Zn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??yu,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?ti(n,this.code,e?.truncate):n.then(o=>ti(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function ti(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 ri(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Qe=Yn({name:"sha2-256",code:18,encode:ri("SHA-256")}),xu=Yn({name:"sha2-512",code:19,encode:ri("SHA-512")});var Je={...Gn,...zn,...jn,...Fn,...qn,...kn,...Nn,...On,...$n,...Vn},Hh={...Xn,...Kn};function oi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ni=oi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Wn=oi("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}),wu={utf8:ni,"utf-8":ni,hex:Je.base16,latin1:Wn,ascii:Wn,binary:Wn,...Je},Rr=wu;function $(r,t="utf8"){let e=Rr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Q(r,t="utf8"){let e=Rr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Eu=parseInt("11111",2),Qn=parseInt("10000000",2),Su=parseInt("01111111",2),si={0:tr,1:tr,2:vu,3:Au,4:Bu,5:Iu,6:_u,16:tr,22:tr,48:tr};function Jn(r,t={offset:0}){let e=r[t.offset]&Eu;if(t.offset++,si[e]!=null)return si[e](r,t);throw new Error("No decoder for tag "+e)}function er(r,t){let e=0;if((r[t.offset]&Qn)===Qn){let n=r[t.offset]&Su,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function tr(r,t){er(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Jn(r,t);if(n===null)break;e.push(n)}return e}function vu(r,t){let e=er(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function _u(r,t){let e=er(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let d=0;for(let h=0;h<c.length;h++)d+=c[h]<<h*7;a+=`.${d}`,c=[]}}return a}function Iu(r,t){return t.offset++,null}function Au(r,t){let e=er(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Bu(r,t){let e=er(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Lu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new J;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function to(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Lu(r.byteLength);return new J(Uint8Array.from([t.byteLength|Qn]),t)}function ii(r){let t=new J,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new J(Uint8Array.from([2]),to(t),t)}function ai(r){let t=Uint8Array.from([0]),e=new J(t,r);return new J(Uint8Array.from([3]),to(e),e)}function Pr(r,t=48){let e=new J;for(let n of r)e.append(n);return new J(Uint8Array.from([t]),to(e),e)}async function ci(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 Tu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Du=Uint8Array.from([6,5,43,129,4,0,34]),Cu=Uint8Array.from([6,5,43,129,4,0,35]),Ru={ext:!0,kty:"EC",crv:"P-256"},Pu={ext:!0,kty:"EC",crv:"P-384"},Ou={ext:!0,kty:"EC",crv:"P-521"},eo=32,ro=48,no=66;function ui(r){let t=Jn(r);return fi(t)}function fi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===eo*2+1)return n=Q(t.subarray(e,e+eo),"base64url"),o=Q(t.subarray(e+eo),"base64url"),new _e({...Ru,key_ops:["verify"],x:n,y:o});if(t.byteLength===ro*2+1)return n=Q(t.subarray(e,e+ro),"base64url"),o=Q(t.subarray(e+ro),"base64url"),new _e({...Pu,key_ops:["verify"],x:n,y:o});if(t.byteLength===no*2+1)return n=Q(t.subarray(e,e+no),"base64url"),o=Q(t.subarray(e+no),"base64url"),new _e({...Ou,key_ops:["verify"],x:n,y:o});throw new ft(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function li(r){return Pr([ii(Uint8Array.from([1])),Pr([ku(r.crv)],160),Pr([ai(new J(Uint8Array.from([4]),$(r.x??"","base64url"),$(r.y??"","base64url")))],161)]).subarray()}function ku(r){if(r==="P-256")return Tu;if(r==="P-384")return Du;if(r==="P-521")return Cu;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=li(this.jwk)),this._raw}toMultihash(){return xt.digest(Ie(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 ci(this.jwk,e,t,n)}};function ne(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function At(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function M(r,t,e=""){let n=ne(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Or(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");At(r.outputLen),At(r.blockLen)}function Ae(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function hi(r,t){M(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 Pt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function kr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Et(r,t){return r<<32-t|r>>>t}var pi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Nu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Ot(r){if(M(r),pi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Nu[r[e]];return t}var Rt={_0:48,_9:57,A:65,F:70,a:97,f:102};function di(r){if(r>=Rt._0&&r<=Rt._9)return r-Rt._0;if(r>=Rt.A&&r<=Rt.F)return r-(Rt.A-10);if(r>=Rt.a&&r<=Rt.f)return r-(Rt.a-10)}function kt(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(pi)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=di(r.charCodeAt(s)),a=di(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function mt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];M(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 oo(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function 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 so=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function mi(r,t,e){return r&t^~r&e}function gi(r,t,e){return r&t^r&e^t&e}var rr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=kr(this.buffer)}update(t){Ae(this),M(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=kr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ae(this),hi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Pt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)e[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=kr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let l=c/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<l;h++)a.setUint32(4*h,d[h],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nr=BigInt(4294967295),bi=BigInt(32);function Uu(r,t=!1){return t?{h:Number(r&Nr),l:Number(r>>bi&Nr)}:{h:Number(r>>bi&Nr)|0,l:Number(r&Nr)|0}}function yi(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}=Uu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var io=(r,t,e)=>r>>>e,ao=(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 Bt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var xi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),wi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ei=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Si=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,vi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),_i=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Ku=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),co=class extends rr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let h=0;h<16;h++,e+=4)Zt[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let u=Zt[h-15],p=Zt[h-2],m=Et(u,7)^Et(u,18)^u>>>3,v=Et(p,17)^Et(p,19)^p>>>10;Zt[h]=v+Zt[h-7]+m+Zt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:d}=this;for(let h=0;h<64;h++){let u=Et(a,6)^Et(a,11)^Et(a,25),p=d+u+mi(a,c,l)+Ku[h]+Zt[h]|0,v=(Et(n,2)^Et(n,13)^Et(n,22))+gi(n,o,s)|0;d=l,l=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+v|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,l,d)}roundClean(){Pt(Zt)}destroy(){this.set(0,0,0,0,0,0,0,0),Pt(this.buffer)}},uo=class extends co{A=Nt[0]|0;B=Nt[1]|0;C=Nt[2]|0;D=Nt[3]|0;E=Nt[4]|0;F=Nt[5]|0;G=Nt[6]|0;H=Nt[7]|0;constructor(){super(32)}};var Ii=yi(["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))),Fu=Ii[0],qu=Ii[1],Yt=new Uint32Array(80),Xt=new Uint32Array(80),fo=class extends rr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:d,Fh:h,Fl:u,Gh:p,Gl:m,Hh:v,Hl:x}=this;return[t,e,n,o,s,i,a,c,l,d,h,u,p,m,v,x]}set(t,e,n,o,s,i,a,c,l,d,h,u,p,m,v,x){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=d|0,this.Fh=h|0,this.Fl=u|0,this.Gh=p|0,this.Gl=m|0,this.Hh=v|0,this.Hl=x|0}process(t,e){for(let b=0;b<16;b++,e+=4)Yt[b]=t.getUint32(e),Xt[b]=t.getUint32(e+=4);for(let b=16;b<80;b++){let _=Yt[b-15]|0,B=Xt[b-15]|0,C=oe(_,B,1)^oe(_,B,8)^io(_,B,7),U=se(_,B,1)^se(_,B,8)^ao(_,B,7),I=Yt[b-2]|0,S=Xt[b-2]|0,k=oe(I,S,19)^nr(I,S,61)^io(I,S,6),K=se(I,S,19)^or(I,S,61)^ao(I,S,6),R=Ei(U,K,Xt[b-7],Xt[b-16]),w=Si(R,C,k,Yt[b-7],Yt[b-16]);Yt[b]=w|0,Xt[b]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:d,Eh:h,El:u,Fh:p,Fl:m,Gh:v,Gl:x,Hh:f,Hl:g}=this;for(let b=0;b<80;b++){let _=oe(h,u,14)^oe(h,u,18)^nr(h,u,41),B=se(h,u,14)^se(h,u,18)^or(h,u,41),C=h&p^~h&v,U=u&m^~u&x,I=vi(g,B,U,qu[b],Xt[b]),S=_i(I,f,_,C,Fu[b],Yt[b]),k=I|0,K=oe(n,o,28)^nr(n,o,34)^nr(n,o,39),R=se(n,o,28)^or(n,o,34)^or(n,o,39),w=n&s^n&a^s&a,E=o&i^o&c^i&c;f=v|0,g=x|0,v=p|0,x=m|0,p=h|0,m=u|0,{h,l:u}=Bt(l|0,d|0,S|0,k|0),l=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let y=xi(k,R,E);n=wi(y,S,K,w),o=y|0}({h:n,l:o}=Bt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Bt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Bt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:d}=Bt(this.Dh|0,this.Dl|0,l|0,d|0),{h,l:u}=Bt(this.Eh|0,this.El|0,h|0,u|0),{h:p,l:m}=Bt(this.Fh|0,this.Fl|0,p|0,m|0),{h:v,l:x}=Bt(this.Gh|0,this.Gl|0,v|0,x|0),{h:f,l:g}=Bt(this.Hh|0,this.Hl|0,f|0,g|0),this.set(n,o,s,i,a,c,l,d,h,u,p,m,v,x,f,g)}roundClean(){Pt(Yt,Xt)}destroy(){Pt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},lo=class extends fo{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 Ai=oo(()=>new uo,so(1));var Bi=oo(()=>new lo,so(3));var po=BigInt(0),ho=BigInt(1);function Ut(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function Li(r){if(typeof r=="bigint"){if(!Ur(r))throw new Error("positive bigint expected, got "+r)}else At(r);return r}function sr(r){let t=Li(r).toString(16);return t.length&1?"0"+t:t}function Ti(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?po:BigInt("0x"+r)}function Le(r){return Ti(Ot(r))}function ie(r){return Ti(Ot(Kr(M(r)).reverse()))}function Mr(r,t){At(t),r=Li(r);let e=kt(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function mo(r,t){return Mr(r,t).reverse()}function Kr(r){return Uint8Array.from(r)}var Ur=r=>typeof r=="bigint"&&po<=r;function zu(r,t,e){return Ur(r)&&Ur(t)&&Ur(e)&&t<=r&&r<e}function ir(r,t,e,n){if(!zu(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function go(r){let t;for(t=0;r>po;r>>=ho,t+=1);return t}var ar=r=>(ho<<BigInt(r))-ho;function Di(r,t,e){if(At(r,"hashLen"),At(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=x=>new Uint8Array(x),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),l=n(r),d=0,h=()=>{c.fill(1),l.fill(0),d=0},u=(...x)=>e(l,mt(c,...x)),p=(x=o)=>{l=u(s,x),c=u(),x.length!==0&&(l=u(i,x),c=u())},m=()=>{if(d++>=a)throw new Error("drbg: tried max amount of iterations");let x=0,f=[];for(;x<t;){c=u();let g=c.slice();f.push(g),x+=c.length}return mt(...f)};return(x,f)=>{h(),p(x);let g;for(;!(g=f(m()));)p();return h(),g}}function Wt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,a){let c=r[s];if(a&&c===void 0)return;let l=typeof c;if(l!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${l}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}function Te(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var dt=BigInt(0),tt=BigInt(1),ae=BigInt(2),Pi=BigInt(3),Oi=BigInt(4),ki=BigInt(5),Vu=BigInt(7),Ni=BigInt(8),Hu=BigInt(9),Ui=BigInt(16);function W(r,t){let e=r%t;return e>=dt?e:t+e}function H(r,t,e){let n=r;for(;t-- >dt;)n*=n,n%=e;return n}function Ci(r,t){if(r===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=dt,s=tt,i=tt,a=dt;for(;e!==dt;){let l=n/e,d=n%e,h=o-i*l,u=s-a*l;n=e,e=d,o=i,s=a,i=h,a=u}if(n!==tt)throw new Error("invert: does not exist");return W(o,t)}function yo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function Mi(r,t){let e=(r.ORDER+tt)/Oi,n=r.pow(t,e);return yo(r,n,t),n}function $u(r,t){let e=(r.ORDER-ki)/Ni,n=r.mul(t,ae),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ae),o),a=r.mul(s,r.sub(i,r.ONE));return yo(r,a,t),a}function ju(r){let t=De(r),e=Ki(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Vu)/Ui;return(a,c)=>{let l=a.pow(c,i),d=a.mul(l,n),h=a.mul(l,o),u=a.mul(l,s),p=a.eql(a.sqr(d),c),m=a.eql(a.sqr(h),c);l=a.cmov(l,d,p),d=a.cmov(u,h,m);let v=a.eql(a.sqr(d),c),x=a.cmov(l,d,v);return yo(a,x,c),x}}function Ki(r){if(r<Pi)throw new Error("sqrt is not defined for small field");let t=r-tt,e=0;for(;t%ae===dt;)t/=ae,e++;let n=ae,o=De(r);for(;Ri(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Mi;let s=o.pow(n,t),i=(t+tt)/ae;return function(c,l){if(c.is0(l))return l;if(Ri(c,l)!==1)throw new Error("Cannot find square root");let d=e,h=c.mul(c.ONE,s),u=c.pow(l,t),p=c.pow(l,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let m=1,v=c.sqr(u);for(;!c.eql(v,c.ONE);)if(m++,v=c.sqr(v),m===d)throw new Error("Cannot find square root");let x=tt<<BigInt(d-m-1),f=c.pow(h,x);d=m,h=c.sqr(f),u=c.mul(u,h),p=c.mul(p,f)}return p}}function Gu(r){return r%Oi===Pi?Mi:r%Ni===ki?$u:r%Ui===Hu?ju(r):Ki(r)}var Fi=(r,t)=>(W(r,t)&tt)===tt,Zu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Zu.reduce((n,o)=>(n[o]="function",n),t);return Wt(r,e),r}function Yu(r,t,e){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(e===dt)return r.ONE;if(e===tt)return t;let n=r.ONE,o=t;for(;e>dt;)e&tt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=tt;return n}function cr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Ri(r,t){let e=(r.ORDER-tt)/ae,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Xu(r,t){t!==void 0&&At(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var bo=class{ORDER;BITS;BYTES;isLE;ZERO=dt;ONE=tt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=dt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=Xu(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return dt<=t&&t<this.ORDER}is0(t){return t===dt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&tt)===tt}neg(t){return W(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return W(t*t,this.ORDER)}add(t,e){return W(t+e,this.ORDER)}sub(t,e){return W(t-e,this.ORDER)}mul(t,e){return W(t*e,this.ORDER)}pow(t,e){return Yu(this,t,e)}div(t,e){return W(t*Ci(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 Ci(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Gu(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?mo(t,this.BYTES):Mr(t,this.BYTES)}fromBytes(t,e=!1){M(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let l=new Uint8Array(o);l.set(t,s?0:l.length-t.length),t=l}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?ie(t):Le(t);if(a&&(c=W(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return cr(this,t)}cmov(t,e,n){return n?e:t}};function De(r,t={}){return new bo(r,t)}function qi(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 wo(r){let t=qi(r);return t+Math.ceil(t/2)}function Eo(r,t,e=!1){M(r);let n=r.length,o=qi(t),s=wo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ie(r):Le(r),a=W(i,t-tt)+tt;return e?mo(a,o):Mr(a,o)}var Ce=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,o)=>r.fromAffine(n.toAffine(e[o])))}function $i(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function So(r,t){$i(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ar(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function zi(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+=ce);let l=t*n,d=l+Math.abs(a)-1,h=a===0,u=a<0,p=t%2!==0;return{nextN:c,offset:d,isZero:h,isNeg:u,isNegF:p,offsetF:l}}var vo=new WeakMap,ji=new WeakMap;function _o(r){return ji.get(r)||1}function Vi(r){if(r!==Ce)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 o=t;for(;e>Ce;)e&ce&&(n=n.add(o)),o=o.double(),e>>=ce;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=So(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let l=1;l<o;l++)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=So(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:l,isZero:d,isNeg:h,isNegF:u,offsetF:p}=zi(n,a,i);n=c,d?s=s.add(ur(u,e[p])):o=o.add(ur(h,e[l]))}return Vi(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=So(t,this.bits);for(let i=0;i<s.windows&&n!==Ce;i++){let{nextN:a,offset:c,isZero:l,isNeg:d}=zi(n,i,s);if(n=a,!l){let h=e[c];o=o.add(d?h.negate():h)}}return Vi(n),o}getPrecomputes(t,e,n){let o=vo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),vo.set(e,o))),o}cached(t,e,n){let o=_o(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=_o(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){$i(e,this.bits),ji.set(t,e),vo.delete(t)}hasCache(t){return _o(t)!==1}};function Gi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ce||n>Ce;)e&ce&&(s=s.add(o)),n&ce&&(i=i.add(o)),o=o.double(),e>>=ce,n>>=ce;return{p1:s,p2:i}}function Hi(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return xo(t),t}else return De(r,{isLE:e})}function Fr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let l=t[c];if(!(typeof l=="bigint"&&l>Ce))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Hi(t.p,e.Fp,n),s=Hi(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 qr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Qt=BigInt(0),et=BigInt(1),Io=BigInt(2),Wu=BigInt(8);function Qu(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 Zi(r,t={}){let e=Fr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;Wt(t,{},{uvRatio:"function"});let a=Io<<BigInt(o.BYTES*8)-et,c=x=>n.create(x),l=t.uvRatio||((x,f)=>{try{return{isValid:!0,value:n.sqrt(n.div(x,f))}}catch{return{isValid:!1,value:Qt}}});if(!Qu(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(x,f,g=!1){let b=g?et:Qt;return ir("coordinate "+x,f,b,a),f}function h(x){if(!(x instanceof m))throw new Error("EdwardsPoint expected")}let u=Te((x,f)=>{let{X:g,Y:b,Z:_}=x,B=x.is0();f==null&&(f=B?Wu:n.inv(_));let C=c(g*f),U=c(b*f),I=n.mul(_,f);if(B)return{x:Qt,y:et};if(I!==et)throw new Error("invZ was invalid");return{x:C,y:U}}),p=Te(x=>{let{a:f,d:g}=s;if(x.is0())throw new Error("bad point: ZERO");let{X:b,Y:_,Z:B,T:C}=x,U=c(b*b),I=c(_*_),S=c(B*B),k=c(S*S),K=c(U*f),R=c(S*c(K+I)),w=c(k+c(g*c(U*I)));if(R!==w)throw new Error("bad point: equation left != right (1)");let E=c(b*_),y=c(B*C);if(E!==y)throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(s.Gx,s.Gy,et,c(s.Gx*s.Gy));static ZERO=new m(Qt,et,et,Qt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(f,g,b,_){this.X=d("x",f),this.Y=d("y",g),this.Z=d("z",b,!0),this.T=d("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(f){if(f instanceof m)throw new Error("extended point not allowed");let{x:g,y:b}=f||{};return d("x",g),d("y",b),new m(g,b,et,c(g*b))}static fromBytes(f,g=!1){let b=n.BYTES,{a:_,d:B}=s;f=Kr(M(f,b,"point")),Ut(g,"zip215");let C=Kr(f),U=f[b-1];C[b-1]=U&-129;let I=ie(C),S=g?a:n.ORDER;ir("point.y",I,Qt,S);let k=c(I*I),K=c(k-et),R=c(B*k-_),{isValid:w,value:E}=l(K,R);if(!w)throw new Error("bad point: invalid y coordinate");let y=(E&et)===et,A=(U&128)!==0;if(!g&&E===Qt&&A)throw new Error("bad point: x=0 and x_0=1");return A!==y&&(E=c(-E)),m.fromAffine({x:E,y:I})}static fromHex(f,g=!1){return m.fromBytes(kt(f),g)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(f=8,g=!0){return v.createCache(this,f),g||this.multiply(Io),this}assertValidity(){p(this)}equals(f){h(f);let{X:g,Y:b,Z:_}=this,{X:B,Y:C,Z:U}=f,I=c(g*U),S=c(B*_),k=c(b*U),K=c(C*_);return I===S&&k===K}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:f}=s,{X:g,Y:b,Z:_}=this,B=c(g*g),C=c(b*b),U=c(Io*c(_*_)),I=c(f*B),S=g+b,k=c(c(S*S)-B-C),K=I+C,R=K-U,w=I-C,E=c(k*R),y=c(K*w),A=c(k*w),L=c(R*K);return new m(E,y,L,A)}add(f){h(f);let{a:g,d:b}=s,{X:_,Y:B,Z:C,T:U}=this,{X:I,Y:S,Z:k,T:K}=f,R=c(_*I),w=c(B*S),E=c(U*b*K),y=c(C*k),A=c((_+B)*(I+S)-R-w),L=y-E,D=y+E,P=c(w-g*R),T=c(A*L),O=c(D*P),N=c(A*P),j=c(L*D);return new m(T,O,j,N)}subtract(f){return this.add(f.negate())}multiply(f){if(!o.isValidNot0(f))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:g,f:b}=v.cached(this,f,_=>ue(m,_));return ue(m,[g,b])[0]}multiplyUnsafe(f,g=m.ZERO){if(!o.isValid(f))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return f===Qt?m.ZERO:this.is0()||f===et?this:v.unsafe(this,f,b=>ue(m,b),g)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(f){return u(this,f)}clearCofactor(){return i===et?this:this.multiplyUnsafe(i)}toBytes(){let{x:f,y:g}=this.toAffine(),b=n.toBytes(g);return b[b.length-1]|=f&et?128:0,b}toHex(){return Ot(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new Re(m,o.BITS);return m.BASE.precompute(8),m}function Yi(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Wt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=e.randomBytes||Be,c=e.adjustScalarBytes||(I=>I),l=e.domain||((I,S,k)=>{if(Ut(k,"phflag"),S.length||k)throw new Error("Contexts/pre-hash are not supported");return I});function d(I){return i.create(ie(I))}function h(I){let S=b.secretKey;M(I,b.secretKey,"secretKey");let k=M(t(I),2*S,"hashedSecretKey"),K=c(k.slice(0,S)),R=k.slice(S,2*S),w=d(K);return{head:K,prefix:R,scalar:w}}function u(I){let{head:S,prefix:k,scalar:K}=h(I),R=o.multiply(K),w=R.toBytes();return{head:S,prefix:k,scalar:K,point:R,pointBytes:w}}function p(I){return u(I).pointBytes}function m(I=Uint8Array.of(),...S){let k=mt(...S);return d(t(l(k,M(I,void 0,"context"),!!n)))}function v(I,S,k={}){I=M(I,void 0,"message"),n&&(I=n(I));let{prefix:K,scalar:R,pointBytes:w}=u(S),E=m(k.context,K,I),y=o.multiply(E).toBytes(),A=m(k.context,y,w,I),L=i.create(E+A*R);if(!i.isValid(L))throw new Error("sign failed: invalid s");let D=mt(y,i.toBytes(L));return M(D,b.signature,"result")}let x={zip215:!0};function f(I,S,k,K=x){let{context:R,zip215:w}=K,E=b.signature;I=M(I,E,"signature"),S=M(S,void 0,"message"),k=M(k,b.publicKey,"publicKey"),w!==void 0&&Ut(w,"zip215"),n&&(S=n(S));let y=E/2,A=I.subarray(0,y),L=ie(I.subarray(y,E)),D,P,T;try{D=r.fromBytes(k,w),P=r.fromBytes(A,w),T=o.multiplyUnsafe(L)}catch{return!1}if(!w&&D.isSmallOrder())return!1;let O=m(R,P.toBytes(),D.toBytes(),S);return P.add(D.multiplyUnsafe(O)).subtract(T).clearCofactor().is0()}let g=s.BYTES,b={secretKey:g,publicKey:g,signature:2*g,seed:g};function _(I=a(b.seed)){return M(I,b.seed,"seed")}function B(I){return ne(I)&&I.length===i.BYTES}function C(I,S){try{return!!r.fromBytes(I,S)}catch{return!1}}let U={getExtendedPublicKey:u,randomSecretKey:_,isValidSecretKey:B,isValidPublicKey:C,toMontgomery(I){let{y:S}=r.fromBytes(I),k=b.publicKey,K=k===32;if(!K&&k!==57)throw new Error("only defined for 25519 and 448");let R=K?s.div(et+S,et-S):s.div(S-et,S+et);return s.toBytes(R)},toMontgomerySecret(I){let S=b.secretKey;M(I,S);let k=t(I.subarray(0,S));return c(k).subarray(0,S)}};return Object.freeze({keygen:qr(_,p),getPublicKey:p,sign:v,verify:f,utils:U,Point:r,lengths:b})}var Ju=BigInt(1),Xi=BigInt(2);var tf=BigInt(5),ef=BigInt(8),Ao=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),rf={p:Ao,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ef,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function nf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ao,a=r*r%s*r%s,c=H(a,Xi,s)*a%s,l=H(c,Ju,s)*r%s,d=H(l,tf,s)*l%s,h=H(d,t,s)*d%s,u=H(h,e,s)*h%s,p=H(u,n,s)*u%s,m=H(p,o,s)*p%s,v=H(m,o,s)*p%s,x=H(v,t,s)*d%s;return{pow_p_5_8:H(x,Xi,s)*r%s,b2:a}}function of(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Wi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function sf(r,t){let e=Ao,n=W(t*t*t,e),o=W(n*n*t,e),s=nf(r*o).pow_p_5_8,i=W(r*n*s,e),a=W(t*i*i,e),c=i,l=W(i*Wi,e),d=a===r,h=a===W(-r,e),u=a===W(-r*Wi,e);return d&&(i=c),(h||u)&&(i=l),Fi(i,e)&&(i=W(-i,e)),{isValid:d||h,value:i}}var af=Zi(rf,{uvRatio:sf});function cf(r){return Yi(af,Bi,Object.assign({adjustScalarBytes:of},r))}var Qi=cf({});var fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ji={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new zr("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 Vr=Ji;var Hr=32;var Bo,uf=(async()=>{try{return await Vr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ff(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Vr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Vr.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 lf(r,t,e){return Qi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function ta(r,t,e){return Bo==null&&(Bo=await uf),Bo?ff(r,t,e):lf(r,t,e)}function $r(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=Lo(t,Hr)}toMultihash(){return xt.digest(Ie(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=ta(this.raw,e,t);return $r(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ra(r){return r=Lo(r,Hr),new jr(r)}function Lo(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 hf=Math.pow(2,7),pf=Math.pow(2,14),mf=Math.pow(2,21),To=Math.pow(2,28),Do=Math.pow(2,35),Co=Math.pow(2,42),Ro=Math.pow(2,49),q=128,ct=127;function gt(r){if(r<hf)return 1;if(r<pf)return 2;if(r<mf)return 3;if(r<To)return 4;if(r<Do)return 5;if(r<Co)return 6;if(r<Ro)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|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function gf(r,t,e=0){switch(gt(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Po(r,t){let e=r[t],n=0;if(n+=e&ct,e<q||(e=r[t+1],n+=(e&ct)<<7,e<q)||(e=r[t+2],n+=(e&ct)<<14,e<q)||(e=r[t+3],n+=(e&ct)<<21,e<q)||(e=r[t+4],n+=(e&ct)*To,e<q)||(e=r[t+5],n+=(e&ct)*Do,e<q)||(e=r[t+6],n+=(e&ct)*Co,e<q)||(e=r[t+7],n+=(e&ct)*Ro,e<q))return n;throw new RangeError("Could not decode varint")}function bf(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<q||(e=r.get(t+1),n+=(e&ct)<<7,e<q)||(e=r.get(t+2),n+=(e&ct)<<14,e<q)||(e=r.get(t+3),n+=(e&ct)<<21,e<q)||(e=r.get(t+4),n+=(e&ct)*To,e<q)||(e=r.get(t+5),n+=(e&ct)*Do,e<q)||(e=r.get(t+6),n+=(e&ct)*Co,e<q)||(e=r.get(t+7),n+=(e&ct)*Ro,e<q))return n;throw new RangeError("Could not decode varint")}function na(r,t,e=0){return t==null&&(t=pt(gt(r))),t instanceof Uint8Array?Pe(r,t,e):gf(r,t,e)}function lr(r,t=0){return r instanceof Uint8Array?Po(r,t):bf(r,t)}var Oo=new Float32Array([-0]),Jt=new Uint8Array(Oo.buffer);function sa(r,t,e){Oo[0]=r,t[e]=Jt[0],t[e+1]=Jt[1],t[e+2]=Jt[2],t[e+3]=Jt[3]}function ia(r,t){return Jt[0]=r[t],Jt[1]=r[t+1],Jt[2]=r[t+2],Jt[3]=r[t+3],Oo[0]}var ko=new Float64Array([-0]),ut=new Uint8Array(ko.buffer);function aa(r,t,e){ko[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 ca(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],ko[0]}var yf=BigInt(Number.MAX_SAFE_INTEGER),xf=BigInt(Number.MIN_SAFE_INTEGER),yt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return fe;if(t<yf&&t>xf)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>ua&&(o=0n,++n>ua&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return fe;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):fe}},fe=new yt(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var ua=4294967296n;function fa(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 la(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 No(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function St(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Gr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Uo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,St(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw St(this,4);return Gr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw St(this,4);return Gr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw St(this,4);let t=ia(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw St(this,4);let t=ca(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw St(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return la(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw St(this,t);this.pos+=t}else do if(this.pos>=this.len)throw St(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new yt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw St(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw St(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw St(this,8);let t=Gr(this.buf,this.pos+=4),e=Gr(this.buf,this.pos+=4);return new yt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Po(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 Uo(r instanceof Uint8Array?r:r.subarray())}function Mt(r,t,e){let n=dr(r);return t.decode(n,void 0,e)}function Mo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return pt(i);o+i>t&&(n=pt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|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 Ko(){}var qo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},wf=Mo();function Ef(r){return globalThis.Buffer!=null?pt(r):wf(r)}var pr=class{len;head;tail;states;constructor(){this.len=0,this.head=new le(Ko,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 zo((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(Zr,10,yt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=yt.fromBigInt(t);return this._push(Zr,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=yt.fromBigInt(t).zzEncode();return this._push(Zr,e.length(),e)}sint64Number(t){let e=yt.fromNumber(t).zzEncode();return this._push(Zr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Fo,1,t?1:0)}fixed32(t){return this._push(hr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=yt.fromBigInt(t);return this._push(hr,4,e.lo)._push(hr,4,e.hi)}fixed64Number(t){let e=yt.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(sa,4,t)}double(t){return this._push(aa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Fo,1,0):this.uint32(e)._push(vf,e,t)}string(t){let e=fa(t);return e!==0?this.uint32(e)._push(No,e,t):this._push(Fo,1,0)}fork(){return this.states=new qo(this),this.head=this.tail=new le(Ko,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(Ko,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=Ef(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Fo(r,t,e){t[e]=r&255}function Sf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var zo=class extends le{next;constructor(t,e){super(Sf,t,e),this.next=void 0}};function Zr(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 vf(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(_f,t,r),this},pr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(If,t,r),this});function _f(r,t,e){t.set(r,e)}function If(r,t,e){r.length<40?No(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function Vo(){return new pr}function Kt(r,t){let e=Vo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*Ft(r,t,e){let n=dr(r);yield*t.stream(n,void 0,"$",e)}var Yr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Xr(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function Oe(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 Xr("enum",Yr.VARINT,e,n,o)}function qt(r,t,e){return Xr("message",Yr.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 Ho;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Ho||(Ho={}));(function(r){r.codec=()=>Oe(Ho)})(ht||(ht={}));var gr;(function(r){let t;r.codec=()=>(t==null&&(t=qt((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={},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=ht.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:ht.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Kt(s,r.codec())}r.encode=e;function n(s,i){return Mt(s,r.codec(),i)}r.decode=n;function o(s,i){return Ft(s,r.codec(),i)}r.stream=o})(gr||(gr={}));var $o;(function(r){let t;r.codec=()=>(t==null&&(t=qt((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={},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=ht.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:ht.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Kt(s,r.codec())}r.encode=e;function n(s,i){return Mt(s,r.codec(),i)}r.decode=n;function o(s,i){return Ft(s,r.codec(),i)}r.stream=o})($o||($o={}));var Wr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Or(t),M(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),Pt(o)}update(t){return Ae(this),this.iHash.update(t),this}digestInto(t){Ae(this),M(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},jo=(r,t,e)=>new Wr(r,t).update(e).digest();jo.create=(r,t)=>new Wr(r,t);var ha=(r,t)=>(r+(r>=0?t:-t)/pa)/t;function Bf(r,t,e){let[[n,o],[s,i]]=t,a=ha(i*r,e),c=ha(-o*r,e),l=r-a*n-c*s,d=-a*o-c*i,h=l<zt,u=d<zt;h&&(l=-l),u&&(d=-d);let p=ar(Math.ceil(go(e)/2))+ke;if(l<zt||l>=p||d<zt||d>=p)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:h,k1:l,k2neg:u,k2:d}}function Zo(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Go(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Ut(e.lowS,"lowS"),Ut(e.prehash,"prehash"),e.format!==void 0&&Zo(e.format),e}var Yo=class extends Error{constructor(t=""){super(t)}},te={Err:Yo,_tlv:{encode:(r,t)=>{let{Err:e}=te;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=sr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?sr(o.length/2|128):"";return sr(r)+s+o+t},decode(r,t){let{Err:e}=te,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of l)i=i<<8|d;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=te;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}=te;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 Le(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=te,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:l,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=te,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},zt=BigInt(0),ke=BigInt(1),pa=BigInt(2),Qr=BigInt(3),Lf=BigInt(4);function ma(r,t={}){let e=Fr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;Wt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=ba(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(R,w,E){let{x:y,y:A}=w.toAffine(),L=n.toBytes(y);if(Ut(E,"isCompressed"),E){d();let D=!n.isOdd(A);return mt(ga(D),L)}else return mt(Uint8Array.of(4),L,n.toBytes(A))}function u(R){M(R,void 0,"Point");let{publicKey:w,publicKeyUncompressed:E}=l,y=R.length,A=R[0],L=R.subarray(1);if(y===w&&(A===2||A===3)){let D=n.fromBytes(L);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let P=v(D),T;try{T=n.sqrt(P)}catch(j){let V=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}d();let O=n.isOdd(T);return(A&1)===1!==O&&(T=n.neg(T)),{x:D,y:T}}else if(y===E&&A===4){let D=n.BYTES,P=n.fromBytes(L.subarray(0,D)),T=n.fromBytes(L.subarray(D,D*2));if(!x(P,T))throw new Error("bad point: is not on curve");return{x:P,y:T}}else throw new Error(`bad point: got length ${y}, expected compressed=${w} or uncompressed=${E}`)}let p=t.toBytes||h,m=t.fromBytes||u;function v(R){let w=n.sqr(R),E=n.mul(w,R);return n.add(n.add(E,n.mul(R,s.a)),s.b)}function x(R,w){let E=n.sqr(w),y=v(R);return n.eql(E,y)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let f=n.mul(n.pow(s.a,Qr),Lf),g=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(f,g)))throw new Error("bad curve params: a or b");function b(R,w,E=!1){if(!n.isValid(w)||E&&n.is0(w))throw new Error(`bad point coordinate ${R}`);return w}function _(R){if(!(R instanceof S))throw new Error("Weierstrass Point expected")}function B(R){if(!c||!c.basises)throw new Error("no endo");return Bf(R,c.basises,o.ORDER)}let C=Te((R,w)=>{let{X:E,Y:y,Z:A}=R;if(n.eql(A,n.ONE))return{x:E,y};let L=R.is0();w==null&&(w=L?n.ONE:n.inv(A));let D=n.mul(E,w),P=n.mul(y,w),T=n.mul(A,w);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(T,n.ONE))throw new Error("invZ was invalid");return{x:D,y:P}}),U=Te(R=>{if(R.is0()){if(t.allowInfinityPoint&&!n.is0(R.Y))return;throw new Error("bad point: ZERO")}let{x:w,y:E}=R.toAffine();if(!n.isValid(w)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!x(w,E))throw new Error("bad point: equation left != right");if(!R.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function I(R,w,E,y,A){return E=new S(n.mul(E.X,R),E.Y,E.Z),w=ur(y,w),E=ur(A,E),w.add(E)}class S{static BASE=new S(s.Gx,s.Gy,n.ONE);static ZERO=new S(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(w,E,y){this.X=b("x",w),this.Y=b("y",E,!0),this.Z=b("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(w){let{x:E,y}=w||{};if(!w||!n.isValid(E)||!n.isValid(y))throw new Error("invalid affine point");if(w instanceof S)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(y)?S.ZERO:new S(E,y,n.ONE)}static fromBytes(w){let E=S.fromAffine(m(M(w,void 0,"point")));return E.assertValidity(),E}static fromHex(w){return S.fromBytes(kt(w))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,E=!0){return K.createCache(this,w),E||this.multiply(Qr),this}assertValidity(){U(this)}hasEvenY(){let{y:w}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(w)}equals(w){_(w);let{X:E,Y:y,Z:A}=this,{X:L,Y:D,Z:P}=w,T=n.eql(n.mul(E,P),n.mul(L,A)),O=n.eql(n.mul(y,P),n.mul(D,A));return T&&O}negate(){return new S(this.X,n.neg(this.Y),this.Z)}double(){let{a:w,b:E}=s,y=n.mul(E,Qr),{X:A,Y:L,Z:D}=this,P=n.ZERO,T=n.ZERO,O=n.ZERO,N=n.mul(A,A),j=n.mul(L,L),V=n.mul(D,D),F=n.mul(A,L);return F=n.add(F,F),O=n.mul(A,D),O=n.add(O,O),P=n.mul(w,O),T=n.mul(y,V),T=n.add(P,T),P=n.sub(j,T),T=n.add(j,T),T=n.mul(P,T),P=n.mul(F,P),O=n.mul(y,O),V=n.mul(w,V),F=n.sub(N,V),F=n.mul(w,F),F=n.add(F,O),O=n.add(N,N),N=n.add(O,N),N=n.add(N,V),N=n.mul(N,F),T=n.add(T,N),V=n.mul(L,D),V=n.add(V,V),N=n.mul(V,F),P=n.sub(P,N),O=n.mul(V,j),O=n.add(O,O),O=n.add(O,O),new S(P,T,O)}add(w){_(w);let{X:E,Y:y,Z:A}=this,{X:L,Y:D,Z:P}=w,T=n.ZERO,O=n.ZERO,N=n.ZERO,j=s.a,V=n.mul(s.b,Qr),F=n.mul(E,L),G=n.mul(y,D),nt=n.mul(A,P),It=n.add(E,y),Z=n.add(L,D);It=n.mul(It,Z),Z=n.add(F,G),It=n.sub(It,Z),Z=n.add(E,A);let it=n.add(L,P);return Z=n.mul(Z,it),it=n.add(F,nt),Z=n.sub(Z,it),it=n.add(y,A),T=n.add(D,P),it=n.mul(it,T),T=n.add(G,nt),it=n.sub(it,T),N=n.mul(j,Z),T=n.mul(V,nt),N=n.add(T,N),T=n.sub(G,N),N=n.add(G,N),O=n.mul(T,N),G=n.add(F,F),G=n.add(G,F),nt=n.mul(j,nt),Z=n.mul(V,Z),G=n.add(G,nt),nt=n.sub(F,nt),nt=n.mul(j,nt),Z=n.add(Z,nt),F=n.mul(G,Z),O=n.add(O,F),F=n.mul(it,Z),T=n.mul(It,T),T=n.sub(T,F),F=n.mul(It,G),N=n.mul(it,N),N=n.add(N,F),new S(T,O,N)}subtract(w){return this.add(w.negate())}is0(){return this.equals(S.ZERO)}multiply(w){let{endo:E}=t;if(!o.isValidNot0(w))throw new Error("invalid scalar: out of range");let y,A,L=D=>K.cached(this,D,P=>ue(S,P));if(E){let{k1neg:D,k1:P,k2neg:T,k2:O}=B(w),{p:N,f:j}=L(P),{p:V,f:F}=L(O);A=j.add(F),y=I(E.beta,N,V,D,T)}else{let{p:D,f:P}=L(w);y=D,A=P}return ue(S,[y,A])[0]}multiplyUnsafe(w){let{endo:E}=t,y=this;if(!o.isValid(w))throw new Error("invalid scalar: out of range");if(w===zt||y.is0())return S.ZERO;if(w===ke)return y;if(K.hasCache(this))return this.multiply(w);if(E){let{k1neg:A,k1:L,k2neg:D,k2:P}=B(w),{p1:T,p2:O}=Gi(S,y,L,P);return I(E.beta,T,O,A,D)}else return K.unsafe(y,w)}toAffine(w){return C(this,w)}isTorsionFree(){let{isTorsionFree:w}=t;return i===ke?!0:w?w(S,this):K.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:w}=t;return i===ke?this:w?w(S,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(w=!0){return Ut(w,"isCompressed"),this.assertValidity(),p(S,this,w)}toHex(w=!0){return Ot(this.toBytes(w))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let k=o.BITS,K=new Re(S,t.endo?Math.ceil(k/2):k);return S.BASE.precompute(8),S}function ga(r){return Uint8Array.of(r?2:3)}function ba(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Tf(r,t={}){let{Fn:e}=r,n=t.randomBytes||Be,o=Object.assign(ba(r.Fp,e),{seed:wo(e.ORDER)});function s(p){try{let m=e.fromBytes(p);return e.isValidNot0(m)}catch{return!1}}function i(p,m){let{publicKey:v,publicKeyUncompressed:x}=o;try{let f=p.length;return m===!0&&f!==v||m===!1&&f!==x?!1:!!r.fromBytes(p)}catch{return!1}}function a(p=n(o.seed)){return Eo(M(p,o.seed,"seed"),e.ORDER)}function c(p,m=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(m)}function l(p){let{secretKey:m,publicKey:v,publicKeyUncompressed:x}=o;if(!ne(p)||"_lengths"in e&&e._lengths||m===v)return;let f=M(p,void 0,"key").length;return f===v||f===x}function d(p,m,v=!0){if(l(p)===!0)throw new Error("first arg must be private key");if(l(m)===!1)throw new Error("second arg must be public key");let x=e.fromBytes(p);return r.fromBytes(m).multiply(x).toBytes(v)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},u=qr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:u,Point:r,utils:h,lengths:o})}function ya(r,t,e={}){Or(t),Wt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Be,o=e.hmac||((E,y)=>jo(t,E,y)),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:l,getPublicKey:d,getSharedSecret:h,utils:u,lengths:p}=Tf(r,e),m={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},v=a*pa<s.ORDER;function x(E){let y=a>>ke;return E>y}function f(E,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return y}function g(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function b(E,y){Zo(y);let A=p.signature,L=y==="compact"?A:y==="recovered"?A+1:void 0;return M(E,L)}class _{r;s;recovery;constructor(y,A,L){if(this.r=f("r",y),this.s=f("s",A),L!=null){if(g(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(y,A=m.format){b(y,A);let L;if(A==="der"){let{r:O,s:N}=te.toSig(M(y));return new _(O,N)}A==="recovered"&&(L=y[0],A="compact",y=y.subarray(1));let D=p.signature/2,P=y.subarray(0,D),T=y.subarray(D,D*2);return new _(i.fromBytes(P),i.fromBytes(T),L)}static fromHex(y,A){return this.fromBytes(kt(y),A)}assertRecovery(){let{recovery:y}=this;if(y==null)throw new Error("invalid recovery id: must be present");return y}addRecoveryBit(y){return new _(this.r,this.s,y)}recoverPublicKey(y){let{r:A,s:L}=this,D=this.assertRecovery(),P=D===2||D===3?A+a:A;if(!s.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let T=s.toBytes(P),O=r.fromBytes(mt(ga((D&1)===0),T)),N=i.inv(P),j=C(M(y,void 0,"msgHash")),V=i.create(-j*N),F=i.create(L*N),G=r.BASE.multiplyUnsafe(V).add(O.multiplyUnsafe(F));if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return x(this.s)}toBytes(y=m.format){if(Zo(y),y==="der")return kt(te.hexFromSig(this));let{r:A,s:L}=this,D=i.toBytes(A),P=i.toBytes(L);return y==="recovered"?(g(),mt(Uint8Array.of(this.assertRecovery()),D,P)):mt(D,P)}toHex(y){return Ot(this.toBytes(y))}}let B=e.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let A=Le(y),L=y.length*8-c;return L>0?A>>BigInt(L):A},C=e.bits2int_modN||function(y){return i.create(B(y))},U=ar(c);function I(E){return ir("num < 2^"+c,E,zt,U),i.toBytes(E)}function S(E,y){return M(E,void 0,"message"),y?M(t(E),void 0,"prehashed message"):E}function k(E,y,A){let{lowS:L,prehash:D,extraEntropy:P}=Go(A,m);E=S(E,D);let T=C(E),O=i.fromBytes(y);if(!i.isValidNot0(O))throw new Error("invalid private key");let N=[I(O),I(T)];if(P!=null&&P!==!1){let G=P===!0?n(p.secretKey):P;N.push(M(G,void 0,"extraEntropy"))}let j=mt(...N),V=T;function F(G){let nt=B(G);if(!i.isValidNot0(nt))return;let It=i.inv(nt),Z=r.BASE.multiply(nt).toAffine(),it=i.create(Z.x);if(it===zt)return;let Ir=i.create(It*i.create(V+it*O));if(Ir===zt)return;let Cs=(Z.x===it?0:2)|Number(Z.y&ke),Rs=Ir;return L&&x(Ir)&&(Rs=i.neg(Ir),Cs^=1),new _(it,Rs,v?void 0:Cs)}return{seed:j,k2sig:F}}function K(E,y,A={}){let{seed:L,k2sig:D}=k(E,y,A);return Di(t.outputLen,i.BYTES,o)(L,D).toBytes(A.format)}function R(E,y,A,L={}){let{lowS:D,prehash:P,format:T}=Go(L,m);if(A=M(A,void 0,"publicKey"),y=S(y,P),!ne(E)){let O=E instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}b(E,T);try{let O=_.fromBytes(E,T),N=r.fromBytes(A);if(D&&O.hasHighS())return!1;let{r:j,s:V}=O,F=C(y),G=i.inv(V),nt=i.create(F*G),It=i.create(j*G),Z=r.BASE.multiplyUnsafe(nt).add(N.multiplyUnsafe(It));return Z.is0()?!1:i.create(Z.x)===j}catch{return!1}}function w(E,y,A={}){let{prehash:L}=Go(A,m);return y=S(y,L),_.fromBytes(E,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:l,getPublicKey:d,getSharedSecret:h,utils:u,lengths:p,Point:r,sign:K,verify:R,recoverPublicKey:w,Signature:_,hash:t})}var Wo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Df={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var xa=BigInt(2);function Cf(r){let t=Wo.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,d=l*l*r%t,h=H(d,e,t)*d%t,u=H(h,e,t)*d%t,p=H(u,xa,t)*l%t,m=H(p,o,t)*p%t,v=H(m,s,t)*m%t,x=H(v,a,t)*v%t,f=H(x,c,t)*x%t,g=H(f,a,t)*v%t,b=H(g,e,t)*d%t,_=H(b,i,t)*m%t,B=H(_,n,t)*l%t,C=H(B,xa,t);if(!Xo.eql(Xo.sqr(C),r))throw new Error("Cannot find square root");return C}var Xo=De(Wo.p,{sqrt:Cf}),Rf=ma(Wo,{Fp:Xo,endo:Df}),Ne=ya(Rf,Ai);function wa(r,t,e,n){let o=Qe.digest(e instanceof Uint8Array?e:e.subarray());if($r(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ne.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new fr(String(s))});try{return n?.signal?.throwIfAborted(),Ne.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new fr(String(s))}}var Jr=class{type="secp256k1";raw;_key;constructor(t){this._key=Sa(t),this.raw=Ea(this._key)}toMultihash(){return xt.digest(Ie(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 wa(this._key,e,t,n)}};function va(r){return new Jr(r)}function Ea(r){return Ne.Point.fromBytes(r).toBytes()}function Sa(r){try{return Ne.Point.fromBytes(r),r}catch(t){throw new Br(String(t))}}function _a(r){let{Type:t,Data:e}=gr.decode(r.digest),n=e??new Uint8Array;switch(t){case ht.Ed25519:return ra(n);case ht.secp256k1:return va(n);case ht.ECDSA:return ui(n);default:throw new Ge}}function Ie(r){return gr.encode({Type:ht[r.type],Data:r.raw})}var Ia=Symbol.for("nodejs.util.inspect.custom"),Pf=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()})`}[Tn]=!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(Pf,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")}[Ia](){return`PeerId(${this.toString()})`}},tn=class extends br{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},en=class extends br{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},rn=class extends br{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Of=2336,nn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=xt.digest($(this.url))}[Ia](){return`PeerId(${this.url})`}[Tn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Of,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Q(t)),t.toString()===this.toString())}};function on(r){if(Nf(r))return new tn({multihash:r});if(kf(r))try{let t=_a(r);if(t.type==="Ed25519")return new en({multihash:r,publicKey:t});if(t.type==="secp256k1")return new rn({multihash:r,publicKey:t})}catch{let e=Q(r.digest);return new nn(new URL(e))}throw new Lr("Supplied PeerID Multihash is invalid")}function kf(r){return r.code===xt.code}function Nf(r){return r.code===Qe.code}function Qo(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function sn(r){let t=re(X.decode(`z${r}`));return on(t)}var an=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Qo(this.set.entries(),t=>{let e=sn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=sn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Qo(this.set.values(),t=>sn(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Jo(){return new an}var ts={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Aa={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ba=new globalThis.TextEncoder;function Uf(r,t){let e=ts[t],n=Aa[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Mf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=ts[t],o=Aa[t],s=r;for(;s.length>0;){let i=Ba.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 es(r,{size:t=32,utf8Buffer:e}={}){if(!ts[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 Mf(r,t,e);r=Ba.encode(r)}return Uf(r,t)}var yr={hash:r=>Number(es(r,{size:32})),hashV:(r,t)=>Kf(yr.hash(r,t))};function Kf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),$(t,"base16")}var rs=64,vt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>rs)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=wt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?lt(this.fp,t.fp):!1}};function de(r,t){return Math.floor(Math.random()*(t-r))+r}var he=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");let e=de(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Ff=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??de(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=$(t));let e=new vt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new he(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new he(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[de(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new he(this.bucketSize));for(let a=0;a<Ff;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new he(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=$(t));let e=new vt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=$(t));let e=new vt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},qf={1:.5,2:.84,4:.95,8:.98};function zf(r=.001){return r>.002?2:r>1e-5?4:8}function La(r,t=.001){let e=zf(t),n=qf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),rs);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var cn=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??yr,this.seed=t.seed??de(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=$(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=$(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=$(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function ns(r,t=.001,e){return new cn({...La(r,t),...e??{}})}function _t(r){let t=r.getComponents(),e={},n=0;if(t[n]?.name==="ip6zone"&&(e.zone=`${t[n].value}`,n++),t[n].name==="ip4"||t[n].name==="ip6"||t[n].name==="dns"||t[n].name==="dns4"||t[n].name==="dns6"?(e.type=t[n].name,e.host=t[n].value,n++):t[n].name==="dnsaddr"&&(e.type=t[n].name,e.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(e.protocol=t[n].name==="tcp"?"tcp":"udp",e.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(e.type==="ip4"?e.cidr=parseInt(`${t[n].value}`):e.type==="ip6"&&(e.cidr=`${t[n].value}`),n++),e.type==null||e.host==null)throw new ft(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e}var un=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let u=Number.parseInt(h,t);if(!Number.isNaN(u))return u});if(d===void 0)break;if(s*=t,s+=d,s>l||(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 Ta=45,Vf=15,Ue=new un;function fn(r){if(!(r.length>Vf))return Ue.new(r).parseWith(()=>Ue.readIPv4Addr())}function ln(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ta))return Ue.new(r).parseWith(()=>Ue.readIPv6Addr())}function Me(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Ta)return;let e=Ue.new(r).parseWith(()=>Ue.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 Da(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 Ca(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 os(r){switch(r.length){case pe:return r.join(".");case me:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Ra(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 Pa(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var pe=4,me=16,Qg=parseInt("0xFFFF",16),Hf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function wr(r,t){t.length===me&&r.length===pe&&Da(t,0,11)&&(t=t.slice(12)),t.length===pe&&r.length===me&&Ca(r,Hf,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 Oa(r,t){if(typeof t=="string"&&(t=Me(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 ss(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=pe,o=fn(t);if(o==null&&(n=me,o=ln(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=is(s,8*n);return{network:wr(o,i),mask:i}}function is(r,t){if(t!==8*pe&&t!==8*me)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var Er=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=ss(t));else{let n=Me(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=Me(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=is(o,8*n.length);this.network=wr(n,this.mask)}}contains(t){return Oa({network:this.network,mask:this.mask},t)}toString(){let t=Ra(this.mask),e=t!==-1?String(t):Pa(this.mask);return os(this.network)+"/"+e}};function ka(r,t){return new Er(r).contains(t)}function Na(r){try{let t=_t(r);switch(t.type){case"ip6":return ka("2000::/3",t.host);default:return!1}}catch{return!1}}function Ke(r){return!!fn(r)}function dn(r){return!!ln(r)}var Fa=hc(Ka(),1),Wf=["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"],Qf=Wf.map(r=>new Fa.Netmask(r));function hs(r){for(let t of Qf)if(t.contains(r))return!0;return!1}function Jf(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function tl(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return hs(o)}function el(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function rl(r){let t=r.split(":"),e=t[t.length-1];return hs(e)}function nl(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 qa(r){if(Ke(r))return hs(r);if(Jf(r))return tl(r);if(el(r))return rl(r);if(dn(r))return nl(r)}function ps(r){try{let t=_t(r);switch(t.type){case"ip4":case"ip6":return qa(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function Ve(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var pn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},He=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new pn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new pn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var ms=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function mn(r={}){return ol(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 ol(r,t){t=t??{};let e=t.onEnd,n=new He,o,s,i,a=Ve(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,f)=>{s=g=>{s=null,n.push(g);try{x(r(n))}catch(b){f(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ve()})}},l=x=>s!=null?s(x):(n.push(x),o),d=x=>(n=new He,s!=null?s({error:x}):(n.push({error:x}),o)),h=x=>{if(i)return o;if(t?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:x})},u=x=>i?o:(i=!0,x!=null?d(x):l({done:!0})),p=()=>(n=new He,u(),{done:!0}),m=x=>(u(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:m,push:h,end:u,get readableLength(){return n.size},onEmpty:async x=>{let f=x?.signal;if(f?.throwIfAborted(),n.isEmpty())return;let g,b;f!=null&&(g=new Promise((_,B)=>{b=()=>{B(new ms)},f.addEventListener("abort",b)}));try{await Promise.race([a.promise,g])}finally{b!=null&&f!=null&&f?.removeEventListener("abort",b)}}},e==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(x){return v.throw(x),e!=null&&(e(x),e=void 0),{done:!0}},return(){return v.return(),e!=null&&(e(),e=void 0),{done:!0}},push:h,end(x){return v.end(x),e!=null&&(e(x),e=void 0),o},get readableLength(){return v.readableLength},onEmpty:x=>v.onEmpty(x)},o}var gs=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},za=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function bs(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,d=new Promise((h,u)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){u(za(i));return}if(i&&(c=()=>{u(za(i))},i.addEventListener("abort",c,{once:!0})),r.then(h,u),e===Number.POSITIVE_INFINITY)return;let p=new gs;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(m){u(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?u(o):(p.message=o??`Promise timed out after ${e} milliseconds`,u(p))},e)}).finally(()=>{d.clear(),c&&i&&i.removeEventListener("abort",c)});return d.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},d}var sl=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 il(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:l,removeListener:d}=sl(r),h=async(...p)=>{let m=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(m))return}catch(v){n(),i(v);return}c.push(m),e.count===c.length&&(n(),s(c))},u=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)d(p,h);for(let p of e.rejectionEvents)a.includes(p)||d(p,u)};for(let p of a)l(p,h);for(let p of e.rejectionEvents)a.includes(p)||l(p,u);e.signal&&e.signal.addEventListener("abort",()=>{u(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=bs(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function $e(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=il(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Sr(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var gn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},be=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function al(r){return r.reason}async function vr(r,t,e){if(t==null)return r;let n=e?.translateError??al;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 bn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Ve(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Tt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function cl(){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=cl(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Tt),this.cleanup())}async join(t={}){let e=new bn(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 vr(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 xn=class extends Tr{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=Sr(this.emitEmpty.bind(this),1),this.emitIdle=Sr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new gn;let n=new yn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Tt)}),this.clear()}async onEmpty(t){this.size!==0&&await $e(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await $e(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await $e(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=mn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Tt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function wn(r){let t=new globalThis.AbortController;function e(){let s=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}var st=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Vt=class extends Error{static name="ValidationError";name="ValidationError"},En=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Sn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function xs(r){return t=>Q(t,r)}function ws(r){return t=>$(t,r)}function je(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 Va(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=$(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ye(n);return Ct([e,o],e.length+o.length)}function Ha(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=jt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ye(n);return Ct([e,o],e.length+o.length)}function Es(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=Q(t,"base32"),o=je(e);return`${n}:${o}`}var Ss=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new st("Invalid byte value in IP address");t[n]=o}),t},$a=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Ke(e[n]),i;s&&(i=Ss(e[n]),e[n]=Q(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,Q(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new st("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},ja=function(r){if(r.byteLength!==4)throw new st("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Ga=function(r){if(r.byteLength!==16)throw new st("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${e}"`)}};function Za(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${r}"`)}}var ys=Object.values(Je).map(r=>r.decoder),ul=(function(){let r=ys[0].or(ys[1]);return ys.slice(2).forEach(t=>r=r.or(t)),r})();function Ya(r){return ul.decode(r)}function Xa(r){return t=>r.encoder.encode(t)}function fl(r){if(parseInt(r).toString()!==r)throw new Vt("Value must be an integer")}function ll(r){if(r<0)throw new Vt("Value must be a positive integer, or zero")}function dl(r){return t=>{if(t>r)throw new Vt(`Value must be smaller than or equal to ${r}`)}}function hl(...r){return t=>{for(let e of r)e(t)}}var _r=hl(fl,ll,dl(65535));var rt=-1,vs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new Sn(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Ht=new vs,Jl=[{code:4,name:"ip4",size:32,valueToBytes:Ss,bytesToValue:ja,validate:r=>{if(!Ke(r))throw new Vt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ye,bytesToValue:je,validate:_r},{code:273,name:"udp",size:16,valueToBytes:ye,bytesToValue:je,validate:_r},{code:33,name:"dccp",size:16,valueToBytes:ye,bytesToValue:je,validate:_r},{code:41,name:"ip6",size:128,valueToBytes:$a,bytesToValue:Ga,stringToValue:Za,validate:r=>{if(!dn(r))throw new Vt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:rt},{code:43,name:"ipcidr",size:8,bytesToValue:xs("base10"),valueToBytes:ws("base10")},{code:53,name:"dns",size:rt},{code:54,name:"dns4",size:rt},{code:55,name:"dns6",size:rt},{code:56,name:"dnsaddr",size:rt},{code:132,name:"sctp",size:16,valueToBytes:ye,bytesToValue:je,validate:_r},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:rt,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:rt,bytesToValue: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:Va},{code:445,name:"onion3",size:296,bytesToValue:Es,valueToBytes:Ha},{code:446,name:"garlic64",size:rt},{code:447,name:"garlic32",size:rt},{code:448,name:"tls"},{code:449,name:"sni",size:rt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:rt,bytesToValue:Xa(Hn),valueToBytes:Ya},{code:480,name:"http"},{code:481,name:"http-path",size:rt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:rt}];Jl.forEach(r=>{Ht.addProtocol(r)});function Wa(r){let t=[],e=0;for(;e<r.length;){let n=lr(r,e),o=Ht.getProtocol(n),s=gt(n),i=td(o,r,e+s),a=0;i>0&&o.size===rt&&(a=gt(i));let c=s+a+i,l={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let d=e+s+a,h=r.subarray(d,d+i);l.value=o.bytesToValue?.(h)??Q(h)}t.push(l),e+=c}return t}function Qa(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Ht.getProtocol(n.code),s=gt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??$(n.value),a=i.byteLength,o.size===rt&&(c=gt(a)));let l=new Uint8Array(s+c+a),d=0;Pe(n.code,l,d),d+=s,i!=null&&(o.size===rt&&(Pe(a,l,d),d+=c),l.set(i,d)),n.bytes=l}e.push(n.bytes),t+=n.bytes.byteLength}return Ct(e,t)}function Ja(r){if(r.charAt(0)!=="/")throw new st('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=Ht.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 st(`Component ${o} was missing value`);e="value"}else if(e==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new st(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}t.push(l),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new st("Incomplete multiaddr");return t}function tc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Ht.getProtocol(t.code);if(e==null)throw new st(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function td(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:lr(t,e)}var ed=Symbol.for("nodejs.util.inspect.custom"),_s=Symbol.for("@multiformats/multiaddr");function rd(r){if(r==null&&(r="/"),ec(r))return r.getComponents();if(r instanceof Uint8Array)return Wa(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Ja(r);if(Array.isArray(r))return r;throw new st("Must be a string, Uint8Array, Component[], or another Multiaddr")}var _n=class r{[_s]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=rd(t),e.validate!==!1&&nd(this)}get bytes(){return this.#r==null&&(this.#r=Qa(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=tc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new En(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return lt(this.bytes,t.bytes)}[ed](){return`Multiaddr(${this.toString()})`}};function nd(r){r.getComponents().forEach(t=>{let e=Ht.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function ec(r){return!!r?.[_s]}function rc(r){return new _n(r)}var od=4194304,In=class extends Error{static name="UnwrappedError";name="UnwrappedError"},As=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Bs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ls=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function sd(r){return typeof r?.closeRead=="function"}function id(r){return typeof r?.close=="function"}function Is(r){return sd(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:id(r)?r.status!=="open":!1}function ad(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function cd(r,t){let e=t?.maxBufferSize??od,n=new J,o,s=!1;if(!ad(r))throw new ft("Argument should be a Stream or a Multiaddr");let i=d=>{if(n.append(d.data),n.byteLength>e){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let a=d=>{d.error!=null?o?.reject(d.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let l={readBuffer:n,async read(d){if(s===!0)throw new In("Stream was unwrapped");if(Is(r)){if(n.byteLength===0&&d?.bytes==null)return null;if(d?.bytes!=null&&n.byteLength<d.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new be(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let h=d?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await vr(o.promise,d?.signal),Is(r)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let u=d?.bytes??n.byteLength;if(n.byteLength<u){if(Is(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,u),new be(`Unexpected EOF - stream closed while reading ${n.byteLength}/${u} bytes`);return l.read(d)}let p=n.sublist(0,u);return n.consume(u),p},async write(d,h){if(s===!0)throw new In("Stream was unwrapped");r.send(d)||await $e(r,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return l}function ud(r,t={}){let e=cd(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=gt(t.maxDataLength));let n=t?.lengthDecoder??lr,o=t?.lengthEncoder??na;return{async read(i){let a=-1,c=new J;for(;;){let d=await e.read({...i,bytes:1});if(d==null)break;c.append(d);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new As("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ls(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Bs(`Message length too long - ${a} > ${t.maxDataLength}`);let l=await e.read({...i,bytes:a});if(l==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(l.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",l.byteLength,a),new be(`Unexpected EOF - read ${l.byteLength}/${a} bytes before the stream closed`);return l},async write(i,a){await e.write(new J(o(i.byteLength),i),a)},async writeV(i,a){let c=new J(...i.flatMap(l=>[o(l.byteLength),l]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function Ts(r,t){let e=ud(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var An=class extends xn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function nc(r,t,e){let n,o,s=!1;function i(){let l={signal:o.signal},d;e?.timeout!=null&&(d=wn([o.signal,AbortSignal.timeout(e.timeout)]),l.signal=d),s=!0,Promise.resolve().then(async()=>{await r(l)}).catch(()=>{}).finally(()=>{d!=null&&(d.aborted?d.clear():d.addEventListener("abort",()=>{d.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Sr(i,e?.debounce??100),c=!1;return{setInterval:l=>{t!==l&&(t=l,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:l=>{e??={},e.timeout=l},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 Ds=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 oc(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ds({name:t,metrics:e}):n=new Map,n}var sc="libp2p",ic="autonat",ac="1.0.0";var z;(function(r){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),(function(u){u.codec=()=>Oe(e)})(t=r.MessageType||(r.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(u){u.codec=()=>Oe(o)})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let p;u.codec=()=>(p==null&&(p=qt((f,g,b={})=>{if(b.lengthDelimited!==!1&&g.fork(),f.id!=null&&(g.uint32(10),g.bytes(f.id)),f.addrs!=null&&f.addrs.length>0)for(let _ of f.addrs)g.uint32(18),g.bytes(_);b.lengthDelimited!==!1&&g.ldelim()},(f,g,b={})=>{let _={addrs:[]},B=g==null?f.len:f.pos+g;for(;f.pos<B;){let C=f.uint32();switch(C>>>3){case 1:{_.id=f.bytes();break}case 2:{if(b.limits?.addrs!=null&&_.addrs.length===b.limits.addrs)throw new mr('Decode error - repeated field "addrs" had too many elements');_.addrs.push(f.bytes());break}default:{f.skipType(C&7);break}}}return _},function*(f,g,b,_={}){let B={addrs:0},C=g==null?f.len:f.pos+g;for(;f.pos<C;){let U=f.uint32();switch(U>>>3){case 1:{yield{field:`${b}.id`,value:f.bytes()};break}case 2:{if(_.limits?.addrs!=null&&B.addrs===_.limits.addrs)throw new mr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${b}.addrs[]`,index:B.addrs,value:f.bytes()},B.addrs++;break}default:{f.skipType(U&7);break}}}})),p);function m(f){return Kt(f,u.codec())}u.encode=m;function v(f,g){return Mt(f,u.codec(),g)}u.decode=v;function x(f,g){return Ft(f,u.codec(),g)}u.stream=x})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let p;u.codec=()=>(p==null&&(p=qt((f,g,b={})=>{b.lengthDelimited!==!1&&g.fork(),f.peer!=null&&(g.uint32(10),r.PeerInfo.codec().encode(f.peer,g)),b.lengthDelimited!==!1&&g.ldelim()},(f,g,b={})=>{let _={},B=g==null?f.len:f.pos+g;for(;f.pos<B;){let C=f.uint32();switch(C>>>3){case 1:{_.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:b.limits?.peer});break}default:{f.skipType(C&7);break}}}return _},function*(f,g,b,_={}){let B=g==null?f.len:f.pos+g;for(;f.pos<B;){let C=f.uint32();switch(C>>>3){case 1:{yield*r.PeerInfo.codec().stream(f,f.uint32(),`${b}.peer`,{limits:_.limits?.peer});break}default:{f.skipType(C&7);break}}}})),p);function m(f){return Kt(f,u.codec())}u.encode=m;function v(f,g){return Mt(f,u.codec(),g)}u.decode=v;function x(f,g){return Ft(f,u.codec(),g)}u.stream=x})(i=r.Dial||(r.Dial={}));let a;(function(u){let p;u.codec=()=>(p==null&&(p=qt((f,g,b={})=>{b.lengthDelimited!==!1&&g.fork(),f.status!=null&&(g.uint32(8),r.ResponseStatus.codec().encode(f.status,g)),f.statusText!=null&&(g.uint32(18),g.string(f.statusText)),f.addr!=null&&(g.uint32(26),g.bytes(f.addr)),b.lengthDelimited!==!1&&g.ldelim()},(f,g,b={})=>{let _={},B=g==null?f.len:f.pos+g;for(;f.pos<B;){let C=f.uint32();switch(C>>>3){case 1:{_.status=r.ResponseStatus.codec().decode(f);break}case 2:{_.statusText=f.string();break}case 3:{_.addr=f.bytes();break}default:{f.skipType(C&7);break}}}return _},function*(f,g,b,_={}){let B=g==null?f.len:f.pos+g;for(;f.pos<B;){let C=f.uint32();switch(C>>>3){case 1:{yield{field:`${b}.status`,value:r.ResponseStatus.codec().decode(f)};break}case 2:{yield{field:`${b}.statusText`,value:f.string()};break}case 3:{yield{field:`${b}.addr`,value:f.bytes()};break}default:{f.skipType(C&7);break}}}})),p);function m(f){return Kt(f,u.codec())}u.encode=m;function v(f,g){return Mt(f,u.codec(),g)}u.decode=v;function x(f,g){return Ft(f,u.codec(),g)}u.stream=x})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=qt((u,p,m={})=>{m.lengthDelimited!==!1&&p.fork(),u.type!=null&&(p.uint32(8),r.MessageType.codec().encode(u.type,p)),u.dial!=null&&(p.uint32(18),r.Dial.codec().encode(u.dial,p)),u.dialResponse!=null&&(p.uint32(26),r.DialResponse.codec().encode(u.dialResponse,p)),m.lengthDelimited!==!1&&p.ldelim()},(u,p,m={})=>{let v={},x=p==null?u.len:u.pos+p;for(;u.pos<x;){let f=u.uint32();switch(f>>>3){case 1:{v.type=r.MessageType.codec().decode(u);break}case 2:{v.dial=r.Dial.codec().decode(u,u.uint32(),{limits:m.limits?.dial});break}case 3:{v.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:m.limits?.dialResponse});break}default:{u.skipType(f&7);break}}}return v},function*(u,p,m,v={}){let x=p==null?u.len:u.pos+p;for(;u.pos<x;){let f=u.uint32();switch(f>>>3){case 1:{yield{field:`${m}.type`,value:r.MessageType.codec().decode(u)};break}case 2:{yield*r.Dial.codec().stream(u,u.uint32(),`${m}.dial`,{limits:v.limits?.dial});break}case 3:{yield*r.DialResponse.codec().stream(u,u.uint32(),`${m}.dialResponse`,{limits:v.limits?.dialResponse});break}default:{u.skipType(f&7);break}}}})),c);function l(u){return Kt(u,r.codec())}r.encode=l;function d(u,p){return Mt(u,r.codec(),p)}r.decode=d;function h(u,p){return Ft(u,r.codec(),p)}r.stream=h})(z||(z={}));var md=4,gd=8,Bn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${e.protocolPrefix??sc}/${ic}/${ac}`,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=oc({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=nc(this.findRandomPeers.bind(this),6e4),this.addressFilter=ns(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Os]=["@libp2p/autonat"];get[ks](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,e)=>{this.handleIncomingAutonatStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=wn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,e){let n=AbortSignal.timeout(this.timeout);try{let o=Ts(t,{maxDataLength:this.maxMessageSize}).pb(z),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,e,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(h=>_t(h).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("peerId missing from message"),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let h=re(a.id);i=on(h)}catch(h){return this.log.error("invalid PeerId - %e",h),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(h=>rc(h)).filter(h=>{try{let u=_t(h);return ps(h)?!1:u.host!==_t(e.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",h,e.remoteAddr),!1):o.includes(u.host)?!1:this.components.transportManager.dialTransportForMultiaddr(h)==null?(this.log.trace("not dialing %a - transport unsupported",h),!1):!0}catch{return!1}}).map(h=>(h.getComponents().find(u=>u.code===421)?.value==null&&(h=h.encapsulate(`/p2p/${i.toString()}`)),h));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(h=>h.toString()).join(", "),i);let l="",d=c[0];for(let h of c){let u;d=h;try{if(u=await this.components.connectionManager.openConnection(h,n),!u.remoteAddr.equals(h))throw this.log.error("tried to dial %a but dialed %a",h,u.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,h),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.OK,addr:u.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),l=p.message}finally{u!=null&&await u.close()}}return{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_DIAL_ERROR,statusText:l,addr:d.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||_t(o.multiaddr).type==="ip6"&&(!e||!Na(o.multiaddr))||ps(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:Jo(),queue:new An({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>_t(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=Ts(i).pb(z),[,c]=await Promise.all([a.write({type:z.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==z.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let l=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,l),l!==z.ResponseStatus.OK&&l!==z.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),l===z.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else l===z.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===md&&this.confirmAddress(o),o.failure===gd&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=_t(t);switch(e.type){case"ip4":return e.host.split(".")[0].padStart(3,"0");case"ip6":return e.host.split(":")[0].padStart(4,"0");default:throw new ft(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function bd(r={}){return t=>new Bn(t,r)}return pc(yd);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/utils.js:
|