@libp2p/autonat 2.0.37 → 2.0.38-a02cb0461
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/dist/src/autonat.d.ts +2 -2
- package/dist/src/autonat.d.ts.map +1 -1
- package/dist/src/autonat.js +37 -36
- package/dist/src/autonat.js.map +1 -1
- package/package.json +17 -19
- package/src/autonat.ts +41 -42
- 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 Xa=Object.create;var Sr=Object.defineProperty;var Qa=Object.getOwnPropertyDescriptor;var Ja=Object.getOwnPropertyNames;var tc=Object.getPrototypeOf,ec=Object.prototype.hasOwnProperty;var rc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)Sr(r,e,{get:t[e],enumerable:!0})},ws=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ja(t))!ec.call(r,o)&&o!==e&&Sr(r,o,{get:()=>t[o],enumerable:!(n=Qa(t,o))||n.enumerable});return r};var nc=(r,t,e)=>(e=r!=null?Xa(tc(r)):{},ws(t||!r||!r.__esModule?Sr(e,"default",{value:r,enumerable:!0}):e,r)),oc=r=>ws(Sr({},"__esModule",{value:!0}),r);var Ma=rc(Er=>{(function(){var r,t,e,n,o,s,i,a;a=function(u){var c,l,f,h;return c=(u&255<<24)>>>24,l=(u&255<<16)>>>16,f=(u&65280)>>>8,h=u&255,[c,l,f,h].join(".")},i=function(u){var c,l,f,h,m,b;for(c=[],f=h=0;h<=3&&u.length!==0;f=++h){if(f>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}b=t(u),m=b[0],l=b[1],u=u.substring(l),c.push(m)}if(u.length!==0)throw new Error("Invalid IP");switch(c.length){case 1:if(c[0]>4294967295)throw new Error("Invalid IP");return c[0]>>>0;case 2:if(c[0]>255||c[1]>16777215)throw new Error("Invalid IP");return(c[0]<<24|c[1])>>>0;case 3:if(c[0]>255||c[1]>255||c[2]>65535)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2])>>>0;case 4:if(c[0]>255||c[1]>255||c[2]>255||c[3]>255)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2]<<8|c[3])>>>0;default:throw new Error("Invalid IP")}},e=function(u){return u.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(u){var c,l,f,h,m;for(h=0,c=10,l="9",f=0,u.length>1&&u[f]==="0"&&(u[f+1]==="x"||u[f+1]==="X"?(f+=2,c=16):"0"<=u[f+1]&&u[f+1]<="9"&&(f++,c=8,l="7")),m=f;f<u.length;){if("0"<=u[f]&&u[f]<=l)h=h*c+(e(u[f])-n)>>>0;else if(c===16)if("a"<=u[f]&&u[f]<="f")h=h*c+(10+e(u[f])-s)>>>0;else if("A"<=u[f]&&u[f]<="F")h=h*c+(10+e(u[f])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===m)throw new Error("empty octet");return[h,f]},r=function(){function u(c,l){var f,h,m,b;if(typeof c!="string")throw new Error("Missing `net' parameter");if(l||(b=c.split("/",2),c=b[0],l=b[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(w){throw f=w,new Error("Invalid mask: "+l)}for(h=m=32;m>=0;h=--m)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(c)&this.maskLong)>>>0}catch(w){throw f=w,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return u.prototype.contains=function(c){return typeof c=="string"&&(c.indexOf("/")>0||c.split(".").length!==4)&&(c=new u(c)),c instanceof u?this.contains(c.base)&&this.contains(c.broadcast||c.last):(i(c)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},u.prototype.next=function(c){return c==null&&(c=1),new u(a(this.netLong+this.size*c),this.mask)},u.prototype.forEach=function(c){var l,f,h;for(h=i(this.first),f=i(this.last),l=0;h<=f;)c(a(h),h,l),l++,h++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u}(),Er.ip2long=i,Er.long2ip=a,Er.Netmask=r}).call(Er)});var jl={};dt(jl,{autoNAT:()=>Vl});var Ln=Symbol.for("@libp2p/peer-id");var Bt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Tt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},vr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ar=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var He=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ir=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"),_s=Symbol.for("@libp2p/service-dependencies");var kn={};dt(kn,{base58btc:()=>V,base58flickr:()=>lc});var yh=new Uint8Array(0);function Ss(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 vs(r){return new TextEncoder().encode(r)}function As(r){return new TextDecoder().decode(r)}function sc(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,u=r.charAt(0),c=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var w=0,d=0,S=0,T=b.length;S!==T&&b[S]===0;)S++,w++;for(var v=(T-S)*l+1>>>0,P=new Uint8Array(v);S!==T;){for(var y=b[S],L=0,C=v-1;(y!==0||L<d)&&C!==-1;C--,L++)y+=256*P[C]>>>0,P[C]=y%a>>>0,y=y/a>>>0;if(y!==0)throw new Error("Non-zero carry");d=L,S++}for(var I=v-d;I!==v&&P[I]===0;)I++;for(var p=u.repeat(w);I<v;++I)p+=r.charAt(P[I]);return p}function h(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var w=0;if(b[w]!==" "){for(var d=0,S=0;b[w]===u;)d++,w++;for(var T=(b.length-w)*c+1>>>0,v=new Uint8Array(T);b[w];){var P=e[b.charCodeAt(w)];if(P===255)return;for(var y=0,L=T-1;(P!==0||y<S)&&L!==-1;L--,y++)P+=a*v[L]>>>0,v[L]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");S=y,w++}if(b[w]!==" "){for(var C=T-S;C!==T&&v[C]===0;)C++;for(var I=new Uint8Array(d+(T-C)),p=d;C!==T;)I[p++]=v[C++];return I}}}function m(b){var w=h(b);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:m}}var ic=sc,ac=ic,Bs=ac;var Pn=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")}},Rn=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)}},On=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 On({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Nn=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 Pn(t,e,n),this.decoder=new Rn(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 Nn(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Bs(e,r);return ge({prefix:t,name:r,encode:n,decode:s=>Dt(o(s))})}function cc(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,u=0;for(let c=0;c<o;++c){let l=t[r[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[u++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function uc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],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 fc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function G({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=fc(n);return ge({prefix:t,name:r,encode(s){return uc(s,n,e)},decode(s){return cc(s,o,e,r)}})}var V=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lc=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Un={};dt(Un,{base32:()=>qt,base32hex:()=>mc,base32hexpad:()=>yc,base32hexpadupper:()=>bc,base32hexupper:()=>gc,base32pad:()=>dc,base32padupper:()=>pc,base32upper:()=>hc,base32z:()=>xc});var qt=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hc=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),dc=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),pc=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mc=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gc=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yc=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),bc=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xc=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Mn={};dt(Mn,{base36:()=>Ve,base36upper:()=>wc});var Ve=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),wc=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ec=Ls,Ds=128,_c=127,Sc=~_c,vc=Math.pow(2,31);function Ls(r,t,e){t=t||[],e=e||0;for(var n=e;r>=vc;)t[e++]=r&255|Ds,r/=128;for(;r⪼)t[e++]=r&255|Ds,r>>>=7;return t[e]=r|0,Ls.bytes=e-n+1,t}var Ac=Fn,Ic=128,Cs=127;function Fn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Fn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Cs)<<o:(i&Cs)*Math.pow(2,o),o+=7}while(i>=Ic);return Fn.bytes=s-n,e}var Bc=Math.pow(2,7),Tc=Math.pow(2,14),Dc=Math.pow(2,21),Cc=Math.pow(2,28),Lc=Math.pow(2,35),Pc=Math.pow(2,42),Rc=Math.pow(2,49),Oc=Math.pow(2,56),Nc=Math.pow(2,63),kc=function(r){return r<Bc?1:r<Tc?2:r<Dc?3:r<Cc?4:r<Lc?5:r<Pc?6:r<Rc?7:r<Oc?8:r<Nc?9:10},Uc={encode:Ec,decode:Ac,encodingLength:kc},Mc=Uc,je=Mc;function Ge(r,t=0){return[je.decode(r,t),je.decode.bytes]}function ye(r,t,e=0){return je.encode(r,t,e),t}function be(r){return je.encodingLength(r)}function Xt(r,t){let e=t.byteLength,n=be(r),o=n+be(e),s=new Uint8Array(o+e);return ye(r,s,0),ye(e,s,n),s.set(t,o),new xe(r,e,t,s)}function Qt(r){let t=Dt(r),[e,n]=Ge(t),[o,s]=Ge(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 Ps(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ss(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 Rs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Kc(e,Kn(r),t??V.encoder);default:return zc(e,Kn(r),t??qt.encoder)}}var Os=new WeakMap;function Kn(r){let t=Os.get(r);if(t==null){let e=new Map;return Os.set(r,e),e}return t}var X=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!==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=Xt(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&&Ps(t.multihash,n.multihash)}toString(t){return Rs(this,t)}toJSON(){return{"/":Rs(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[Hc]===!0){let{version:n,multihash:o,code:s}=e,i=Qt(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=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 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[f,h]=Ge(t.subarray(e));return e+=h,f},o=n(),s=$e;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),u=n(),c=e+u,l=c-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:l,size:c}}static parse(t,e){let[n,o]=Fc(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 Kn(s).set(n,t),s}};function Fc(r,t){switch(r[0]){case"Q":{let e=t??V;return[V.prefix,e.decode(`${V.prefix}${r}`)]}case V.prefix:{let e=t??V;return[V.prefix,e.decode(r)]}case qt.prefix:{let e=t??qt;return[qt.prefix,e.decode(r)]}case Ve.prefix:{let e=t??Ve;return[Ve.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!==V.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 zc(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,qc=18;function Ns(r,t,e){let n=be(r),o=n+be(t),s=new Uint8Array(o+e.byteLength);return ye(r,s,0),ye(t,s,n),s.set(e,o),s}var Hc=Symbol.for("@ipld/js-cid/CID");var zn={};dt(zn,{identity:()=>yt});var ks=0,Vc="identity",Us=Dt;function jc(r){return Xt(ks,Us(r))}var yt={code:ks,name:Vc,encode:Us,digest:jc};function at(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function bt(r=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function Ct(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Fs=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 Tr(r){return!!r?.[Fs]}var W=class r{bufs;length;[Fs]=!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(Tr(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(Tr(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(Tr(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,u=a+i.byteLength;if(o=u,t>=u)continue;let c=t>=a&&t<u,l=e>a&&e<=u;if(c&&l){if(t===a&&e===u){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===u){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(!Tr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,u=this.byteLength-n.byteLength,c=n.byteLength-1,l;for(let f=e;f<=u;f+=l){l=0;for(let h=c;h>=0;h--){let m=this.get(f+h);if(n[h]!==m){l=Math.max(1,h-a[m]);break}}if(l===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=bt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=bt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=bt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=bt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=bt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=bt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=bt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=bt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!at(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 qn={};dt(qn,{base10:()=>Gc});var Gc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var Hn={};dt(Hn,{base16:()=>$c,base16upper:()=>Zc});var $c=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Zc=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Vn={};dt(Vn,{base2:()=>Wc});var Wc=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var jn={};dt(jn,{base256emoji:()=>tu});var Ks=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}"),Yc=Ks.reduce((r,t,e)=>(r[e]=t,r),[]),Xc=Ks.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Qc(r){return r.reduce((t,e)=>(t+=Yc[e],t),"")}function Jc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Xc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var tu=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Qc,decode:Jc});var $n={};dt($n,{base64:()=>eu,base64pad:()=>ru,base64url:()=>Gn,base64urlpad:()=>nu});var eu=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ru=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Gn=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nu=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Zn={};dt(Zn,{base8:()=>ou});var ou=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Wn={};dt(Wn,{identity:()=>su});var su=ge({prefix:"\0",name:"identity",encode:r=>As(r),decode:r=>vs(r)});var td=new TextEncoder,ed=new TextDecoder;var Qn={};dt(Qn,{sha256:()=>Ze,sha512:()=>cu});function Xn({name:r,code:t,encode:e}){return new Yn(r,t,e)}var Yn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Xt(this.code,e):e.then(n=>Xt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function qs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ze=Xn({name:"sha2-256",code:18,encode:qs("SHA-256")}),cu=Xn({name:"sha2-512",code:19,encode:qs("SHA-512")});var We={...Wn,...Vn,...Zn,...qn,...Hn,...Un,...Mn,...kn,...$n,...jn},dd={...Qn,...zn};function Vs(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Hs=Vs("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Jn=Vs("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=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),uu={utf8:Hs,"utf-8":Hs,hex:We.base16,latin1:Jn,ascii:Jn,binary:Jn,...We},Dr=uu;function M(r,t="utf8"){let e=Dr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function z(r,t="utf8"){let e=Dr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var fu=parseInt("11111",2),to=parseInt("10000000",2),lu=parseInt("01111111",2),js={0:Ye,1:Ye,2:hu,3:mu,4:gu,5:pu,6:du,16:Ye,22:Ye,48:Ye};function eo(r,t={offset:0}){let e=r[t.offset]&fu;if(t.offset++,js[e]!=null)return js[e](r,t);throw new Error("No decoder for tag "+e)}function Xe(r,t){let e=0;if((r[t.offset]&to)===to){let n=r[t.offset]&lu,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 Ye(r,t){Xe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=eo(r,t);if(n===null)break;e.push(n)}return e}function hu(r,t){let e=Xe(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 du(r,t){let e=Xe(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}`,u=[];for(;t.offset<n;){let c=r[t.offset];if(t.offset++,u.push(c&127),c<128){u.reverse();let l=0;for(let f=0;f<u.length;f++)l+=u[f]<<f*7;a+=`.${l}`,u=[]}}return a}function pu(r,t){return t.offset++,null}function mu(r,t){let e=Xe(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 gu(r,t){let e=Xe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function yu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new W;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function ro(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=yu(r.byteLength);return new W(Uint8Array.from([t.byteLength|to]),t)}function Gs(r){let t=new W,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new W(Uint8Array.from([2]),ro(t),t)}function $s(r){let t=Uint8Array.from([0]),e=new W(t,r);return new W(Uint8Array.from([3]),ro(e),e)}function Cr(r,t=48){let e=new W;for(let n of r)e.append(n);return new W(Uint8Array.from([t]),ro(e),e)}async function Zs(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 bu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),xu=Uint8Array.from([6,5,43,129,4,0,34]),wu=Uint8Array.from([6,5,43,129,4,0,35]),Eu={ext:!0,kty:"EC",crv:"P-256"},_u={ext:!0,kty:"EC",crv:"P-384"},Su={ext:!0,kty:"EC",crv:"P-521"},no=32,oo=48,so=66;function Ws(r){let t=eo(r);return Ys(t)}function Ys(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===no*2+1)return n=z(t.subarray(e,e+no),"base64url"),o=z(t.subarray(e+no),"base64url"),new we({...Eu,key_ops:["verify"],x:n,y:o});if(t.byteLength===oo*2+1)return n=z(t.subarray(e,e+oo),"base64url"),o=z(t.subarray(e+oo),"base64url"),new we({..._u,key_ops:["verify"],x:n,y:o});if(t.byteLength===so*2+1)return n=z(t.subarray(e,e+so),"base64url"),o=z(t.subarray(e+so),"base64url"),new we({...Su,key_ops:["verify"],x:n,y:o});throw new Tt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Xs(r){return Cr([Gs(Uint8Array.from([1])),Cr([vu(r.crv)],160),Cr([$s(new W(Uint8Array.from([4]),M(r.x??"","base64url"),M(r.y??"","base64url")))],161)]).subarray()}function vu(r){if(r==="P-256")return bu;if(r==="P-384")return xu;if(r==="P-521")return wu;throw new Tt(`Invalid curve ${r}`)}var we=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Xs(this.jwk)),this._raw}toMultihash(){return yt.digest(Ee(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return V.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async verify(t,e,n){return Zs(this.jwk,e,t,n)}};var Jt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Se(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Qe(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function nt(r,...t){if(!Se(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Js(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Qe(r.outputLen),Qe(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){nt(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Pt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Lr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function xt(r,t){return r<<32-t|r>>>t}var ei=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Au=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function vt(r){if(nt(r),ei)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Au[r[e]];return t}var Lt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Qs(r){if(r>=Lt._0&&r<=Lt._9)return r-Lt._0;if(r>=Lt.A&&r<=Lt.F)return r-(Lt.A-10);if(r>=Lt.a&&r<=Lt.f)return r-(Lt.a-10)}function Ae(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=Qs(r.charCodeAt(s)),a=Qs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let u=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+s)}n[o]=i*16+a}return n}function ri(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Je(r){return typeof r=="string"&&(r=ri(r)),nt(r),r}function pt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];nt(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}var _e=class{};function io(r){let t=n=>r().update(Je(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function tr(r=32){if(Jt&&typeof Jt.getRandomValues=="function")return Jt.getRandomValues(new Uint8Array(r));if(Jt&&typeof Jt.randomBytes=="function")return Uint8Array.from(Jt.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Iu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),u=n?4:0,c=n?0:4;r.setUint32(t+u,i,n),r.setUint32(t+c,a,n)}function ni(r,t,e){return r&t^~r&e}function oi(r,t,e){return r&t^r&e^t&e}var er=class extends _e{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Lr(this.buffer)}update(t){ve(this),t=Je(t),nt(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 u=Lr(t);for(;o<=s-i;i+=o)this.process(u,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ve(this),ti(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 f=i;f<o;f++)e[f]=0;Iu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Lr(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let c=u/4,l=this.get();if(c>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<c;f++)a.setUint32(4*f,l[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(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()}},Rt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var tt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Pr=BigInt(4294967295),si=BigInt(32);function Bu(r,t=!1){return t?{h:Number(r&Pr),l:Number(r>>si&Pr)}:{h:Number(r>>si&Pr)|0,l:Number(r&Pr)|0}}function ii(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}=Bu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var ao=(r,t,e)=>r>>>e,co=(r,t,e)=>r<<32-e|t>>>e,te=(r,t,e)=>r>>>e|t<<32-e,ee=(r,t,e)=>r<<32-e|t>>>e,rr=(r,t,e)=>r<<64-e|t>>>e-32,nr=(r,t,e)=>r>>>e-32|t<<64-e;function At(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var ai=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ci=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ui=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),fi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,li=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),hi=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Du=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]),Vt=new Uint32Array(64),uo=class extends er{constructor(t=32){super(64,t,8,!1),this.A=Rt[0]|0,this.B=Rt[1]|0,this.C=Rt[2]|0,this.D=Rt[3]|0,this.E=Rt[4]|0,this.F=Rt[5]|0,this.G=Rt[6]|0,this.H=Rt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:u}=this;return[t,e,n,o,s,i,a,u]}set(t,e,n,o,s,i,a,u){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=u|0}process(t,e){for(let f=0;f<16;f++,e+=4)Vt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Vt[f-15],m=Vt[f-2],b=xt(h,7)^xt(h,18)^h>>>3,w=xt(m,17)^xt(m,19)^m>>>10;Vt[f]=w+Vt[f-7]+b+Vt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:u,G:c,H:l}=this;for(let f=0;f<64;f++){let h=xt(a,6)^xt(a,11)^xt(a,25),m=l+h+ni(a,u,c)+Du[f]+Vt[f]|0,w=(xt(n,2)^xt(n,13)^xt(n,22))+oi(n,o,s)|0;l=c,c=u,u=a,a=i+m|0,i=s,s=o,o=n,n=m+w|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,u=u+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,u,c,l)}roundClean(){Pt(Vt)}destroy(){this.set(0,0,0,0,0,0,0,0),Pt(this.buffer)}};var di=ii(["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))),Cu=di[0],Lu=di[1],jt=new Uint32Array(80),Gt=new Uint32Array(80),fo=class extends er{constructor(t=64){super(128,t,16,!1),this.Ah=tt[0]|0,this.Al=tt[1]|0,this.Bh=tt[2]|0,this.Bl=tt[3]|0,this.Ch=tt[4]|0,this.Cl=tt[5]|0,this.Dh=tt[6]|0,this.Dl=tt[7]|0,this.Eh=tt[8]|0,this.El=tt[9]|0,this.Fh=tt[10]|0,this.Fl=tt[11]|0,this.Gh=tt[12]|0,this.Gl=tt[13]|0,this.Hh=tt[14]|0,this.Hl=tt[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:u,Eh:c,El:l,Fh:f,Fl:h,Gh:m,Gl:b,Hh:w,Hl:d}=this;return[t,e,n,o,s,i,a,u,c,l,f,h,m,b,w,d]}set(t,e,n,o,s,i,a,u,c,l,f,h,m,b,w,d){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=u|0,this.Eh=c|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=m|0,this.Gl=b|0,this.Hh=w|0,this.Hl=d|0}process(t,e){for(let v=0;v<16;v++,e+=4)jt[v]=t.getUint32(e),Gt[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let P=jt[v-15]|0,y=Gt[v-15]|0,L=te(P,y,1)^te(P,y,8)^ao(P,y,7),C=ee(P,y,1)^ee(P,y,8)^co(P,y,7),I=jt[v-2]|0,p=Gt[v-2]|0,E=te(I,p,19)^rr(I,p,61)^ao(I,p,6),g=ee(I,p,19)^nr(I,p,61)^co(I,p,6),x=ui(C,g,Gt[v-7],Gt[v-16]),_=fi(x,L,E,jt[v-7],jt[v-16]);jt[v]=_|0,Gt[v]=x|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:u,Dh:c,Dl:l,Eh:f,El:h,Fh:m,Fl:b,Gh:w,Gl:d,Hh:S,Hl:T}=this;for(let v=0;v<80;v++){let P=te(f,h,14)^te(f,h,18)^rr(f,h,41),y=ee(f,h,14)^ee(f,h,18)^nr(f,h,41),L=f&m^~f&w,C=h&b^~h&d,I=li(T,y,C,Lu[v],Gt[v]),p=hi(I,S,P,L,Cu[v],jt[v]),E=I|0,g=te(n,o,28)^rr(n,o,34)^rr(n,o,39),x=ee(n,o,28)^nr(n,o,34)^nr(n,o,39),_=n&s^n&a^s&a,B=o&i^o&u^i&u;S=w|0,T=d|0,w=m|0,d=b|0,m=f|0,b=h|0,{h:f,l:h}=At(c|0,l|0,p|0,E|0),c=a|0,l=u|0,a=s|0,u=i|0,s=n|0,i=o|0;let A=ai(E,x,B);n=ci(A,p,g,_),o=A|0}({h:n,l:o}=At(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=At(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:u}=At(this.Ch|0,this.Cl|0,a|0,u|0),{h:c,l}=At(this.Dh|0,this.Dl|0,c|0,l|0),{h:f,l:h}=At(this.Eh|0,this.El|0,f|0,h|0),{h:m,l:b}=At(this.Fh|0,this.Fl|0,m|0,b|0),{h:w,l:d}=At(this.Gh|0,this.Gl|0,w|0,d|0),{h:S,l:T}=At(this.Hh|0,this.Hl|0,S|0,T|0),this.set(n,o,s,i,a,u,c,l,f,h,m,b,w,d,S,T)}roundClean(){Pt(jt,Gt)}destroy(){Pt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var pi=io(()=>new uo);var mi=io(()=>new fo);var po=BigInt(0),ho=BigInt(1);function Ot(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function or(r){let t=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===""?po:BigInt("0x"+r)}function Ie(r){return gi(vt(r))}function re(r){return nt(r),gi(vt(Uint8Array.from(r).reverse()))}function Rr(r,t){return Ae(r.toString(16).padStart(t*2,"0"))}function Be(r,t){return Rr(r,t).reverse()}function q(r,t,e){let n;if(typeof t=="string")try{n=Ae(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Se(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}var lo=r=>typeof r=="bigint"&&po<=r;function yi(r,t,e){return lo(r)&&lo(t)&&lo(e)&&t<=r&&r<e}function $t(r,t,e,n){if(!yi(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function bi(r){let t;for(t=0;r>po;r>>=ho,t+=1);return t}var ne=r=>(ho<<BigInt(r))-ho;function xi(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=m=>new Uint8Array(m),o=m=>Uint8Array.of(m),s=n(r),i=n(r),a=0,u=()=>{s.fill(1),i.fill(0),a=0},c=(...m)=>e(i,s,...m),l=(m=n(0))=>{i=c(o(0),m),s=c(),m.length!==0&&(i=c(o(1),m),s=c())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let m=0,b=[];for(;m<t;){s=c();let w=s.slice();b.push(w),m+=s.length}return pt(...b)};return(m,b)=>{u(),l(m);let w;for(;!(w=b(f()));)l();return u(),w}}function Zt(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let u=typeof a;if(u!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${u}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!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 ct=BigInt(0),Q=BigInt(1),oe=BigInt(2),Pu=BigInt(3),_i=BigInt(4),Si=BigInt(5),vi=BigInt(8);function j(r,t){let e=r%t;return e>=ct?e:t+e}function H(r,t,e){let n=r;for(;t-- >ct;)n*=n,n%=e;return n}function wi(r,t){if(r===ct)throw new Error("invert: expected non-zero number");if(t<=ct)throw new Error("invert: expected positive modulus, got "+t);let e=j(r,t),n=t,o=ct,s=Q,i=Q,a=ct;for(;e!==ct;){let c=n/e,l=n%e,f=o-i*c,h=s-a*c;n=e,e=l,o=i,s=a,i=f,a=h}if(n!==Q)throw new Error("invert: does not exist");return j(o,t)}function Ai(r,t){let e=(r.ORDER+Q)/_i,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function Ru(r,t){let e=(r.ORDER-Si)/vi,n=r.mul(t,oe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,oe),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function Ou(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-Q,e=0;for(;t%oe===ct;)t/=oe,e++;let n=oe,o=wt(r);for(;Ei(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+Q)/oe;return function(u,c){if(u.is0(c))return c;if(Ei(u,c)!==1)throw new Error("Cannot find square root");let l=e,f=u.mul(u.ONE,s),h=u.pow(c,t),m=u.pow(c,i);for(;!u.eql(h,u.ONE);){if(u.is0(h))return u.ZERO;let b=1,w=u.sqr(h);for(;!u.eql(w,u.ONE);)if(b++,w=u.sqr(w),b===l)throw new Error("Cannot find square root");let d=Q<<BigInt(l-b-1),S=u.pow(f,d);l=b,f=u.sqr(S),h=u.mul(h,f),m=u.mul(m,S)}return m}}function Nu(r){return r%_i===Pu?Ai:r%vi===Si?Ru:Ou(r)}var Ii=(r,t)=>(j(r,t)&Q)===Q,ku=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function mo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=ku.reduce((n,o)=>(n[o]="function",n),t);return Zt(r,e),r}function Uu(r,t,e){if(e<ct)throw new Error("invalid exponent, negatives unsupported");if(e===ct)return r.ONE;if(e===Q)return t;let n=r.ONE,o=t;for(;e>ct;)e&Q&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Q;return n}function sr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,u)=>r.is0(a)?i:(n[u]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,u)=>r.is0(a)?i:(n[u]=r.mul(i,n[u]),r.mul(i,a)),s),n}function Ei(r,t){let e=(r.ORDER-Q)/oe,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Bi(r,t){t!==void 0&&Qe(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function wt(r,t,e=!1,n={}){if(r<=ct)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(o=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(e=l.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Bi(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u,c=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ne(i),ZERO:ct,ONE:Q,create:l=>j(l,r),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return ct<=l&&l<r},is0:l=>l===ct,isValidNot0:l=>!c.is0(l)&&c.isValid(l),isOdd:l=>(l&Q)===Q,neg:l=>j(-l,r),eql:(l,f)=>l===f,sqr:l=>j(l*l,r),add:(l,f)=>j(l+f,r),sub:(l,f)=>j(l-f,r),mul:(l,f)=>j(l*f,r),pow:(l,f)=>Uu(c,l,f),div:(l,f)=>j(l*wi(f,r),r),sqrN:l=>l*l,addN:(l,f)=>l+f,subN:(l,f)=>l-f,mulN:(l,f)=>l*f,inv:l=>wi(l,r),sqrt:s||(l=>(u||(u=Nu(r)),u(c,l))),toBytes:l=>e?Be(l,a):Rr(l,a),fromBytes:l=>{if(l.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);return e?re(l):Ie(l)},invertBatch:l=>sr(c,l),cmov:(l,f,h)=>h?f:l});return Object.freeze(c)}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 go(r){let t=Ti(r);return t+Math.ceil(t/2)}function Di(r,t,e=!1){let n=r.length,o=Ti(t),s=go(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?re(r):Ie(r),a=j(i,t-Q)+Q;return e?Be(a,o):Rr(a,o)}var Ce=BigInt(0),se=BigInt(1);function De(r,t){let e=t.negate();return r?e:t}function Or(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=sr(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}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 yo(r,t){Ri(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ne(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ci(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),u=r>>i;a>n&&(a-=s,u+=se);let c=t*n,l=c+Math.abs(a)-1,f=a===0,h=a<0,m=t%2!==0;return{nextN:u,offset:l,isZero:f,isNeg:h,isNegF:m,offsetF:c}}function Mu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Fu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var bo=new WeakMap,Oi=new WeakMap;function xo(r){return Oi.get(r)||1}function Li(r){if(r!==Ce)throw new Error("invalid wNAF")}function Nr(r,t){return{constTimeNegate:De,hasPrecomputes(e){return xo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Ce;)n&se&&(o=o.add(s)),s=s.double(),n>>=se;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=yo(n,t),i=[],a=e,u=a;for(let c=0;c<o;c++){u=a,i.push(u);for(let l=1;l<s;l++)u=u.add(a),i.push(u);a=u.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=yo(e,t);for(let u=0;u<a.windows;u++){let{nextN:c,offset:l,isZero:f,isNeg:h,isNegF:m,offsetF:b}=Ci(o,u,a);o=c,f?i=i.add(De(m,n[b])):s=s.add(De(h,n[l]))}return Li(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=yo(e,t);for(let a=0;a<i.windows&&o!==Ce;a++){let{nextN:u,offset:c,isZero:l,isNeg:f}=Ci(o,a,i);if(o=u,!l){let h=n[c];s=s.add(f?h.negate():h)}}return Li(o),s},getPrecomputes(e,n,o){let s=bo.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),bo.set(n,s))),s},wNAFCached(e,n,o){let s=xo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=xo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Ri(n,t),Oi.set(e,n),bo.delete(e)}}}function Ni(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ce||n>Ce;)e&se&&(s=s.add(o)),n&se&&(i=i.add(o)),o=o.double(),e>>=se,n>>=se;return{p1:s,p2:i}}function kr(r,t,e,n){Mu(e,r),Fu(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=bi(BigInt(o)),u=1;a>12?u=a-3:a>4?u=a-2:a>0&&(u=2);let c=ne(u),l=new Array(Number(c)+1).fill(i),f=Math.floor((t.BITS-1)/u)*u,h=i;for(let m=f;m>=0;m-=u){l.fill(i);for(let w=0;w<s;w++){let d=n[w],S=Number(d>>BigInt(m)&c);l[S]=l[S].add(e[w])}let b=i;for(let w=l.length-1,d=i;w>0;w--)d=d.add(l[w]),b=b.add(d);if(h=h.add(b),m!==0)for(let w=0;w<u;w++)h=h.double()}return h}function Pi(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return mo(t),t}else return wt(r)}function Ur(r,t,e={}){if(!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>Ce))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Pi(t.p,e.Fp),o=Pi(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var It=BigInt(0),ut=BigInt(1),wo=BigInt(2),Ku=BigInt(8),zu={zip215:!0};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 Hu(r,t={}){let{Fp:e,Fn:n}=Ur("edwards",r,t),{h:o,n:s}=r;Zt(t,{},{uvRatio:"function"});let i=wo<<BigInt(n.BYTES*8)-ut,a=w=>e.create(w),u=t.uvRatio||((w,d)=>{try{return{isValid:!0,value:e.sqrt(e.div(w,d))}}catch{return{isValid:!1,value:It}}});if(!qu(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function c(w,d,S=!1){let T=S?ut:It;return $t("coordinate "+w,d,T,i),d}function l(w){if(!(w instanceof m))throw new Error("ExtendedPoint expected")}let f=Te((w,d)=>{let{ex:S,ey:T,ez:v}=w,P=w.is0();d==null&&(d=P?Ku:e.inv(v));let y=a(S*d),L=a(T*d),C=a(v*d);if(P)return{x:It,y:ut};if(C!==ut)throw new Error("invZ was invalid");return{x:y,y:L}}),h=Te(w=>{let{a:d,d:S}=r;if(w.is0())throw new Error("bad point: ZERO");let{ex:T,ey:v,ez:P,et:y}=w,L=a(T*T),C=a(v*v),I=a(P*P),p=a(I*I),E=a(L*d),g=a(I*a(E+C)),x=a(p+a(S*a(L*C)));if(g!==x)throw new Error("bad point: equation left != right (1)");let _=a(T*v),B=a(P*y);if(_!==B)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(d,S,T,v){this.ex=c("x",d),this.ey=c("y",S),this.ez=c("z",T,!0),this.et=c("t",v),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof m)throw new Error("extended point not allowed");let{x:S,y:T}=d||{};return c("x",S),c("y",T),new m(S,T,ut,a(S*T))}static normalizeZ(d){return Or(m,"ez",d)}static msm(d,S){return kr(m,n,d,S)}_setWindowSize(d){this.precompute(d)}precompute(d=8,S=!0){return b.setWindowSize(this,d),S||this.multiply(wo),this}assertValidity(){h(this)}equals(d){l(d);let{ex:S,ey:T,ez:v}=this,{ex:P,ey:y,ez:L}=d,C=a(S*L),I=a(P*v),p=a(T*L),E=a(y*v);return C===I&&p===E}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:d}=r,{ex:S,ey:T,ez:v}=this,P=a(S*S),y=a(T*T),L=a(wo*a(v*v)),C=a(d*P),I=S+T,p=a(a(I*I)-P-y),E=C+y,g=E-L,x=C-y,_=a(p*g),B=a(E*x),A=a(p*x),D=a(g*E);return new m(_,B,D,A)}add(d){l(d);let{a:S,d:T}=r,{ex:v,ey:P,ez:y,et:L}=this,{ex:C,ey:I,ez:p,et:E}=d,g=a(v*C),x=a(P*I),_=a(L*T*E),B=a(y*p),A=a((v+P)*(C+I)-g-x),D=B-_,O=B+_,R=a(x-S*g),$=a(A*D),U=a(O*R),N=a(A*R),Z=a(D*O);return new m($,U,Z,N)}subtract(d){return this.add(d.negate())}multiply(d){let S=d;$t("scalar",S,ut,s);let{p:T,f:v}=b.wNAFCached(this,S,m.normalizeZ);return m.normalizeZ([T,v])[0]}multiplyUnsafe(d,S=m.ZERO){let T=d;return $t("scalar",T,It,s),T===It?m.ZERO:this.is0()||T===ut?this:b.wNAFCachedUnsafe(this,T,m.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return b.wNAFCachedUnsafe(this,s).is0()}toAffine(d){return f(this,d)}clearCofactor(){return o===ut?this:this.multiplyUnsafe(o)}static fromBytes(d,S=!1){return nt(d),this.fromHex(d,S)}static fromHex(d,S=!1){let{d:T,a:v}=r,P=e.BYTES;d=q("pointHex",d,P),Ot("zip215",S);let y=d.slice(),L=d[P-1];y[P-1]=L&-129;let C=re(y),I=S?i:e.ORDER;$t("pointHex.y",C,It,I);let p=a(C*C),E=a(p-ut),g=a(T*p-v),{isValid:x,value:_}=u(E,g);if(!x)throw new Error("Point.fromHex: invalid y coordinate");let B=(_&ut)===ut,A=(L&128)!==0;if(!S&&_===It&&A)throw new Error("Point.fromHex: x=0 and x_0=1");return A!==B&&(_=a(-_)),m.fromAffine({x:_,y:C})}static fromPrivateScalar(d){return m.BASE.multiply(d)}toBytes(){let{x:d,y:S}=this.toAffine(),T=Be(S,e.BYTES);return T[T.length-1]|=d&ut?128:0,T}toRawBytes(){return this.toBytes()}toHex(){return vt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}m.BASE=new m(r.Gx,r.Gy,ut,a(r.Gx*r.Gy)),m.ZERO=new m(It,ut,ut,It),m.Fp=e,m.Fn=n;let b=Nr(m,n.BYTES*8);return m}function Vu(r,t){Zt(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,u=t.randomBytes||tr,c=t.adjustScalarBytes||(y=>y),l=t.domain||((y,L,C)=>{if(Ot("phflag",C),L.length||C)throw new Error("Contexts/pre-hash are not supported");return y});function f(y){return i.create(y)}function h(y){return f(re(y))}function m(y){let L=s.BYTES;y=q("private key",y,L);let C=q("hashed private key",n(y),2*L),I=c(C.slice(0,L)),p=C.slice(L,2*L),E=h(I);return{head:I,prefix:p,scalar:E}}function b(y){let{head:L,prefix:C,scalar:I}=m(y),p=o.multiply(I),E=p.toBytes();return{head:L,prefix:C,scalar:I,point:p,pointBytes:E}}function w(y){return b(y).pointBytes}function d(y=Uint8Array.of(),...L){let C=pt(...L);return h(n(l(C,q("context",y),!!e)))}function S(y,L,C={}){y=q("message",y),e&&(y=e(y));let{prefix:I,scalar:p,pointBytes:E}=b(L),g=d(C.context,I,y),x=o.multiply(g).toBytes(),_=d(C.context,x,E,y),B=f(g+_*p);$t("signature.s",B,It,a);let A=s.BYTES,D=pt(x,Be(B,A));return q("result",D,A*2)}let T=zu;function v(y,L,C,I=T){let{context:p,zip215:E}=I,g=s.BYTES;y=q("signature",y,2*g),L=q("message",L),C=q("publicKey",C,g),E!==void 0&&Ot("zip215",E),e&&(L=e(L));let x=re(y.slice(g,2*g)),_,B,A;try{_=r.fromHex(C,E),B=r.fromHex(y.slice(0,g),E),A=o.multiplyUnsafe(x)}catch{return!1}if(!E&&_.isSmallOrder())return!1;let D=d(p,B.toBytes(),_.toBytes(),L);return B.add(_.multiplyUnsafe(D)).subtract(A).clearCofactor().is0()}return o.precompute(8),{getPublicKey:w,sign:S,verify:v,utils:{getExtendedPublicKey:b,randomPrivateKey:()=>u(s.BYTES),precompute(y=8,L=r.BASE){return L.precompute(y,!1)}},Point:r}}function ju(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=wt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function Gu(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function ki(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=ju(r),o=Hu(t,e),s=Vu(o,n);return Gu(r,s)}var bp=BigInt(0),$u=BigInt(1),Ui=BigInt(2),xp=BigInt(3),Zu=BigInt(5),Wu=BigInt(8),Mr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Wu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Yu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Mr.p,a=r*r%s*r%s,u=H(a,Ui,s)*a%s,c=H(u,$u,s)*r%s,l=H(c,Zu,s)*c%s,f=H(l,t,s)*l%s,h=H(f,e,s)*f%s,m=H(h,n,s)*h%s,b=H(m,o,s)*m%s,w=H(b,o,s)*m%s,d=H(w,t,s)*l%s;return{pow_p_5_8:H(d,Ui,s)*r%s,b2:a}}function Xu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Mi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Qu(r,t){let e=Mr.p,n=j(t*t*t,e),o=j(n*n*t,e),s=Yu(r*o).pow_p_5_8,i=j(r*n*s,e),a=j(t*i*i,e),u=i,c=j(i*Mi,e),l=a===r,f=a===j(-r,e),h=a===j(-r*Mi,e);return l&&(i=u),(f||h)&&(i=c),Ii(i,e)&&(i=j(-i,e)),{isValid:l||f,value:i}}var Ju=wt(Mr.p,void 0,!0),tf={...Mr,Fp:Ju,hash:mi,adjustScalarBytes:Xu,uvRatio:Qu},Fi=ki(tf);var ir=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Fr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ki={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Fr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Kr=Ki;var zr=32;var Eo,ef=(async()=>{try{return await Kr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function rf(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Kr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Kr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function nf(r,t,e){return Fi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function zi(r,t,e){return Eo==null&&(Eo=await ef),Eo?rf(r,t,e):nf(r,t,e)}function qr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Hr=class{type="Ed25519";raw;constructor(t){this.raw=_o(t,zr)}toMultihash(){return yt.digest(Ee(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return V.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=zi(this.raw,e,t);return qr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Hi(r){return r=_o(r,zr),new Hr(r)}function _o(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Tt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var sf=Math.pow(2,7),af=Math.pow(2,14),cf=Math.pow(2,21),So=Math.pow(2,28),vo=Math.pow(2,35),Ao=Math.pow(2,42),Io=Math.pow(2,49),k=128,ot=127;function lt(r){if(r<sf)return 1;if(r<af)return 2;if(r<cf)return 3;if(r<So)return 4;if(r<vo)return 5;if(r<Ao)return 6;if(r<Io)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Le(r,t,e=0){switch(lt(r)){case 8:t[e++]=r&255|k,r/=128;case 7:t[e++]=r&255|k,r/=128;case 6:t[e++]=r&255|k,r/=128;case 5:t[e++]=r&255|k,r/=128;case 4:t[e++]=r&255|k,r>>>=7;case 3:t[e++]=r&255|k,r>>>=7;case 2:t[e++]=r&255|k,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function uf(r,t,e=0){switch(lt(r)){case 8:t.set(e++,r&255|k),r/=128;case 7:t.set(e++,r&255|k),r/=128;case 6:t.set(e++,r&255|k),r/=128;case 5:t.set(e++,r&255|k),r/=128;case 4:t.set(e++,r&255|k),r>>>=7;case 3:t.set(e++,r&255|k),r>>>=7;case 2:t.set(e++,r&255|k),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Bo(r,t){let e=r[t],n=0;if(n+=e&ot,e<k||(e=r[t+1],n+=(e&ot)<<7,e<k)||(e=r[t+2],n+=(e&ot)<<14,e<k)||(e=r[t+3],n+=(e&ot)<<21,e<k)||(e=r[t+4],n+=(e&ot)*So,e<k)||(e=r[t+5],n+=(e&ot)*vo,e<k)||(e=r[t+6],n+=(e&ot)*Ao,e<k)||(e=r[t+7],n+=(e&ot)*Io,e<k))return n;throw new RangeError("Could not decode varint")}function ff(r,t){let e=r.get(t),n=0;if(n+=e&ot,e<k||(e=r.get(t+1),n+=(e&ot)<<7,e<k)||(e=r.get(t+2),n+=(e&ot)<<14,e<k)||(e=r.get(t+3),n+=(e&ot)<<21,e<k)||(e=r.get(t+4),n+=(e&ot)*So,e<k)||(e=r.get(t+5),n+=(e&ot)*vo,e<k)||(e=r.get(t+6),n+=(e&ot)*Ao,e<k)||(e=r.get(t+7),n+=(e&ot)*Io,e<k))return n;throw new RangeError("Could not decode varint")}function Vi(r,t,e=0){return t==null&&(t=ft(lt(r))),t instanceof Uint8Array?Le(r,t,e):uf(r,t,e)}function ar(r,t=0){return r instanceof Uint8Array?Bo(r,t):ff(r,t)}var To=new Float32Array([-0]),Wt=new Uint8Array(To.buffer);function Gi(r,t,e){To[0]=r,t[e]=Wt[0],t[e+1]=Wt[1],t[e+2]=Wt[2],t[e+3]=Wt[3]}function $i(r,t){return Wt[0]=r[t],Wt[1]=r[t+1],Wt[2]=r[t+2],Wt[3]=r[t+3],To[0]}var Do=new Float64Array([-0]),st=new Uint8Array(Do.buffer);function Zi(r,t,e){Do[0]=r,t[e]=st[0],t[e+1]=st[1],t[e+2]=st[2],t[e+3]=st[3],t[e+4]=st[4],t[e+5]=st[5],t[e+6]=st[6],t[e+7]=st[7]}function Wi(r,t){return st[0]=r[t],st[1]=r[t+1],st[2]=r[t+2],st[3]=r[t+3],st[4]=r[t+4],st[5]=r[t+5],st[6]=r[t+6],st[7]=r[t+7],Do[0]}var lf=BigInt(Number.MAX_SAFE_INTEGER),hf=BigInt(Number.MIN_SAFE_INTEGER),mt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ie;if(t<lf&&t>hf)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>Yi&&(o=0n,++n>Yi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ie;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ie}},ie=new mt(0,0);ie.toBigInt=function(){return 0n};ie.zzEncode=ie.zzDecode=function(){return this};ie.length=function(){return 1};var Yi=4294967296n;function Xi(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,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 Co(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 Et(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Vr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Lo=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,Et(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 Et(this,4);return Vr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Et(this,4);return Vr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Et(this,4);let t=$i(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Et(this,4);let t=Wi(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 Et(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 Et(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Et(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 mt(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 Et(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 Et(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 Et(this,8);let t=Vr(this.buf,this.pos+=4),e=Vr(this.buf,this.pos+=4);return new mt(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=Bo(this.buf,this.pos);return this.pos+=lt(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 Po(r){return new Lo(r instanceof Uint8Array?r:r.subarray())}function Nt(r,t,e){let n=Po(r);return t.decode(n,void 0,e)}function Ro(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ae=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Oo(){}var ko=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},df=Ro();function pf(r){return globalThis.Buffer!=null?ft(r):df(r)}var ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new ae(Oo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ae(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Uo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(jr,10,mt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=mt.fromBigInt(t);return this._push(jr,e.length(),e)}uint64Number(t){return this._push(Le,lt(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=mt.fromBigInt(t).zzEncode();return this._push(jr,e.length(),e)}sint64Number(t){let e=mt.fromNumber(t).zzEncode();return this._push(jr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(No,1,t?1:0)}fixed32(t){return this._push(cr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=mt.fromBigInt(t);return this._push(cr,4,e.lo)._push(cr,4,e.hi)}fixed64Number(t){let e=mt.fromNumber(t);return this._push(cr,4,e.lo)._push(cr,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(Gi,4,t)}double(t){return this._push(Zi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(No,1,0):this.uint32(e)._push(gf,e,t)}string(t){let e=Xi(t);return e!==0?this.uint32(e)._push(Co,e,t):this._push(No,1,0)}fork(){return this.states=new ko(this),this.head=this.tail=new ae(Oo,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 ae(Oo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=pf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function No(r,t,e){t[e]=r&255}function mf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Uo=class extends ae{next;constructor(t,e){super(mf,t,e),this.next=void 0}};function jr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function cr(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 gf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ur.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(yf,t,r),this},ur.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(bf,t,r),this});function yf(r,t,e){t.set(r,e)}function bf(r,t,e){r.length<40?Co(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(M(r),e)}function Mo(){return new ur}function kt(r,t){let e=Mo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Pe;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Pe||(Pe={}));function Gr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Re(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Gr("enum",Pe.VARINT,e,n)}function Ut(r,t){return Gr("message",Pe.LENGTH_DELIMITED,r,t)}var $r=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var gt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(gt||(gt={}));var Fo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Fo||(Fo={}));(function(r){r.codec=()=>Re(Fo)})(gt||(gt={}));var fr;(function(r){let t;r.codec=()=>(t==null&&(t=Ut((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=gt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>kt(e,r.codec()),r.decode=(e,n)=>Nt(e,r.codec(),n)})(fr||(fr={}));var Ko;(function(r){let t;r.codec=()=>(t==null&&(t=Ut((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=gt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>kt(e,r.codec()),r.decode=(e,n)=>Nt(e,r.codec(),n)})(Ko||(Ko={}));var Zr=class extends _e{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Js(t);let n=Je(e);if(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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Pt(s)}update(t){return ve(this),this.iHash.update(t),this}digestInto(t){ve(this),nt(t,this.outputLen),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||(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()}},zo=(r,t,e)=>new Zr(r,t).update(e).digest();zo.create=(r,t)=>new Zr(r,t);function ta(r){r.lowS!==void 0&&Ot("lowS",r.lowS),r.prehash!==void 0&&Ot("prehash",r.prehash)}var qo=class extends Error{constructor(t=""){super(t)}},Mt={Err:qo,_tlv:{encode:(r,t)=>{let{Err:e}=Mt;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=or(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?or(o.length/2|128):"";return or(r)+s+o+t},decode(r,t){let{Err:e}=Mt,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 u=o&127;if(!u)throw new e("tlv.decode(long): indefinite length not supported");if(u>4)throw new e("tlv.decode(long): byte length is too big");let c=t.subarray(n,n+u);if(c.length!==u)throw new e("tlv.decode: length bytes not complete");if(c[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of c)i=i<<8|l;if(n+=u,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}=Mt;if(r<lr)throw new t("integer: negative integers are not allowed");let e=or(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Mt;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 Ie(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Mt,o=q("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:u}=n.decode(2,s),{v:c,l}=n.decode(2,u);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(c)}},hexFromSig(r){let{_tlv:t,_int:e}=Mt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},lr=BigInt(0),hr=BigInt(1),wf=BigInt(2),Wr=BigInt(3),Ef=BigInt(4);function _f(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function ea(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=q("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let u=new Uint8Array(n);u.set(a,u.length-a.length),a=u}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function Sf(r,t={}){let{Fp:e,Fn:n}=Ur("weierstrass",r,t),{h:o,n:s}=r;Zt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(I,p,E){let{x:g,y:x}=p.toAffine(),_=e.toBytes(g);if(Ot("isCompressed",E),E){a();let B=!e.isOdd(x);return pt(ra(B),_)}else return pt(Uint8Array.of(4),_,e.toBytes(x))}function c(I){nt(I);let p=e.BYTES,E=p+1,g=2*p+1,x=I.length,_=I[0],B=I.subarray(1);if(x===E&&(_===2||_===3)){let A=e.fromBytes(B);if(!e.isValid(A))throw new Error("bad point: is not on curve, wrong x");let D=h(A),O;try{O=e.sqrt(D)}catch(U){let N=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+N)}a();let R=e.isOdd(O);return(_&1)===1!==R&&(O=e.neg(O)),{x:A,y:O}}else if(x===g&&_===4){let A=e.fromBytes(B.subarray(p*0,p*1)),D=e.fromBytes(B.subarray(p*1,p*2));if(!m(A,D))throw new Error("bad point: is not on curve");return{x:A,y:D}}else throw new Error(`bad point: got length ${x}, expected compressed=${E} or uncompressed=${g}`)}let l=t.toBytes||u,f=t.fromBytes||c,h=_f(e,r.a,r.b);function m(I,p){let E=e.sqr(p),g=h(I);return e.eql(E,g)}if(!m(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let b=e.mul(e.pow(r.a,Wr),Ef),w=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(b,w)))throw new Error("bad curve params: a or b");function d(I,p,E=!1){if(!e.isValid(p)||E&&e.is0(p))throw new Error(`bad point coordinate ${I}`);return p}function S(I){if(!(I instanceof y))throw new Error("ProjectivePoint expected")}let T=Te((I,p)=>{let{px:E,py:g,pz:x}=I;if(e.eql(x,e.ONE))return{x:E,y:g};let _=I.is0();p==null&&(p=_?e.ONE:e.inv(x));let B=e.mul(E,p),A=e.mul(g,p),D=e.mul(x,p);if(_)return{x:e.ZERO,y:e.ZERO};if(!e.eql(D,e.ONE))throw new Error("invZ was invalid");return{x:B,y:A}}),v=Te(I=>{if(I.is0()){if(t.allowInfinityPoint&&!e.is0(I.py))return;throw new Error("bad point: ZERO")}let{x:p,y:E}=I.toAffine();if(!e.isValid(p)||!e.isValid(E))throw new Error("bad point: x or y not field elements");if(!m(p,E))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function P(I,p,E,g,x){return E=new y(e.mul(E.px,I),E.py,E.pz),p=De(g,p),E=De(x,E),p.add(E)}class y{constructor(p,E,g){this.px=d("x",p),this.py=d("y",E,!0),this.pz=d("z",g),Object.freeze(this)}static fromAffine(p){let{x:E,y:g}=p||{};if(!p||!e.isValid(E)||!e.isValid(g))throw new Error("invalid affine point");if(p instanceof y)throw new Error("projective point not allowed");return e.is0(E)&&e.is0(g)?y.ZERO:new y(E,g,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(p){return Or(y,"pz",p)}static fromBytes(p){return nt(p),y.fromHex(p)}static fromHex(p){let E=y.fromAffine(f(q("pointHex",p)));return E.assertValidity(),E}static fromPrivateKey(p){let E=ea(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return y.BASE.multiply(E(p))}static msm(p,E){return kr(y,n,p,E)}precompute(p=8,E=!0){return C.setWindowSize(this,p),E||this.multiply(Wr),this}_setWindowSize(p){this.precompute(p)}assertValidity(){v(this)}hasEvenY(){let{y:p}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(p)}equals(p){S(p);let{px:E,py:g,pz:x}=this,{px:_,py:B,pz:A}=p,D=e.eql(e.mul(E,A),e.mul(_,x)),O=e.eql(e.mul(g,A),e.mul(B,x));return D&&O}negate(){return new y(this.px,e.neg(this.py),this.pz)}double(){let{a:p,b:E}=r,g=e.mul(E,Wr),{px:x,py:_,pz:B}=this,A=e.ZERO,D=e.ZERO,O=e.ZERO,R=e.mul(x,x),$=e.mul(_,_),U=e.mul(B,B),N=e.mul(x,_);return N=e.add(N,N),O=e.mul(x,B),O=e.add(O,O),A=e.mul(p,O),D=e.mul(g,U),D=e.add(A,D),A=e.sub($,D),D=e.add($,D),D=e.mul(A,D),A=e.mul(N,A),O=e.mul(g,O),U=e.mul(p,U),N=e.sub(R,U),N=e.mul(p,N),N=e.add(N,O),O=e.add(R,R),R=e.add(O,R),R=e.add(R,U),R=e.mul(R,N),D=e.add(D,R),U=e.mul(_,B),U=e.add(U,U),R=e.mul(U,N),A=e.sub(A,R),O=e.mul(U,$),O=e.add(O,O),O=e.add(O,O),new y(A,D,O)}add(p){S(p);let{px:E,py:g,pz:x}=this,{px:_,py:B,pz:A}=p,D=e.ZERO,O=e.ZERO,R=e.ZERO,$=r.a,U=e.mul(r.b,Wr),N=e.mul(E,_),Z=e.mul(g,B),Y=e.mul(x,A),rt=e.add(E,g),F=e.add(_,B);rt=e.mul(rt,F),F=e.add(N,Z),rt=e.sub(rt,F),F=e.add(E,x);let it=e.add(_,A);return F=e.mul(F,it),it=e.add(N,Y),F=e.sub(F,it),it=e.add(g,x),D=e.add(B,A),it=e.mul(it,D),D=e.add(Z,Y),it=e.sub(it,D),R=e.mul($,F),D=e.mul(U,Y),R=e.add(D,R),D=e.sub(Z,R),R=e.add(Z,R),O=e.mul(D,R),Z=e.add(N,N),Z=e.add(Z,N),Y=e.mul($,Y),F=e.mul(U,F),Z=e.add(Z,Y),Y=e.sub(N,Y),Y=e.mul($,Y),F=e.add(F,Y),N=e.mul(Z,F),O=e.add(O,N),N=e.mul(it,F),D=e.mul(rt,D),D=e.sub(D,N),N=e.mul(rt,Z),R=e.mul(it,R),R=e.add(R,N),new y(D,O,R)}subtract(p){return this.add(p.negate())}is0(){return this.equals(y.ZERO)}multiply(p){let{endo:E}=t;if(!n.isValidNot0(p))throw new Error("invalid scalar: out of range");let g,x,_=B=>C.wNAFCached(this,B,y.normalizeZ);if(E){let{k1neg:B,k1:A,k2neg:D,k2:O}=E.splitScalar(p),{p:R,f:$}=_(A),{p:U,f:N}=_(O);x=$.add(N),g=P(E.beta,R,U,B,D)}else{let{p:B,f:A}=_(p);g=B,x=A}return y.normalizeZ([g,x])[0]}multiplyUnsafe(p){let{endo:E}=t,g=this;if(!n.isValid(p))throw new Error("invalid scalar: out of range");if(p===lr||g.is0())return y.ZERO;if(p===hr)return g;if(C.hasPrecomputes(this))return this.multiply(p);if(E){let{k1neg:x,k1:_,k2neg:B,k2:A}=E.splitScalar(p),{p1:D,p2:O}=Ni(y,g,_,A);return P(E.beta,D,O,x,B)}else return C.wNAFCachedUnsafe(g,p)}multiplyAndAddUnsafe(p,E,g){let x=this.multiplyUnsafe(E).add(p.multiplyUnsafe(g));return x.is0()?void 0:x}toAffine(p){return T(this,p)}isTorsionFree(){let{isTorsionFree:p}=t;return o===hr?!0:p?p(y,this):C.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:p}=t;return o===hr?this:p?p(y,this):this.multiplyUnsafe(o)}toBytes(p=!0){return Ot("isCompressed",p),this.assertValidity(),l(y,this,p)}toRawBytes(p=!0){return this.toBytes(p)}toHex(p=!0){return vt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}y.BASE=new y(r.Gx,r.Gy,e.ONE),y.ZERO=new y(e.ZERO,e.ONE,e.ZERO),y.Fp=e,y.Fn=n;let L=n.BITS,C=Nr(y,t.endo?Math.ceil(L/2):L);return y}function ra(r){return Uint8Array.of(r?2:3)}function vf(r,t,e={}){Zt(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||tr,o=t.hmac||((g,...x)=>zo(t.hash,g,pt(...x))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:u}=i;function c(g){let x=a>>hr;return g>x}function l(g){return c(g)?i.neg(g):g}function f(g,x){if(!i.isValidNot0(x))throw new Error(`invalid signature ${g}: out of range 1..CURVE.n`)}class h{constructor(x,_,B){f("r",x),f("s",_),this.r=x,this.s=_,B!=null&&(this.recovery=B),Object.freeze(this)}static fromCompact(x){let _=i.BYTES,B=q("compactSignature",x,_*2);return new h(i.fromBytes(B.subarray(0,_)),i.fromBytes(B.subarray(_,_*2)))}static fromDER(x){let{r:_,s:B}=Mt.toSig(q("DER",x));return new h(_,B)}assertValidity(){}addRecoveryBit(x){return new h(this.r,this.s,x)}recoverPublicKey(x){let _=s.ORDER,{r:B,s:A,recovery:D}=this;if(D==null||![0,1,2,3].includes(D))throw new Error("recovery id invalid");if(a*wf<_&&D>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=D===2||D===3?B+a:B;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let $=s.toBytes(R),U=r.fromHex(pt(ra((D&1)===0),$)),N=i.inv(R),Z=v(q("msgHash",x)),Y=i.create(-Z*N),rt=i.create(A*N),F=r.BASE.multiplyUnsafe(Y).add(U.multiplyUnsafe(rt));if(F.is0())throw new Error("point at infinify");return F.assertValidity(),F}hasHighS(){return c(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i.neg(this.s),this.recovery):this}toBytes(x){if(x==="compact")return pt(i.toBytes(this.r),i.toBytes(this.s));if(x==="der")return Ae(Mt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return vt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return vt(this.toBytes("compact"))}}let m=ea(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),b={isValidPrivateKey(g){try{return m(g),!0}catch{return!1}},normPrivateKeyToScalar:m,randomPrivateKey:()=>{let g=a;return Di(n(go(g)),g)},precompute(g=8,x=r.BASE){return x.precompute(g,!1)}};function w(g,x=!0){return r.fromPrivateKey(g).toBytes(x)}function d(g){if(typeof g=="bigint")return!1;if(g instanceof r)return!0;let _=q("key",g).length,B=s.BYTES,A=B+1,D=2*B+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===A))return _===A||_===D}function S(g,x,_=!0){if(d(g)===!0)throw new Error("first arg must be private key");if(d(x)===!1)throw new Error("second arg must be public key");return r.fromHex(x).multiply(m(g)).toBytes(_)}let T=t.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");let x=Ie(g),_=g.length*8-u;return _>0?x>>BigInt(_):x},v=t.bits2int_modN||function(g){return i.create(T(g))},P=ne(u);function y(g){return $t("num < 2^"+u,g,lr,P),i.toBytes(g)}function L(g,x,_=C){if(["recovered","canonical"].some(rt=>rt in _))throw new Error("sign() legacy options not supported");let{hash:B}=t,{lowS:A,prehash:D,extraEntropy:O}=_;A==null&&(A=!0),g=q("msgHash",g),ta(_),D&&(g=q("prehashed msgHash",B(g)));let R=v(g),$=m(x),U=[y($),y(R)];if(O!=null&&O!==!1){let rt=O===!0?n(s.BYTES):O;U.push(q("extraEntropy",rt))}let N=pt(...U),Z=R;function Y(rt){let F=T(rt);if(!i.isValidNot0(F))return;let it=i.inv(F),qe=r.BASE.multiply(F).toAffine(),pe=i.create(qe.x);if(pe===lr)return;let Yt=i.create(it*i.create(Z+pe*$));if(Yt===lr)return;let Cn=(qe.x===pe?0:2)|Number(qe.y&hr),me=Yt;return A&&c(Yt)&&(me=l(Yt),Cn^=1),new h(pe,me,Cn)}return{seed:N,k2sig:Y}}let C={lowS:t.lowS,prehash:!1},I={lowS:t.lowS,prehash:!1};function p(g,x,_=C){let{seed:B,k2sig:A}=L(g,x,_);return xi(t.hash.outputLen,i.BYTES,o)(B,A)}r.BASE.precompute(8);function E(g,x,_,B=I){let A=g;x=q("msgHash",x),_=q("publicKey",_),ta(B);let{lowS:D,prehash:O,format:R}=B;if("strict"in B)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&!["compact","der","js"].includes(R))throw new Error('format must be "compact", "der" or "js"');let $=typeof A=="string"||Se(A),U=!$&&!R&&typeof A=="object"&&A!==null&&typeof A.r=="bigint"&&typeof A.s=="bigint";if(!$&&!U)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let N,Z;try{if(U)if(R===void 0||R==="js")N=new h(A.r,A.s);else throw new Error("invalid format");if($){try{R!=="compact"&&(N=h.fromDER(A))}catch(me){if(!(me instanceof Mt.Err))throw me}!N&&R!=="der"&&(N=h.fromCompact(A))}Z=r.fromHex(_)}catch{return!1}if(!N||D&&N.hasHighS())return!1;O&&(x=t.hash(x));let{r:Y,s:rt}=N,F=v(x),it=i.inv(rt),qe=i.create(F*it),pe=i.create(Y*it),Yt=r.BASE.multiplyUnsafe(qe).add(Z.multiplyUnsafe(pe));return Yt.is0()?!1:i.create(Yt.x)===Y}return Object.freeze({getPublicKey:w,getSharedSecret:S,sign:p,verify:E,utils:b,Point:r,Signature:h})}function Af(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=wt(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function If(r){let{CURVE:t,curveOpts:e}=Af(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function Bf(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function na(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=If(r),o=Sf(t,e),s=vf(o,n,e);return Bf(r,s)}function oa(r,t){let e=n=>na({...r,hash:n});return{...e(t),create:e}}var Yr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},M0=BigInt(0),Tf=BigInt(1),Ho=BigInt(2),sa=(r,t)=>(r+t/Ho)/t;function Df(r){let t=Yr.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),u=BigInt(88),c=r*r*r%t,l=c*c*r%t,f=H(l,e,t)*l%t,h=H(f,e,t)*l%t,m=H(h,Ho,t)*c%t,b=H(m,o,t)*m%t,w=H(b,s,t)*b%t,d=H(w,a,t)*w%t,S=H(d,u,t)*d%t,T=H(S,a,t)*w%t,v=H(T,e,t)*l%t,P=H(v,i,t)*b%t,y=H(P,n,t)*c%t,L=H(y,Ho,t);if(!Vo.eql(Vo.sqr(L),r))throw new Error("Cannot find square root");return L}var Vo=wt(Yr.p,void 0,void 0,{sqrt:Df}),Oe=oa({...Yr,Fp:Vo,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Yr.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Tf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=sa(s*r,t),u=sa(-n*r,t),c=j(r-a*e-u*o,t),l=j(-a*n-u*s,t),f=c>i,h=l>i;if(f&&(c=t-c),h&&(l=t-l),c>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:c,k2neg:h,k2:l}}}},pi);function ia(r,t,e,n){let o=Ze.digest(e instanceof Uint8Array?e:e.subarray());if(qr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Oe.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new ir(String(s))});try{return n?.signal?.throwIfAborted(),Oe.verify(t,o.digest,r)}catch(s){throw new ir(String(s))}}var Xr=class{type="secp256k1";raw;_key;constructor(t){this._key=ca(t),this.raw=aa(this._key)}toMultihash(){return yt.digest(Ee(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return V.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){return ia(this._key,e,t,n)}};function ua(r){return new Xr(r)}function aa(r){return Oe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ca(r){try{return Oe.ProjectivePoint.fromHex(r),r}catch(t){throw new vr(String(t))}}function fa(r){let{Type:t,Data:e}=fr.decode(r.digest),n=e??new Uint8Array;switch(t){case gt.Ed25519:return Hi(n);case gt.secp256k1:return ua(n);case gt.ECDSA:return Ws(n);default:throw new He}}function Ee(r){return fr.encode({Type:gt[r.type],Data:r.raw})}var la=Symbol.for("nodejs.util.inspect.custom"),Cf=114,dr=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()})`}[Ln]=!0;toString(){return this.string==null&&(this.string=V.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return X.createV1(Cf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return at(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return at(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[la](){return`PeerId(${this.toString()})`}},Qr=class extends dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Jr=class extends dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},tn=class extends dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Lf=2336,en=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=yt.digest(M(this.url))}[la](){return`PeerId(${this.url})`}[Ln]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return X.createV1(Lf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function rn(r){if(Rf(r))return new Qr({multihash:r});if(Pf(r))try{let t=fa(r);if(t.type==="Ed25519")return new Jr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new tn({multihash:r,publicKey:t})}catch{let e=z(r.digest);return new en(new URL(e))}throw new Ar("Supplied PeerID Multihash is invalid")}function Pf(r){return r.code===yt.code}function Rf(r){return r.code===Ze.code}function jo(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 nn(r){let t=Qt(V.decode(`z${r}`));return rn(t)}var on=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 jo(this.set.entries(),t=>{let e=nn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=nn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return jo(this.set.values(),t=>nn(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 Go(){return new on}var $o={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},da=new globalThis.TextEncoder;function Of(r,t){let e=$o[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 Nf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=$o[t],o=ha[t],s=r;for(;s.length>0;){let i=da.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 Zo(r,{size:t=32,utf8Buffer:e}={}){if(!$o[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 Nf(r,t,e);r=da.encode(r)}return Of(r,t)}var pr={hash:r=>Number(Zo(r,{size:32})),hashV:(r,t)=>kf(pr.hash(r,t))};function kf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),M(t,"base16")}var Wo=64,_t=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Wo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=bt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?at(this.fp,t.fp):!1}};function ce(r,t){return Math.floor(Math.random()*(t-r))+r}var ue=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof _t))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 _t))throw new TypeError("Invalid Fingerprint");let e=ce(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Uf=500,mr=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??pr,this.seed=t.seed??ce(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=M(t));let e=new _t(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 ue(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ue(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[ce(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ue(this.bucketSize));for(let a=0;a<Uf;a++){let u=this.buckets[i].swap(e);if(u!=null&&(i=(i^u.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ue(this.bucketSize)),this.buckets[i].add(u)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=M(t));let e=new _t(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=M(t));let e=new _t(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}},Mf={1:.5,2:.84,4:.95,8:.98};function Ff(r=.001){return r>.002?2:r>1e-5?4:8}function pa(r,t=.001){let e=Ff(t),n=Mf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Wo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var sn=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??pr,this.seed=t.seed??ce(0,Math.pow(2,10)),this.filterSeries=[new mr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=M(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 mr({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=M(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=M(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function Yo(r,t=.001,e){return new sn({...pa(r,t),...e??{}})}var an=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 u=a==="0",c=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(s*=t,s+=l,s>c||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&u&&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 ma=45,Kf=15,Ne=new an;function cn(r){if(!(r.length>Kf))return Ne.new(r).parseWith(()=>Ne.readIPv4Addr())}function un(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ma))return Ne.new(r).parseWith(()=>Ne.readIPv6Addr())}function ke(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>ma)return;let e=Ne.new(r).parseWith(()=>Ne.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function ga(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function ya(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Xo(r){switch(r.length){case fe:return r.join(".");case le:{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 ba(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 xa(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var fe=4,le=16,vg=parseInt("0xFFFF",16),zf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function gr(r,t){t.length===le&&r.length===fe&&ga(t,0,11)&&(t=t.slice(12)),t.length===fe&&r.length===le&&ya(r,zf,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 wa(r,t){if(typeof t=="string"&&(t=ke(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=fe,o=cn(t);if(o==null&&(n=le,o=un(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:gr(o,i),mask:i}}function Jo(r,t){if(t!==8*fe&&t!==8*le)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 Ue=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Qo(t));else{let n=ke(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=ke(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Jo(o,8*n.length);this.network=gr(n,this.mask)}}contains(t){return wa({network:this.network,mask:this.mask},t)}toString(){let t=ba(this.mask),e=t!==-1?String(t):xa(this.mask);return Xo(this.network)+"/"+e}};function Ea(r,t){return new Ue(r).contains(t)}var et=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ft=class extends Error{static name="ValidationError";name="ValidationError"},yr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},fn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Me(r){return!!cn(r)}function ln(r){return!!un(r)}function es(r){return t=>z(t,r)}function rs(r){return t=>M(t,r)}function Fe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function he(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function _a(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=M(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=he(n);return Ct([e,o],e.length+o.length)}function Sa(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=qt.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=he(n);return Ct([e,o],e.length+o.length)}function ns(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=z(t,"base32"),o=Fe(e);return`${n}:${o}`}var os=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 et("Invalid byte value in IP address");t[n]=o}),t},va=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Me(e[n]),i;s&&(i=os(e[n]),e[n]=z(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,z(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 et("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Aa=function(r){if(r.byteLength!==4)throw new et("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Ia=function(r){if(r.byteLength!==16)throw new et("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 et(`Invalid IPv6 address "${e}"`)}};function Ba(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new et(`Invalid IPv6 address "${r}"`)}}var ts=Object.values(We).map(r=>r.decoder),qf=function(){let r=ts[0].or(ts[1]);return ts.slice(2).forEach(t=>r=r.or(t)),r}();function Ta(r){return qf.decode(r)}function Da(r){return t=>r.encoder.encode(t)}function Hf(r){if(parseInt(r).toString()!==r)throw new Ft("Value must be an integer")}function Vf(r){if(r<0)throw new Ft("Value must be a positive integer, or zero")}function jf(r){return t=>{if(t>r)throw new Ft(`Value must be smaller than or equal to ${r}`)}}function Gf(...r){return t=>{for(let e of r)e(t)}}var br=Gf(Hf,Vf,jf(65535));var J=-1,ss=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 fn(`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 ss,_l=[{code:4,name:"ip4",size:32,valueToBytes:os,bytesToValue:Aa,validate:r=>{if(!Me(r))throw new Ft(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:he,bytesToValue:Fe,validate:br},{code:273,name:"udp",size:16,valueToBytes:he,bytesToValue:Fe,validate:br},{code:33,name:"dccp",size:16,valueToBytes:he,bytesToValue:Fe,validate:br},{code:41,name:"ip6",size:128,valueToBytes:va,bytesToValue:Ia,stringToValue:Ba,validate:r=>{if(!ln(r))throw new Ft(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:J},{code:43,name:"ipcidr",size:8,bytesToValue:es("base10"),valueToBytes:rs("base10")},{code:53,name:"dns",size:J,resolvable:!0},{code:54,name:"dns4",size:J,resolvable:!0},{code:55,name:"dns6",size:J,resolvable:!0},{code:56,name:"dnsaddr",size:J,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:he,bytesToValue:Fe,validate:br},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:J,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:J,bytesToValue:es("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?rs("base58btc")(r):X.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ns,valueToBytes:_a},{code:445,name:"onion3",size:296,bytesToValue:ns,valueToBytes:Sa},{code:446,name:"garlic64",size:J},{code:447,name:"garlic32",size:J},{code:448,name:"tls"},{code:449,name:"sni",size:J},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:J,bytesToValue:Da(Gn),valueToBytes:Ta},{code:480,name:"http"},{code:481,name:"http-path",size:J,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:J}];_l.forEach(r=>{ht.addProtocol(r)});function Ca(r){let t=[],e=0;for(;e<r.length;){let n=ar(r,e),o=ht.getProtocol(n),s=lt(n),i=Sl(o,r,e+s),a=0;i>0&&o.size===J&&(a=lt(i));let u=s+a+i,c={code:n,name:o.name,bytes:r.subarray(e,e+u)};if(i>0){let l=e+s+a,f=r.subarray(l,l+i);c.value=o.bytesToValue?.(f)??z(f)}t.push(c),e+=u}return t}function La(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=ht.getProtocol(n.code),s=lt(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??M(n.value),a=i.byteLength,o.size===J&&(u=lt(a)));let c=new Uint8Array(s+u+a),l=0;Le(n.code,c,l),l+=s,i!=null&&(o.size===J&&(Le(a,c,l),l+=u),c.set(i,l)),n.bytes=c}e.push(n.bytes),t+=n.bytes.byteLength}return Ct(e,t)}function Pa(r){if(r.charAt(0)!=="/")throw new et('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 u=ht.getProtocol(o);if(e==="protocol"){if(u.size==null||u.size===0){t.push({code:u.code,name:u.name}),n="",o="",e="protocol";continue}else if(a)throw new et(`Component ${o} was missing value`);e="value"}else if(e==="value"){let c={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new et(`Component ${o} was missing value`);c.value=u.stringToValue?.(n)??n}t.push(c),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new et("Incomplete multiaddr");return t}function Ra(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=ht.getProtocol(t.code);if(e==null)throw new et(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Sl(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:ar(t,e)}var vl=Symbol.for("nodejs.util.inspect.custom"),hs=Symbol.for("@multiformats/multiaddr"),Al=[53,54,55,56],ls=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Il(r){if(r==null&&(r="/"),Na(r))return r.getComponents();if(r instanceof Uint8Array)return Ca(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Pa(r);if(Array.isArray(r))return r;throw new et("Must be a string, Uint8Array, Component[], or another Multiaddr")}var mn=class r{[hs]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Il(t),e.validate!==!1&&Bl(this)}get bytes(){return this.#r==null&&(this.#r=La(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Ra(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:u,value:c}of this.#t)a===42&&(s=`%${c??""}`),Al.includes(a)&&(e="tcp",o=443,n=`${c??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=u==="tcp"?"tcp":"udp",o=parseInt(c??"")),(a===4||a===41)&&(e="tcp",n=`${c??""}${s}`,t=a===41?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=ht.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=ht.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??M(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}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 yr(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);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})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?z(V.decode(`z${n}`),"base58btc"):z(X.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(ht.getProtocol(t.code).path)return t.value??null;return null}equals(t){return at(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Oa.get(e.name);if(n==null)throw new ls(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>wr(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[vl](){return`Multiaddr(${this.toString()})`}};function Bl(r){r.getComponents().forEach(t=>{let e=ht.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}var Oa=new Map;function Na(r){return!!r?.[hs]}function wr(r){return new mn(r)}function ka(r){let t=ht.getProtocol(r);return{code:t.code,size:t.size??0,name:t.name,resolvable:!!t.resolvable,path:!!t.path}}function Ua(r){try{for(let{code:t,value:e}of r.getComponents())if(e!=null&&t===41)return Ea("2000::/3",e)}catch{}return!1}var Fa=nc(Ma(),1),Tl=["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"],Dl=Tl.map(r=>new Fa.Netmask(r));function ds(r){for(let t of Dl)if(t.contains(r))return!0;return!1}function Cl(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Ll(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 ds(o)}function Pl(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 ds(e)}function Ol(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 Ka(r){if(Me(r))return ds(r);if(Cl(r))return Ll(r);if(Pl(r))return Rl(r);if(ln(r))return Ol(r)}function za(r){try{for(let{code:t}of r.getComponents())if(t!==42)return t===4||t===41}catch{}return!1}function ps(r){try{if(!za(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:Ka(t)??!1}catch{}return!0}function St(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var gn=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}},ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new gn(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 gn(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 qa(r={}){return Nl(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 Nl(r,t){t=t??{};let e=t.onEnd,n=new ze,o,s,i,a=St(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,S)=>{s=T=>{s=null,n.push(T);try{d(r(n))}catch(v){S(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=St()})}},c=d=>s!=null?s(d):(n.push(d),o),l=d=>(n=new ze,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:d})},h=d=>i?o:(i=!0,d!=null?l(d):c({done:!0})),m=()=>(n=new ze,h(),{done:!0}),b=d=>(h(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:m,throw:b,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let S=d?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let T,v;S!=null&&(T=new Promise((P,y)=>{v=()=>{y(new ms)},S.addEventListener("abort",v)}));try{await Promise.race([a.promise,T])}finally{v!=null&&S!=null&&S?.removeEventListener("abort",v)}}},e==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(d){return w.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return w.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return w.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return w.readableLength},onEmpty:d=>w.onEmpty(d)},o}var gs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function yn(r,t,e,n){let o=new gs(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",l),r.removeEventListener(t,u),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,c)}let u=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),i(h);return}a(),s(f)},c=f=>{a(),i(f.detail)},l=()=>{a(),i(o)};e?.addEventListener("abort",l),r.addEventListener(t,u),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,c)})}function _r(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var bn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var xn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function de(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new xn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new xn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var wn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=St(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Bt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function kl(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var En=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=kl(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Bt),this.cleanup())}async join(t={}){let e=new wn(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 de(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 _n=class extends Ir{concurrency;maxSize;queue;pending;sort;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,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=_r(this.emitEmpty.bind(this),1),this.emitIdle=_r(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new bn;let n=new En(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("error",{detail:o}),this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Bt)}),this.clear()}async onEmpty(t){this.size!==0&&await yn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await yn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await yn(this,"idle",t?.signal)}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=qa({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),e.end(u)},o=u=>{u.detail!=null&&e.push(u.detail)},s=u=>{n(u.detail)},i=()=>{n()},a=()=>{n(new Bt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var Sn=class extends _n{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function vn(r){let t=new globalThis.AbortController;function e(){t.abort();for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}function Ha(r,t,e){let n,o,s=!1;function i(){let c={signal:o.signal};if(e?.timeout!=null){let l=vn([o.signal,AbortSignal.timeout(e.timeout)]);c.signal=l}s=!0,Promise.resolve().then(async()=>{await r(c)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=_r(i,e?.debounce??100),u=!1;return{setInterval:c=>{t!==c&&(t=c,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:c=>{e??={},e.timeout=c},run:()=>{s||(clearTimeout(n),a())},start:()=>{u||(u=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),u=!1}}}var ys=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 ys({name:t,metrics:e}):n=new Map,n}var bs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=St(),this.haveNext=St()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=St(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=St(),await de(this.readNext.promise,e?.signal,e)}};function ja(){return new bs}var An=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ga(r,t){let e=ja();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new W;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:u,value:c}=await de(n.next(),i?.signal);return u===!0?null:c}for(;o.byteLength<i.bytes;){let{value:u,done:c}=await de(n.next(),i?.signal);if(c===!0)throw new An("unexpected end of input");o.append(u)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var In=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Bn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Tn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $a(r,t={}){let e=Ga(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=lt(t.maxDataLength));let n=t?.lengthDecoder??ar,o=t?.lengthEncoder??Vi;return{read:async i=>{let a=-1,u=new W;for(;;){u.append(await e.read({...i,bytes:1}));try{a=n(u)}catch(c){if(c instanceof RangeError)continue;throw c}if(a<0)throw new In("Invalid message length");if(t?.maxLengthLength!=null&&u.byteLength>t.maxLengthLength)throw new Tn("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Bn("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new W(o(i.byteLength),i),a)},writeV:async(i,a)=>{let u=new W(...i.flatMap(c=>[o(c.byteLength),c]));await e.write(u,a)},unwrap:()=>e.unwrap()}}function xs(r,t){let e=$a(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 Za="libp2p",Wa="autonat",Ya="1.0.0";var K;(function(r){let t;(function(c){c.DIAL="DIAL",c.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(c){c[c.DIAL=0]="DIAL",c[c.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(c){c.codec=()=>Re(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(c){c.OK="OK",c.E_DIAL_ERROR="E_DIAL_ERROR",c.E_DIAL_REFUSED="E_DIAL_REFUSED",c.E_BAD_REQUEST="E_BAD_REQUEST",c.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(c){c[c.OK=0]="OK",c[c.E_DIAL_ERROR=100]="E_DIAL_ERROR",c[c.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",c[c.E_BAD_REQUEST=200]="E_BAD_REQUEST",c[c.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(c){c.codec=()=>Re(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(c){let l;c.codec=()=>(l==null&&(l=Ut((f,h,m={})=>{if(m.lengthDelimited!==!1&&h.fork(),f.id!=null&&(h.uint32(10),h.bytes(f.id)),f.addrs!=null)for(let b of f.addrs)h.uint32(18),h.bytes(b);m.lengthDelimited!==!1&&h.ldelim()},(f,h,m={})=>{let b={addrs:[]},w=h==null?f.len:f.pos+h;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{b.id=f.bytes();break}case 2:{if(m.limits?.addrs!=null&&b.addrs.length===m.limits.addrs)throw new $r('Decode error - map field "addrs" had too many elements');b.addrs.push(f.bytes());break}default:{f.skipType(d&7);break}}}return b})),l),c.encode=f=>kt(f,c.codec()),c.decode=(f,h)=>Nt(f,c.codec(),h)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(c){let l;c.codec=()=>(l==null&&(l=Ut((f,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),f.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(f.peer,h)),m.lengthDelimited!==!1&&h.ldelim()},(f,h,m={})=>{let b={},w=h==null?f.len:f.pos+h;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{b.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:m.limits?.peer});break}default:{f.skipType(d&7);break}}}return b})),l),c.encode=f=>kt(f,c.codec()),c.decode=(f,h)=>Nt(f,c.codec(),h)})(i=r.Dial||(r.Dial={}));let a;(function(c){let l;c.codec=()=>(l==null&&(l=Ut((f,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),f.status!=null&&(h.uint32(8),r.ResponseStatus.codec().encode(f.status,h)),f.statusText!=null&&(h.uint32(18),h.string(f.statusText)),f.addr!=null&&(h.uint32(26),h.bytes(f.addr)),m.lengthDelimited!==!1&&h.ldelim()},(f,h,m={})=>{let b={},w=h==null?f.len:f.pos+h;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{b.status=r.ResponseStatus.codec().decode(f);break}case 2:{b.statusText=f.string();break}case 3:{b.addr=f.bytes();break}default:{f.skipType(d&7);break}}}return b})),l),c.encode=f=>kt(f,c.codec()),c.decode=(f,h)=>Nt(f,c.codec(),h)})(a=r.DialResponse||(r.DialResponse={}));let u;r.codec=()=>(u==null&&(u=Ut((c,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),c.type!=null&&(l.uint32(8),r.MessageType.codec().encode(c.type,l)),c.dial!=null&&(l.uint32(18),r.Dial.codec().encode(c.dial,l)),c.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(c.dialResponse,l)),f.lengthDelimited!==!1&&l.ldelim()},(c,l,f={})=>{let h={},m=l==null?c.len:c.pos+l;for(;c.pos<m;){let b=c.uint32();switch(b>>>3){case 1:{h.type=r.MessageType.codec().decode(c);break}case 2:{h.dial=r.Dial.codec().decode(c,c.uint32(),{limits:f.limits?.dial});break}case 3:{h.dialResponse=r.DialResponse.codec().decode(c,c.uint32(),{limits:f.limits?.dialResponse});break}default:{c.skipType(b&7);break}}}return h})),u),r.encode=c=>kt(c,r.codec()),r.decode=(c,l)=>Nt(c,r.codec(),l)})(K||(K={}));var ql=4,Hl=8,Dn=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??Za}/${Wa}/${Ya}`,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=Ha(this.findRandomPeers.bind(this),6e4),this.addressFilter=Yo(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Es]=["@libp2p/autonat"];get[_s](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream - %e",e)})},{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=vn([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){let e=AbortSignal.timeout(this.timeout);let n=xs(t.stream,{maxDataLength:this.maxMessageSize}).pb(K);try{let o=await n.read({signal:e}),s=await this.handleAutonatMessage(o,t.connection,{signal:e});await n.write(s,{signal:e}),await n.unwrap().unwrap().close({signal:e})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.stream.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(f=>f.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.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:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Qt(a.id);i=rn(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.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:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let u=a.addrs.map(f=>wr(f)).filter(f=>{let h=f.toOptions();return ps(f)?!1:h.host!==e.remoteAddr.toOptions().host?(this.log.trace("not dialing %a - target host did not match remote host %a",f,e.remoteAddr),!1):o.includes(h.host)?!1:this.components.transportManager.dialTransportForMultiaddr(f)==null?(this.log.trace("not dialing %a - transport unsupported",f),!1):!0}).map(f=>(f.getPeerId()==null&&(f=f.encapsulate(`/p2p/${i.toString()}`)),f));if(u.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",u.map(f=>f.toString()).join(", "),i);let c="",l=u[0];for(let f of u){let h;l=f;try{if(h=await this.components.connectionManager.openConnection(f,n),!h.remoteAddr.equals(f))throw this.log.error("tried to dial %a but dialed %a",f,h.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,f),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(ka("p2p").code).bytes}}}catch(m){this.log.error("could not dial %p - %e",i,m),c=m.message}finally{h!=null&&await h.close()}}return{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_DIAL_ERROR,statusText:c,addr:l.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||o.multiaddr.toOptions().family===6&&(!e||!Ua(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:Go(),queue:new Sn({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})=>i.toOptions().family===6),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 %p to verify multiaddr %s",t.remotePeer,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=xs(i).pb(K),[,u]=await Promise.all([a.write({type:K.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(u.type!==K.MessageType.DIAL_RESPONSE||u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}let c=u.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,c),c!==K.ResponseStatus.OK&&c!==K.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,u.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),c===K.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else c===K.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===ql&&this.confirmAddress(o),o.failure===Hl&&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.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};function Vl(r={}){return t=>new Dn(t,r)}return oc(jl);})();
|
|
2
|
+
"use strict";var Libp2PAutonat=(()=>{var Ec=Object.create;var kr=Object.defineProperty;var vc=Object.getOwnPropertyDescriptor;var Sc=Object.getOwnPropertyNames;var _c=Object.getPrototypeOf,Ac=Object.prototype.hasOwnProperty;var Ic=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var r in t)kr(e,r,{get:t[r],enumerable:!0})},Gs=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sc(t))!Ac.call(e,o)&&o!==r&&kr(e,o,{get:()=>t[o],enumerable:!(n=vc(t,o))||n.enumerable});return e};var Bc=(e,t,r)=>(r=e!=null?Ec(_c(e)):{},Gs(t||!e||!e.__esModule?kr(r,"default",{value:e,enumerable:!0}):r,e)),Tc=e=>Gs(kr({},"__esModule",{value:!0}),e);var lc=Ic(Or=>{(function(){var e,t,r,n,o,s,i,c;c=function(a){var u,h,f,l;return u=(a&255<<24)>>>24,h=(a&255<<16)>>>16,f=(a&65280)>>>8,l=a&255,[u,h,f,l].join(".")},i=function(a){var u,h,f,l,d,p;for(u=[],f=l=0;l<=3&&a.length!==0;f=++l){if(f>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}p=t(a),d=p[0],h=p[1],a=a.substring(h),u.push(d)}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")}},r=function(a){return a.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),t=function(a){var u,h,f,l,d;for(l=0,u=10,h="9",f=0,a.length>1&&a[f]==="0"&&(a[f+1]==="x"||a[f+1]==="X"?(f+=2,u=16):"0"<=a[f+1]&&a[f+1]<="9"&&(f++,u=8,h="7")),d=f;f<a.length;){if("0"<=a[f]&&a[f]<=h)l=l*u+(r(a[f])-n)>>>0;else if(u===16)if("a"<=a[f]&&a[f]<="f")l=l*u+(10+r(a[f])-s)>>>0;else if("A"<=a[f]&&a[f]<="F")l=l*u+(10+r(a[f])-o)>>>0;else break;else break;if(l>4294967295)throw new Error("too large");f++}if(f===d)throw new Error("empty octet");return[l,f]},e=(function(){function a(u,h){var f,l,d,p;if(typeof u!="string")throw new Error("Missing `net' parameter");if(h||(p=u.split("/",2),u=p[0],h=p[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(x){throw f=x,new Error("Invalid mask: "+h)}for(l=d=32;d>=0;l=--d)if(this.maskLong===4294967295<<32-l>>>0){this.bitmask=l;break}}else if(h||h===0)this.bitmask=parseInt(h,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(x){throw f=x,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+h);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 h,f,l;for(l=i(this.first),f=i(this.last),h=0;l<=f;)u(c(l),l,h),h++,l++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a})(),Or.ip2long=i,Or.long2ip=c,Or.Netmask=e}).call(Or)});var Lh={};yt(Lh,{autoNAT:()=>Ch});var Dt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var _t=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Mr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Fr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var er=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Kn=Symbol.for("@libp2p/peer-id");var Kr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Zs=Symbol.for("@libp2p/service-capabilities"),Ws=Symbol.for("@libp2p/service-dependencies");var $n={};yt($n,{base58btc:()=>G,base58flickr:()=>Nc});var ad=new Uint8Array(0);function Xs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ys(e){return new TextEncoder().encode(e)}function Qs(e){return new TextDecoder().decode(e)}function Cc(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),h=Math.log(256)/Math.log(c);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var x=0,E=0,y=0,_=p.length;y!==_&&p[y]===0;)y++,x++;for(var w=(_-y)*h+1>>>0,T=new Uint8Array(w);y!==_;){for(var P=p[y],M=0,k=w-1;(P!==0||M<E)&&k!==-1;k--,M++)P+=256*T[k]>>>0,T[k]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");E=M,y++}for(var O=w-E;O!==w&&T[O]===0;)O++;for(var v=a.repeat(x);O<w;++O)v+=e.charAt(T[O]);return v}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var x=0;if(p[x]!==" "){for(var E=0,y=0;p[x]===a;)E++,x++;for(var _=(p.length-x)*u+1>>>0,w=new Uint8Array(_);p[x];){var T=r[p.charCodeAt(x)];if(T===255)return;for(var P=0,M=_-1;(T!==0||P<y)&&M!==-1;M--,P++)T+=c*w[M]>>>0,w[M]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");y=P,x++}if(p[x]!==" "){for(var k=_-y;k!==_&&w[k]===0;)k++;for(var O=new Uint8Array(E+(_-k)),v=E;k!==_;)O[v++]=w[k++];return O}}}function d(p){var x=l(p);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:l,decode:d}}var Lc=Cc,Dc=Lc,ti=Dc;var zn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},qn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.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 ei(this,t)}},Vn=class{decoders;constructor(t){this.decoders=t}or(t){return ei(this,t)}decode(t){let r=t[0],n=this.decoders[r];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 ei(e,t){return new Vn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Hn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new zn(t,r,n),this.decoder=new qn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function _e({name:e,prefix:t,encode:r,decode:n}){return new Hn(e,t,r,n)}function Qt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=ti(r,e);return _e({prefix:t,name:e,encode:n,decode:s=>Pt(o(s))})}function Pc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let h=t[e[u]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|h,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Rc(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Oc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Oc(n);return _e({prefix:t,name:e,encode(s){return Rc(s,n,r)},decode(s){return Pc(s,o,r,e)}})}var G=Qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nc=Qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var jn={};yt(jn,{base32:()=>Jt,base32hex:()=>Fc,base32hexpad:()=>zc,base32hexpadupper:()=>qc,base32hexupper:()=>Kc,base32pad:()=>kc,base32padupper:()=>Mc,base32upper:()=>Uc,base32z:()=>Vc});var Jt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Uc=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),kc=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Mc=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Fc=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Kc=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),zc=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qc=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vc=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gn={};yt(Gn,{base36:()=>rr,base36upper:()=>Hc});var rr=Qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Hc=Qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var $c=oi,ri=128,jc=127,Gc=~jc,Zc=Math.pow(2,31);function oi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Zc;)t[r++]=e&255|ri,e/=128;for(;e&Gc;)t[r++]=e&255|ri,e>>>=7;return t[r]=e|0,oi.bytes=r-n+1,t}var Wc=Zn,Xc=128,ni=127;function Zn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Zn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ni)<<o:(i&ni)*Math.pow(2,o),o+=7}while(i>=Xc);return Zn.bytes=s-n,r}var Yc=Math.pow(2,7),Qc=Math.pow(2,14),Jc=Math.pow(2,21),tu=Math.pow(2,28),eu=Math.pow(2,35),ru=Math.pow(2,42),nu=Math.pow(2,49),ou=Math.pow(2,56),su=Math.pow(2,63),iu=function(e){return e<Yc?1:e<Qc?2:e<Jc?3:e<tu?4:e<eu?5:e<ru?6:e<nu?7:e<ou?8:e<su?9:10},au={encode:$c,decode:Wc,encodingLength:iu},cu=au,nr=cu;function or(e,t=0){return[nr.decode(e,t),nr.decode.bytes]}function Ae(e,t,r=0){return nr.encode(e,t,r),t}function Ie(e){return nr.encodingLength(e)}function Te(e,t){let r=t.byteLength,n=Ie(e),o=n+Ie(r),s=new Uint8Array(o+r);return Ae(e,s,0),Ae(r,s,n),s.set(t,o),new Be(e,r,t,s)}function ue(e){let t=Pt(e),[r,n]=or(t),[o,s]=or(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Be(r,o,i,t)}function si(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Xs(e.bytes,r.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ii(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return fu(r,Wn(e),t??G.encoder);default:return lu(r,Wn(e),t??Jt.encoder)}}var ai=new WeakMap;function Wn(e){let t=ai.get(e);if(t==null){let r=new Map;return ai.set(e,r),r}return t}var tt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,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:r}=this;if(t!==sr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==hu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}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:r}=this.multihash,n=Te(t,r);return e.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 e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&si(t.multihash,n.multihash)}toString(t){return ii(this,t)}toJSON(){return{"/":ii(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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??ci(n,o,s.bytes))}else if(r[du]===!0){let{version:n,multihash:o,code:s}=r,i=ue(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="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(r!==sr)throw new Error(`Version 0 CID must use dag-pb (code: ${sr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ci(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,sr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Pt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Be(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[f,l]=or(t.subarray(r));return r+=l,f},o=n(),s=sr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,h=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:h,size:u}}static parse(t,r){let[n,o]=uu(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Wn(s).set(n,t),s}};function uu(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case Jt.prefix:{let r=t??Jt;return[Jt.prefix,r.decode(e)]}case rr.prefix:{let r=t??rr;return[rr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function fu(e,t,r){let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function lu(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var sr=112,hu=18;function ci(e,t,r){let n=Ie(e),o=n+Ie(t),s=new Uint8Array(o+r.byteLength);return Ae(e,s,0),Ae(t,s,n),s.set(r,o),s}var du=Symbol.for("@ipld/js-cid/CID");var Xn={};yt(Xn,{identity:()=>At});var ui=0,pu="identity",fi=Pt;function mu(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Te(ui,fi(e))}var At={code:ui,name:pu,encode:fi,digest:mu};function ft(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function It(e=0){return new Uint8Array(e)}function pt(e=0){return new Uint8Array(e)}function Rt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=pt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var hi=Symbol.for("@achingbrain/uint8arraylist");function li(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function qr(e){return!!e?.[hi]}var et=class e{bufs;length;[hi]=!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 r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(qr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(qr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=li(this.bufs,t);return r.buf[r.index]}set(t,r){let n=li(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(qr(t))for(let n=0;n<t.length;n++)this.set(r+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,r){let{bufs:n,length:o}=this._subList(t,r);return Rt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Rt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===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,h=r>c&&r<=a;if(u&&h){if(t===c&&r===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(h){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!qr(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(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,h;for(let f=r;f<=a;f+=h){h=0;for(let l=u;l>=0;l--){let d=this.get(f+l);if(n[l]!==d){h=Math.max(1,l-c[d]);break}}if(h===0)return f}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=It(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=It(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=It(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=It(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=It(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ft(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Yn={};yt(Yn,{base10:()=>gu});var gu=Qt({prefix:"9",name:"base10",alphabet:"0123456789"});var Qn={};yt(Qn,{base16:()=>yu,base16upper:()=>bu});var yu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jn={};yt(Jn,{base2:()=>xu});var xu=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var to={};yt(to,{base256emoji:()=>_u});var di=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}"),wu=di.reduce((e,t,r)=>(e[r]=t,e),[]),Eu=di.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function vu(e){return e.reduce((t,r)=>(t+=wu[r],t),"")}function Su(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Eu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var _u=_e({prefix:"\u{1F680}",name:"base256emoji",encode:vu,decode:Su});var ro={};yt(ro,{base64:()=>Au,base64pad:()=>Iu,base64url:()=>eo,base64urlpad:()=>Bu});var Au=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Iu=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),eo=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bu=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var no={};yt(no,{base8:()=>Tu});var Tu=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oo={};yt(oo,{identity:()=>Cu});var Cu=_e({prefix:"\0",name:"identity",encode:e=>Qs(e),decode:e=>Ys(e)});var Hd=new TextEncoder,$d=new TextDecoder;var ao={};yt(ao,{sha256:()=>ir,sha512:()=>Ru});var Pu=20;function io({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new so(e,t,r,n,o)}var so=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Pu,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.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?pi(n,this.code,r?.truncate):n.then(o=>pi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function pi(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Te(t,e)}function gi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ir=io({name:"sha2-256",code:18,encode:gi("SHA-256")}),Ru=io({name:"sha2-512",code:19,encode:gi("SHA-512")});var ar={...oo,...Jn,...no,...Yn,...Qn,...jn,...Gn,...$n,...ro,...to},np={...ao,...Xn};function bi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var yi=bi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),co=bi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=pt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ou={utf8:yi,"utf-8":yi,hex:ar.base16,latin1:co,ascii:co,binary:co,...ar},Vr=Ou;function V(e,t="utf8"){let r=Vr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function $(e,t="utf8"){let r=Vr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Nu=parseInt("11111",2),uo=parseInt("10000000",2),Uu=parseInt("01111111",2),xi={0:cr,1:cr,2:ku,3:Ku,4:zu,5:Fu,6:Mu,16:cr,22:cr,48:cr};function fo(e,t={offset:0}){let r=e[t.offset]Νif(t.offset++,xi[r]!=null)return xi[r](e,t);throw new Error("No decoder for tag "+r)}function ur(e,t){let r=0;if((e[t.offset]&uo)===uo){let n=e[t.offset]&Uu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function cr(e,t){ur(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=fo(e,t);if(n===null)break;r.push(n)}return r}function ku(e,t){let r=ur(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Mu(e,t){let r=ur(e,t),n=t.offset+r,o=e[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=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let h=0;for(let f=0;f<a.length;f++)h+=a[f]<<f*7;c+=`.${h}`,a=[]}}return c}function Fu(e,t){return t.offset++,null}function Ku(e,t){let r=ur(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function zu(e,t){let r=ur(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function qu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new et;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function lo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=qu(e.byteLength);return new et(Uint8Array.from([t.byteLength|uo]),t)}function wi(e){let t=new et,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new et(Uint8Array.from([2]),lo(t),t)}function Ei(e){let t=Uint8Array.from([0]),r=new et(t,e);return new et(Uint8Array.from([3]),lo(r),r)}function Hr(e,t=48){let r=new et;for(let n of e)r.append(n);return new et(Uint8Array.from([t]),lo(r),r)}async function vi(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Vu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Hu=Uint8Array.from([6,5,43,129,4,0,34]),$u=Uint8Array.from([6,5,43,129,4,0,35]),ju={ext:!0,kty:"EC",crv:"P-256"},Gu={ext:!0,kty:"EC",crv:"P-384"},Zu={ext:!0,kty:"EC",crv:"P-521"},ho=32,po=48,mo=66;function Si(e){let t=fo(e);return _i(t)}function _i(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ho*2+1)return n=$(t.subarray(r,r+ho),"base64url"),o=$(t.subarray(r+ho),"base64url"),new Ce({...ju,key_ops:["verify"],x:n,y:o});if(t.byteLength===po*2+1)return n=$(t.subarray(r,r+po),"base64url"),o=$(t.subarray(r+po),"base64url"),new Ce({...Gu,key_ops:["verify"],x:n,y:o});if(t.byteLength===mo*2+1)return n=$(t.subarray(r,r+mo),"base64url"),o=$(t.subarray(r+mo),"base64url"),new Ce({...Zu,key_ops:["verify"],x:n,y:o});throw new _t(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ai(e){return Hr([wi(Uint8Array.from([1])),Hr([Wu(e.crv)],160),Hr([Ei(new et(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Wu(e){if(e==="P-256")return Vu;if(e==="P-384")return Hu;if(e==="P-521")return $u;throw new _t(`Invalid curve ${e}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ai(this.jwk)),this._raw}toMultihash(){return At.digest(Le(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}async verify(t,r,n){return vi(this.jwk,r,t,n)}};var fe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Nt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function fr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function mt(e,...t){if(!Nt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function $r(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");fr(e.outputLen),fr(e.blockLen)}function Pe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Bi(e,t){mt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ut(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function jr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Bt(e,t){return e<<32-t|e>>>t}var Ti=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Xu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function St(e){if(mt(e),Ti)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Xu[e[r]];return t}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ii(e){if(e>=Ot._0&&e<=Ot._9)return e-Ot._0;if(e>=Ot.A&&e<=Ot.F)return e-(Ot.A-10);if(e>=Ot.a&&e<=Ot.f)return e-(Ot.a-10)}function le(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ti)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ii(e.charCodeAt(s)),c=Ii(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function go(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function lr(e){return typeof e=="string"&&(e=go(e)),mt(e),e}function lt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];mt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var De=class{};function yo(e){let t=n=>e().update(lr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Re(e=32){if(fe&&typeof fe.getRandomValues=="function")return fe.getRandomValues(new Uint8Array(e));if(fe&&typeof fe.randomBytes=="function")return Uint8Array.from(fe.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Yu(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function Ci(e,t,r){return e&t^~e&r}function Li(e,t,r){return e&t^e&r^t&r}var hr=class extends De{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=jr(this.buffer)}update(t){Pe(this),t=lr(t),mt(t);let{view:r,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=jr(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(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Pe(this),Bi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;Yu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=jr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,h[f],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,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%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},kt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Gr=BigInt(4294967295),Di=BigInt(32);function Qu(e,t=!1){return t?{h:Number(e&Gr),l:Number(e>>Di&Gr)}:{h:Number(e>>Di&Gr)|0,l:Number(e&Gr)|0}}function Pi(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Qu(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var bo=(e,t,r)=>e>>>r,xo=(e,t,r)=>e<<32-r|t>>>r,he=(e,t,r)=>e>>>r|t<<32-r,de=(e,t,r)=>e<<32-r|t>>>r,dr=(e,t,r)=>e<<64-r|t>>>r-32,pr=(e,t,r)=>e>>>r-32|t<<64-r;function Lt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ri=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Oi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ni=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ui=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ki=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Mi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var tf=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]),ee=new Uint32Array(64),wo=class extends hr{constructor(t=32){super(64,t,8,!1),this.A=kt[0]|0,this.B=kt[1]|0,this.C=kt[2]|0,this.D=kt[3]|0,this.E=kt[4]|0,this.F=kt[5]|0,this.G=kt[6]|0,this.H=kt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|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,r){for(let f=0;f<16;f++,r+=4)ee[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){let l=ee[f-15],d=ee[f-2],p=Bt(l,7)^Bt(l,18)^l>>>3,x=Bt(d,17)^Bt(d,19)^d>>>10;ee[f]=x+ee[f-7]+p+ee[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:h}=this;for(let f=0;f<64;f++){let l=Bt(c,6)^Bt(c,11)^Bt(c,25),d=h+l+Ci(c,a,u)+tf[f]+ee[f]|0,x=(Bt(n,2)^Bt(n,13)^Bt(n,22))+Li(n,o,s)|0;h=u,u=a,a=c,c=i+d|0,i=s,s=o,o=n,n=d+x|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,h=h+this.H|0,this.set(n,o,s,i,c,a,u,h)}roundClean(){Ut(ee)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}};var Fi=Pi(["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(e=>BigInt(e))),ef=Fi[0],rf=Fi[1],re=new Uint32Array(80),ne=new Uint32Array(80),Eo=class extends hr{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:h,Fh:f,Fl:l,Gh:d,Gl:p,Hh:x,Hl:E}=this;return[t,r,n,o,s,i,c,a,u,h,f,l,d,p,x,E]}set(t,r,n,o,s,i,c,a,u,h,f,l,d,p,x,E){this.Ah=t|0,this.Al=r|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=h|0,this.Fh=f|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=x|0,this.Hl=E|0}process(t,r){for(let w=0;w<16;w++,r+=4)re[w]=t.getUint32(r),ne[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let T=re[w-15]|0,P=ne[w-15]|0,M=he(T,P,1)^he(T,P,8)^bo(T,P,7),k=de(T,P,1)^de(T,P,8)^xo(T,P,7),O=re[w-2]|0,v=ne[w-2]|0,C=he(O,v,19)^dr(O,v,61)^bo(O,v,6),N=de(O,v,19)^pr(O,v,61)^xo(O,v,6),L=Ni(k,N,ne[w-7],ne[w-16]),b=Ui(L,M,C,re[w-7],re[w-16]);re[w]=b|0,ne[w]=L|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:h,Eh:f,El:l,Fh:d,Fl:p,Gh:x,Gl:E,Hh:y,Hl:_}=this;for(let w=0;w<80;w++){let T=he(f,l,14)^he(f,l,18)^dr(f,l,41),P=de(f,l,14)^de(f,l,18)^pr(f,l,41),M=f&d^~f&x,k=l&p^~l&E,O=ki(_,P,k,rf[w],ne[w]),v=Mi(O,y,T,M,ef[w],re[w]),C=O|0,N=he(n,o,28)^dr(n,o,34)^dr(n,o,39),L=de(n,o,28)^pr(n,o,34)^pr(n,o,39),b=n&s^n&c^s&c,m=o&i^o&a^i&a;y=x|0,_=E|0,x=d|0,E=p|0,d=f|0,p=l|0,{h:f,l}=Lt(u|0,h|0,v|0,C|0),u=c|0,h=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let g=Ri(C,L,m);n=Oi(g,v,N,b),o=g|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:h}=Lt(this.Dh|0,this.Dl|0,u|0,h|0),{h:f,l}=Lt(this.Eh|0,this.El|0,f|0,l|0),{h:d,l:p}=Lt(this.Fh|0,this.Fl|0,d|0,p|0),{h:x,l:E}=Lt(this.Gh|0,this.Gl|0,x|0,E|0),{h:y,l:_}=Lt(this.Hh|0,this.Hl|0,y|0,_|0),this.set(n,o,s,i,c,a,u,h,f,l,d,p,x,E,y,_)}roundClean(){Ut(re,ne)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ki=yo(()=>new wo);var zi=yo(()=>new Eo);var _o=BigInt(0),So=BigInt(1);function Mt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function bt(e,t,r=""){let n=Nt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function mr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function qi(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?_o:BigInt("0x"+e)}function Oe(e){return qi(St(e))}function Ft(e){return mt(e),qi(St(Uint8Array.from(e).reverse()))}function Zr(e,t){return le(e.toString(16).padStart(t*2,"0"))}function Ao(e,t){return Zr(e,t).reverse()}function z(e,t,r){let n;if(typeof t=="string")try{n=le(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Nt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Vi(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Io(e){return Uint8Array.from(e)}var vo=e=>typeof e=="bigint"&&_o<=e;function Hi(e,t,r){return vo(e)&&vo(t)&&vo(r)&&t<=e&&e<r}function gr(e,t,r,n){if(!Hi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Wr(e){let t;for(t=0;e>_o;e>>=So,t+=1);return t}var oe=e=>(So<<BigInt(e))-So;function $i(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=d=>new Uint8Array(d),o=d=>Uint8Array.of(d),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...d)=>r(i,s,...d),h=(d=n(0))=>{i=u(o(0),d),s=u(),d.length!==0&&(i=u(o(1),d),s=u())},f=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,p=[];for(;d<t;){s=u();let x=s.slice();p.push(x),d+=s.length}return lt(...p)};return(d,p)=>{a(),h(d);let x;for(;!(x=p(f()));)h();return a(),x}}function se(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Bo=()=>{throw new Error("not implemented")};function Ne(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var ht=BigInt(0),rt=BigInt(1),pe=BigInt(2),Zi=BigInt(3),Wi=BigInt(4),Xi=BigInt(5),nf=BigInt(7),Yi=BigInt(8),of=BigInt(9),Qi=BigInt(16);function Q(e,t){let r=e%t;return r>=ht?r:t+r}function j(e,t,r){let n=e;for(;t-- >ht;)n*=n,n%=r;return n}function ji(e,t){if(e===ht)throw new Error("invert: expected non-zero number");if(t<=ht)throw new Error("invert: expected positive modulus, got "+t);let r=Q(e,t),n=t,o=ht,s=rt,i=rt,c=ht;for(;r!==ht;){let u=n/r,h=n%r,f=o-i*u,l=s-c*u;n=r,r=h,o=i,s=c,i=f,c=l}if(n!==rt)throw new Error("invert: does not exist");return Q(o,t)}function To(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ji(e,t){let r=(e.ORDER+rt)/Wi,n=e.pow(t,r);return To(e,n,t),n}function sf(e,t){let r=(e.ORDER-Xi)/Yi,n=e.mul(t,pe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,pe),o),c=e.mul(s,e.sub(i,e.ONE));return To(e,c,t),c}function af(e){let t=xt(e),r=ta(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+nf)/Qi;return(c,a)=>{let u=c.pow(a,i),h=c.mul(u,n),f=c.mul(u,o),l=c.mul(u,s),d=c.eql(c.sqr(h),a),p=c.eql(c.sqr(f),a);u=c.cmov(u,h,d),h=c.cmov(l,f,p);let x=c.eql(c.sqr(h),a),E=c.cmov(u,h,x);return To(c,E,a),E}}function ta(e){if(e<Zi)throw new Error("sqrt is not defined for small field");let t=e-rt,r=0;for(;t%pe===ht;)t/=pe,r++;let n=pe,o=xt(e);for(;Gi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ji;let s=o.pow(n,t),i=(t+rt)/pe;return function(a,u){if(a.is0(u))return u;if(Gi(a,u)!==1)throw new Error("Cannot find square root");let h=r,f=a.mul(a.ONE,s),l=a.pow(u,t),d=a.pow(u,i);for(;!a.eql(l,a.ONE);){if(a.is0(l))return a.ZERO;let p=1,x=a.sqr(l);for(;!a.eql(x,a.ONE);)if(p++,x=a.sqr(x),p===h)throw new Error("Cannot find square root");let E=rt<<BigInt(h-p-1),y=a.pow(f,E);h=p,f=a.sqr(y),l=a.mul(l,f),d=a.mul(d,y)}return d}}function cf(e){return e%Wi===Zi?Ji:e%Yi===Xi?sf:e%Qi===of?af(e):ta(e)}var Kt=(e,t)=>(Q(e,t)&rt)===rt,uf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Co(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=uf.reduce((n,o)=>(n[o]="function",n),t);return se(e,r),e}function ff(e,t,r){if(r<ht)throw new Error("invalid exponent, negatives unsupported");if(r===ht)return e.ONE;if(r===rt)return t;let n=e.ONE,o=t;for(;r>ht;)r&rt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=rt;return n}function yr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Gi(e,t){let r=(e.ORDER-rt)/pe,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Xr(e,t){t!==void 0&&fr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function xt(e,t,r=!1,n={}){if(e<=ht)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(o=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(r=l.isLE),typeof l.modFromBytes=="boolean"&&(i=l.modFromBytes),c=l.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=Xr(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let h,f=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:oe(a),ZERO:ht,ONE:rt,allowedLengths:c,create:l=>Q(l,e),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return ht<=l&&l<e},is0:l=>l===ht,isValidNot0:l=>!f.is0(l)&&f.isValid(l),isOdd:l=>(l&rt)===rt,neg:l=>Q(-l,e),eql:(l,d)=>l===d,sqr:l=>Q(l*l,e),add:(l,d)=>Q(l+d,e),sub:(l,d)=>Q(l-d,e),mul:(l,d)=>Q(l*d,e),pow:(l,d)=>ff(f,l,d),div:(l,d)=>Q(l*ji(d,e),e),sqrN:l=>l*l,addN:(l,d)=>l+d,subN:(l,d)=>l-d,mulN:(l,d)=>l*d,inv:l=>ji(l,e),sqrt:s||(l=>(h||(h=cf(e)),h(f,l))),toBytes:l=>r?Ao(l,u):Zr(l,u),fromBytes:(l,d=!0)=>{if(c){if(!c.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+l.length);let x=new Uint8Array(u);x.set(l,r?0:x.length-l.length),l=x}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let p=r?Ft(l):Oe(l);if(i&&(p=Q(p,e)),!d&&!f.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:l=>yr(f,l),cmov:(l,d,p)=>p?d:l});return Object.freeze(f)}function ea(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Lo(e){let t=ea(e);return t+Math.ceil(t/2)}function Do(e,t,r=!1){let n=e.length,o=ea(t),s=Lo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ft(e):Oe(e),c=Q(i,t-rt)+rt;return r?Ao(c,o):Zr(c,o)}var Ue=BigInt(0),me=BigInt(1);function br(e,t){let r=t.negate();return e?r:t}function zt(e,t){let r=yr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function sa(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Po(e,t){sa(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=oe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ra(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=me);let u=t*n,h=u+Math.abs(c)-1,f=c===0,l=c<0,d=t%2!==0;return{nextN:a,offset:h,isZero:f,isNeg:l,isNegF:d,offsetF:u}}function lf(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function hf(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Ro=new WeakMap,ia=new WeakMap;function Oo(e){return ia.get(e)||1}function na(e){if(e!==Ue)throw new Error("invalid wNAF")}var ke=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Ue;)r&me&&(n=n.add(o)),o=o.double(),r>>=me;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Po(r,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,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Po(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:h,isNeg:f,isNegF:l,offsetF:d}=ra(n,c,i);n=a,h?s=s.add(br(l,r[d])):o=o.add(br(f,r[u]))}return na(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Po(t,this.bits);for(let i=0;i<s.windows&&n!==Ue;i++){let{nextN:c,offset:a,isZero:u,isNeg:h}=ra(n,i,s);if(n=c,!u){let f=r[a];o=o.add(h?f.negate():f)}}return na(n),o}getPrecomputes(t,r,n){let o=Ro.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Ro.set(r,o))),o}cached(t,r,n){let o=Oo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Oo(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){sa(r,this.bits),ia.set(t,r),Ro.delete(t)}hasCache(t){return Oo(t)!==1}};function aa(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Ue||n>Ue;)r&me&&(s=s.add(o)),n&me&&(i=i.add(o)),o=o.double(),r>>=me,n>>=me;return{p1:s,p2:i}}function Me(e,t,r,n){lf(r,e),hf(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Wr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=oe(a),h=new Array(Number(u)+1).fill(i),f=Math.floor((t.BITS-1)/a)*a,l=i;for(let d=f;d>=0;d-=a){h.fill(i);for(let x=0;x<s;x++){let E=n[x],y=Number(E>>BigInt(d)&u);h[y]=h[y].add(r[x])}let p=i;for(let x=h.length-1,E=i;x>0;x--)E=E.add(h[x]),p=p.add(E);if(l=l.add(p),d!==0)for(let x=0;x<a;x++)l=l.double()}return l}function oa(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Co(t),t}else return xt(e,{isLE:r})}function Yr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Ue))throw new Error(`CURVE.${a} must be positive bigint`)}let o=oa(t.p,r.Fp,n),s=oa(t.n,r.Fn,n),c=["Gx","Gy","a",e==="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}}var ie=BigInt(0),nt=BigInt(1),No=BigInt(2),df=BigInt(8);function pf(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function mf(e,t={}){let r=Yr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;se(t,{},{uvRatio:"function"});let c=No<<BigInt(o.BYTES*8)-nt,a=E=>n.create(E),u=t.uvRatio||((E,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(E,y))}}catch{return{isValid:!1,value:ie}}});if(!pf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function h(E,y,_=!1){let w=_?nt:ie;return gr("coordinate "+E,y,w,c),y}function f(E){if(!(E instanceof p))throw new Error("ExtendedPoint expected")}let l=Ne((E,y)=>{let{X:_,Y:w,Z:T}=E,P=E.is0();y==null&&(y=P?df:n.inv(T));let M=a(_*y),k=a(w*y),O=n.mul(T,y);if(P)return{x:ie,y:nt};if(O!==nt)throw new Error("invZ was invalid");return{x:M,y:k}}),d=Ne(E=>{let{a:y,d:_}=s;if(E.is0())throw new Error("bad point: ZERO");let{X:w,Y:T,Z:P,T:M}=E,k=a(w*w),O=a(T*T),v=a(P*P),C=a(v*v),N=a(k*y),L=a(v*a(N+O)),b=a(C+a(_*a(k*O)));if(L!==b)throw new Error("bad point: equation left != right (1)");let m=a(w*T),g=a(P*M);if(m!==g)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(y,_,w,T){this.X=h("x",y),this.Y=h("y",_),this.Z=h("z",w,!0),this.T=h("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof p)throw new Error("extended point not allowed");let{x:_,y:w}=y||{};return h("x",_),h("y",w),new p(_,w,nt,a(_*w))}static fromBytes(y,_=!1){let w=n.BYTES,{a:T,d:P}=s;y=Io(bt(y,w,"point")),Mt(_,"zip215");let M=Io(y),k=y[w-1];M[w-1]=k&-129;let O=Ft(M),v=_?c:n.ORDER;gr("point.y",O,ie,v);let C=a(O*O),N=a(C-nt),L=a(P*C-T),{isValid:b,value:m}=u(N,L);if(!b)throw new Error("bad point: invalid y coordinate");let g=(m&nt)===nt,S=(k&128)!==0;if(!_&&m===ie&&S)throw new Error("bad point: x=0 and x_0=1");return S!==g&&(m=a(-m)),p.fromAffine({x:m,y:O})}static fromHex(y,_=!1){return p.fromBytes(z("point",y),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,_=!0){return x.createCache(this,y),_||this.multiply(No),this}assertValidity(){d(this)}equals(y){f(y);let{X:_,Y:w,Z:T}=this,{X:P,Y:M,Z:k}=y,O=a(_*k),v=a(P*T),C=a(w*k),N=a(M*T);return O===v&&C===N}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:y}=s,{X:_,Y:w,Z:T}=this,P=a(_*_),M=a(w*w),k=a(No*a(T*T)),O=a(y*P),v=_+w,C=a(a(v*v)-P-M),N=O+M,L=N-k,b=O-M,m=a(C*L),g=a(N*b),S=a(C*b),A=a(L*N);return new p(m,g,A,S)}add(y){f(y);let{a:_,d:w}=s,{X:T,Y:P,Z:M,T:k}=this,{X:O,Y:v,Z:C,T:N}=y,L=a(T*O),b=a(P*v),m=a(k*w*N),g=a(M*C),S=a((T+P)*(O+v)-L-b),A=g-m,D=g+m,I=a(b-_*L),B=a(S*A),R=a(D*I),U=a(S*I),Z=a(A*D);return new p(B,R,Z,U)}subtract(y){return this.add(y.negate())}multiply(y){if(!o.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:_,f:w}=x.cached(this,y,T=>zt(p,T));return zt(p,[_,w])[0]}multiplyUnsafe(y,_=p.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===ie?p.ZERO:this.is0()||y===nt?this:x.unsafe(this,y,w=>zt(p,w),_)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return x.unsafe(this,s.n).is0()}toAffine(y){return l(this,y)}clearCofactor(){return i===nt?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:_}=this.toAffine(),w=n.toBytes(_);return w[w.length-1]|=y&nt?128:0,w}toHex(){return St(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(y){return zt(p,y)}static msm(y,_){return Me(p,o,y,_)}_setWindowSize(y){this.precompute(y)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,nt,a(s.Gx*s.Gy)),p.ZERO=new p(ie,nt,nt,ie),p.Fp=n,p.Fn=o;let x=new ke(p,o.BITS);return p.BASE.precompute(8),p}var Qr=class{constructor(t){this.ep=t}static fromBytes(t){Bo()}static fromHex(t){Bo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return St(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function gf(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');se(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||Re,a=r.adjustScalarBytes||(v=>v),u=r.domain||((v,C,N)=>{if(Mt(N,"phflag"),C.length||N)throw new Error("Contexts/pre-hash are not supported");return v});function h(v){return i.create(Ft(v))}function f(v){let C=w.secretKey;v=z("private key",v,C);let N=z("hashed private key",t(v),2*C),L=a(N.slice(0,C)),b=N.slice(C,2*C),m=h(L);return{head:L,prefix:b,scalar:m}}function l(v){let{head:C,prefix:N,scalar:L}=f(v),b=o.multiply(L),m=b.toBytes();return{head:C,prefix:N,scalar:L,point:b,pointBytes:m}}function d(v){return l(v).pointBytes}function p(v=Uint8Array.of(),...C){let N=lt(...C);return h(t(u(N,z("context",v),!!n)))}function x(v,C,N={}){v=z("message",v),n&&(v=n(v));let{prefix:L,scalar:b,pointBytes:m}=l(C),g=p(N.context,L,v),S=o.multiply(g).toBytes(),A=p(N.context,S,m,v),D=i.create(g+A*b);if(!i.isValid(D))throw new Error("sign failed: invalid s");let I=lt(S,i.toBytes(D));return bt(I,w.signature,"result")}let E={zip215:!0};function y(v,C,N,L=E){let{context:b,zip215:m}=L,g=w.signature;v=z("signature",v,g),C=z("message",C),N=z("publicKey",N,w.publicKey),m!==void 0&&Mt(m,"zip215"),n&&(C=n(C));let S=g/2,A=v.subarray(0,S),D=Ft(v.subarray(S,g)),I,B,R;try{I=e.fromBytes(N,m),B=e.fromBytes(A,m),R=o.multiplyUnsafe(D)}catch{return!1}if(!m&&I.isSmallOrder())return!1;let U=p(b,B.toBytes(),I.toBytes(),C);return B.add(I.multiplyUnsafe(U)).subtract(R).clearCofactor().is0()}let _=s.BYTES,w={secretKey:_,publicKey:_,signature:2*_,seed:_};function T(v=c(w.seed)){return bt(v,w.seed,"seed")}function P(v){let C=O.randomSecretKey(v);return{secretKey:C,publicKey:d(C)}}function M(v){return Nt(v)&&v.length===i.BYTES}function k(v,C){try{return!!e.fromBytes(v,C)}catch{return!1}}let O={getExtendedPublicKey:l,randomSecretKey:T,isValidSecretKey:M,isValidPublicKey:k,toMontgomery(v){let{y:C}=e.fromBytes(v),N=w.publicKey,L=N===32;if(!L&&N!==57)throw new Error("only defined for 25519 and 448");let b=L?s.div(nt+C,nt-C):s.div(C-nt,C+nt);return s.toBytes(b)},toMontgomerySecret(v){let C=w.secretKey;bt(v,C);let N=t(v.subarray(0,C));return a(N).subarray(0,C)},randomPrivateKey:T,precompute(v=8,C=e.BASE){return C.precompute(v,!1)}};return Object.freeze({keygen:P,getPublicKey:d,sign:x,verify:y,utils:O,Point:e,lengths:w})}function yf(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=xt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function bf(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function ca(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=yf(e),s=mf(t,r),i=gf(s,n,o);return bf(e,i)}var xf=BigInt(0),qt=BigInt(1),ua=BigInt(2),l0=BigInt(3),wf=BigInt(5),Ef=BigInt(8),Fe=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),xr={p:Fe,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ef,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function vf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Fe,c=e*e%s*e%s,a=j(c,ua,s)*c%s,u=j(a,qt,s)*e%s,h=j(u,wf,s)*u%s,f=j(h,t,s)*h%s,l=j(f,r,s)*f%s,d=j(l,n,s)*l%s,p=j(d,o,s)*d%s,x=j(p,o,s)*d%s,E=j(x,t,s)*h%s;return{pow_p_5_8:j(E,ua,s)*e%s,b2:c}}function Sf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Uo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Fo(e,t){let r=Fe,n=Q(t*t*t,r),o=Q(n*n*t,r),s=vf(e*o).pow_p_5_8,i=Q(e*n*s,r),c=Q(t*i*i,r),a=i,u=Q(i*Uo,r),h=c===e,f=c===Q(-e,r),l=c===Q(-e*Uo,r);return h&&(i=a),(f||l)&&(i=u),Kt(i,r)&&(i=Q(-i,r)),{isValid:h||f,value:i}}var ae=xt(xr.p,{isLE:!0}),_f=xt(xr.n,{isLE:!0}),Af={...xr,Fp:ae,hash:zi,adjustScalarBytes:Sf,uvRatio:Fo},Vt=ca(Af);var ko=Uo,If=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Bf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Tf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Cf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),fa=e=>Fo(qt,e),Lf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Mo=e=>Vt.Point.Fp.create(Ft(e)&Lf);function la(e){let{d:t}=xr,r=Fe,n=y=>ae.create(y),o=n(ko*e*e),s=n((o+qt)*Tf),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=Fo(s,c),h=n(u*e);Kt(h,r)||(h=n(-h)),a||(u=h),a||(i=o);let f=n(i*(o-qt)*Cf-c),l=u*u,d=n((u+u)*c),p=n(f*If),x=n(qt-l),E=n(qt+l);return new Vt.Point(n(d*E),n(x*p),n(p*E),n(d*x))}function Df(e){mt(e,64);let t=Mo(e.subarray(0,32)),r=la(t),n=Mo(e.subarray(32,64)),o=la(n);return new Ht(r.add(o))}var Ht=class e extends Qr{constructor(t){super(t)}static fromAffine(t){return new e(Vt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Df(z("ristrettoHash",t,64))}static fromBytes(t){mt(t,32);let{a:r,d:n}=xr,o=Fe,s=T=>ae.create(T),i=Mo(t);if(!Vi(ae.toBytes(i),t)||Kt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(qt+r*c),u=s(qt-r*c),h=s(a*a),f=s(u*u),l=s(r*n*h-f),{isValid:d,value:p}=fa(s(l*f)),x=s(p*u),E=s(p*x*l),y=s((i+i)*x);Kt(y,o)&&(y=s(-y));let _=s(a*E),w=s(y*_);if(!d||Kt(w,o)||_===xf)throw new Error("invalid ristretto255 encoding 2");return new e(new Vt.Point(y,_,qt,w))}static fromHex(t){return e.fromBytes(z("ristrettoHex",t,32))}static msm(t,r){return Me(e,Vt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Fe,i=E=>ae.create(E),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:h}=fa(i(c*u)),f=i(h*c),l=i(h*a),d=i(f*l*o),p;if(Kt(o*d,s)){let E=i(r*ko),y=i(t*ko);t=E,r=y,p=i(f*Bf)}else p=l;Kt(t*d,s)&&(r=i(-r));let x=i((n-r)*p);return Kt(x,s)&&(x=i(-x)),ae.toBytes(x)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ae.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};Ht.BASE=new Ht(Vt.Point.BASE);Ht.ZERO=new Ht(Vt.Point.ZERO);Ht.Fp=ae;Ht.Fn=_f;var wr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Jr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ha={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Jr("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 tn=ha;var en=32;var Ko,Pf=(async()=>{try{return await tn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Rf(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await tn.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await tn.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Of(e,t,r){return Vt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function da(e,t,r){return Ko==null&&(Ko=await Pf),Ko?Rf(e,t,r):Of(e,t,r)}function rn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var nn=class{type="Ed25519";raw;constructor(t){this.raw=zo(t,en)}toMultihash(){return At.digest(Le(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=da(this.raw,r,t);return rn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ma(e){return e=zo(e,en),new nn(e)}function zo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new _t(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Uf=Math.pow(2,7),kf=Math.pow(2,14),Mf=Math.pow(2,21),qo=Math.pow(2,28),Vo=Math.pow(2,35),Ho=Math.pow(2,42),$o=Math.pow(2,49),K=128,ct=127;function gt(e){if(e<Uf)return 1;if(e<kf)return 2;if(e<Mf)return 3;if(e<qo)return 4;if(e<Vo)return 5;if(e<Ho)return 6;if(e<$o)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ke(e,t,r=0){switch(gt(e)){case 8:t[r++]=e&255|K,e/=128;case 7:t[r++]=e&255|K,e/=128;case 6:t[r++]=e&255|K,e/=128;case 5:t[r++]=e&255|K,e/=128;case 4:t[r++]=e&255|K,e>>>=7;case 3:t[r++]=e&255|K,e>>>=7;case 2:t[r++]=e&255|K,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ff(e,t,r=0){switch(gt(e)){case 8:t.set(r++,e&255|K),e/=128;case 7:t.set(r++,e&255|K),e/=128;case 6:t.set(r++,e&255|K),e/=128;case 5:t.set(r++,e&255|K),e/=128;case 4:t.set(r++,e&255|K),e>>>=7;case 3:t.set(r++,e&255|K),e>>>=7;case 2:t.set(r++,e&255|K),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function jo(e,t){let r=e[t],n=0;if(n+=r&ct,r<K||(r=e[t+1],n+=(r&ct)<<7,r<K)||(r=e[t+2],n+=(r&ct)<<14,r<K)||(r=e[t+3],n+=(r&ct)<<21,r<K)||(r=e[t+4],n+=(r&ct)*qo,r<K)||(r=e[t+5],n+=(r&ct)*Vo,r<K)||(r=e[t+6],n+=(r&ct)*Ho,r<K)||(r=e[t+7],n+=(r&ct)*$o,r<K))return n;throw new RangeError("Could not decode varint")}function Kf(e,t){let r=e.get(t),n=0;if(n+=r&ct,r<K||(r=e.get(t+1),n+=(r&ct)<<7,r<K)||(r=e.get(t+2),n+=(r&ct)<<14,r<K)||(r=e.get(t+3),n+=(r&ct)<<21,r<K)||(r=e.get(t+4),n+=(r&ct)*qo,r<K)||(r=e.get(t+5),n+=(r&ct)*Vo,r<K)||(r=e.get(t+6),n+=(r&ct)*Ho,r<K)||(r=e.get(t+7),n+=(r&ct)*$o,r<K))return n;throw new RangeError("Could not decode varint")}function ga(e,t,r=0){return t==null&&(t=pt(gt(e))),t instanceof Uint8Array?Ke(e,t,r):Ff(e,t,r)}function Er(e,t=0){return e instanceof Uint8Array?jo(e,t):Kf(e,t)}var Go=new Float32Array([-0]),ce=new Uint8Array(Go.buffer);function ba(e,t,r){Go[0]=e,t[r]=ce[0],t[r+1]=ce[1],t[r+2]=ce[2],t[r+3]=ce[3]}function xa(e,t){return ce[0]=e[t],ce[1]=e[t+1],ce[2]=e[t+2],ce[3]=e[t+3],Go[0]}var Zo=new Float64Array([-0]),ut=new Uint8Array(Zo.buffer);function wa(e,t,r){Zo[0]=e,t[r]=ut[0],t[r+1]=ut[1],t[r+2]=ut[2],t[r+3]=ut[3],t[r+4]=ut[4],t[r+5]=ut[5],t[r+6]=ut[6],t[r+7]=ut[7]}function Ea(e,t){return ut[0]=e[t],ut[1]=e[t+1],ut[2]=e[t+2],ut[3]=e[t+3],ut[4]=e[t+4],ut[5]=e[t+5],ut[6]=e[t+6],ut[7]=e[t+7],Zo[0]}var zf=BigInt(Number.MAX_SAFE_INTEGER),qf=BigInt(Number.MIN_SAFE_INTEGER),wt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+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 r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(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,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<zf&&t>qf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>va&&(o=0n,++n>va&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ge}},ge=new wt(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var va=4294967296n;function Sa(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function _a(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[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 Wo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Tt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function on(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Xo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Tt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Tt(this,4);return on(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return on(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=xa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=Ea(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Tt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return _a(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new wt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*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;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Tt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Tt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Tt(this,8);let t=on(this.buf,this.pos+=4),r=on(this.buf,this.pos+=4);return new wt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=jo(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 Yo(e){return new Xo(e instanceof Uint8Array?e:e.subarray())}function $t(e,t,r){let n=Yo(e);return t.decode(n,void 0,r)}function Qo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)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 ye=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Jo(){}var es=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Vf=Qo();function Hf(e){return globalThis.Buffer!=null?pt(e):Vf(e)}var Sr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye(Jo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ye(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new rs((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(sn,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=wt.fromBigInt(t);return this._push(sn,r.length(),r)}uint64Number(t){return this._push(Ke,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 r=wt.fromBigInt(t).zzEncode();return this._push(sn,r.length(),r)}sint64Number(t){let r=wt.fromNumber(t).zzEncode();return this._push(sn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ts,1,t?1:0)}fixed32(t){return this._push(vr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=wt.fromBigInt(t);return this._push(vr,4,r.lo)._push(vr,4,r.hi)}fixed64Number(t){let r=wt.fromNumber(t);return this._push(vr,4,r.lo)._push(vr,4,r.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(ba,4,t)}double(t){return this._push(wa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ts,1,0):this.uint32(r)._push(jf,r,t)}string(t){let r=Sa(t);return r!==0?this.uint32(r)._push(Wo,r,t):this._push(ts,1,0)}fork(){return this.states=new es(this),this.head=this.tail=new ye(Jo,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 ye(Jo,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Hf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ts(e,t,r){t[r]=e&255}function $f(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var rs=class extends ye{next;constructor(t,r){super($f,t,r),this.next=void 0}};function sn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function vr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function jf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Sr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Gf,t,e),this},Sr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Zf,t,e),this});function Gf(e,t,r){t.set(e,r)}function Zf(e,t,r){e.length<40?Wo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function ns(){return new Sr}function jt(e,t){let r=ns();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var ze;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(ze||(ze={}));function an(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function qe(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return an("enum",ze.VARINT,r,n)}function Gt(e,t){return an("message",ze.LENGTH_DELIMITED,e,t)}var cn=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Et;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Et||(Et={}));var os;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(os||(os={}));(function(e){e.codec=()=>qe(os)})(Et||(Et={}));var _r;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),Et.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=Et.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>jt(r,e.codec()),e.decode=(r,n)=>$t(r,e.codec(),n)})(_r||(_r={}));var ss;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),Et.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=Et.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>jt(r,e.codec()),e.decode=(r,n)=>$t(r,e.codec(),n)})(ss||(ss={}));var un=class extends De{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,$r(t);let n=lr(r);if(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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Ut(s)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),mt(t,this.outputLen),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||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,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=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},is=(e,t,r)=>new un(e,t).update(r).digest();is.create=(e,t)=>new un(e,t);var Ia=(e,t)=>(e+(e>=0?t:-t)/Ba)/t;function Xf(e,t,r){let[[n,o],[s,i]]=t,c=Ia(i*e,r),a=Ia(-o*e,r),u=e-c*n-a*s,h=-c*o-a*i,f=u<Wt,l=h<Wt;f&&(u=-u),l&&(h=-h);let d=oe(Math.ceil(Wr(r)/2))+He;if(u<Wt||u>=d||h<Wt||h>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:u,k2neg:l,k2:h}}function cs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function as(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Mt(r.lowS,"lowS"),Mt(r.prehash,"prehash"),r.format!==void 0&&cs(r.format),r}var us=class extends Error{constructor(t=""){super(t)}},Zt={Err:us,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=mr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?mr(o.length/2|128):"";return mr(e)+s+o+t},decode(e,t){let{Err:r}=Zt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("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 r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let h of u)i=i<<8|h;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Zt;if(e<Wt)throw new t("integer: negative integers are not allowed");let r=mr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Zt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Oe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Zt,o=z("signature",e),{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:h}=n.decode(2,a);if(h.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Wt=BigInt(0),He=BigInt(1),Ba=BigInt(2),fn=BigInt(3),Yf=BigInt(4);function Ve(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=z("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Qf(e,t={}){let r=Yr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;se(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});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=Ca(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(L,b,m){let{x:g,y:S}=b.toAffine(),A=n.toBytes(g);if(Mt(m,"isCompressed"),m){h();let D=!n.isOdd(S);return lt(Ta(D),A)}else return lt(Uint8Array.of(4),A,n.toBytes(S))}function l(L){bt(L,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=u,g=L.length,S=L[0],A=L.subarray(1);if(g===b&&(S===2||S===3)){let D=n.fromBytes(A);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let I=x(D),B;try{B=n.sqrt(I)}catch(Z){let q=Z instanceof Error?": "+Z.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}h();let R=n.isOdd(B);return(S&1)===1!==R&&(B=n.neg(B)),{x:D,y:B}}else if(g===m&&S===4){let D=n.BYTES,I=n.fromBytes(A.subarray(0,D)),B=n.fromBytes(A.subarray(D,D*2));if(!E(I,B))throw new Error("bad point: is not on curve");return{x:I,y:B}}else throw new Error(`bad point: got length ${g}, expected compressed=${b} or uncompressed=${m}`)}let d=t.toBytes||f,p=t.fromBytes||l;function x(L){let b=n.sqr(L),m=n.mul(b,L);return n.add(n.add(m,n.mul(L,s.a)),s.b)}function E(L,b){let m=n.sqr(b),g=x(L);return n.eql(m,g)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,fn),Yf),_=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,_)))throw new Error("bad curve params: a or b");function w(L,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${L}`);return b}function T(L){if(!(L instanceof v))throw new Error("ProjectivePoint expected")}function P(L){if(!a||!a.basises)throw new Error("no endo");return Xf(L,a.basises,o.ORDER)}let M=Ne((L,b)=>{let{X:m,Y:g,Z:S}=L;if(n.eql(S,n.ONE))return{x:m,y:g};let A=L.is0();b==null&&(b=A?n.ONE:n.inv(S));let D=n.mul(m,b),I=n.mul(g,b),B=n.mul(S,b);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:D,y:I}}),k=Ne(L=>{if(L.is0()){if(t.allowInfinityPoint&&!n.is0(L.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=L.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!E(b,m))throw new Error("bad point: equation left != right");if(!L.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function O(L,b,m,g,S){return m=new v(n.mul(m.X,L),m.Y,m.Z),b=br(g,b),m=br(S,m),b.add(m)}class v{constructor(b,m,g){this.X=w("x",b),this.Y=w("y",m,!0),this.Z=w("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:m,y:g}=b||{};if(!b||!n.isValid(m)||!n.isValid(g))throw new Error("invalid affine point");if(b instanceof v)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(g)?v.ZERO:new v(m,g,n.ONE)}static fromBytes(b){let m=v.fromAffine(p(bt(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return v.fromBytes(z("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return N.createCache(this,b),m||this.multiply(fn),this}assertValidity(){k(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){T(b);let{X:m,Y:g,Z:S}=this,{X:A,Y:D,Z:I}=b,B=n.eql(n.mul(m,I),n.mul(A,S)),R=n.eql(n.mul(g,I),n.mul(D,S));return B&&R}negate(){return new v(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,g=n.mul(m,fn),{X:S,Y:A,Z:D}=this,I=n.ZERO,B=n.ZERO,R=n.ZERO,U=n.mul(S,S),Z=n.mul(A,A),q=n.mul(D,D),F=n.mul(S,A);return F=n.add(F,F),R=n.mul(S,D),R=n.add(R,R),I=n.mul(b,R),B=n.mul(g,q),B=n.add(I,B),I=n.sub(Z,B),B=n.add(Z,B),B=n.mul(I,B),I=n.mul(F,I),R=n.mul(g,R),q=n.mul(b,q),F=n.sub(U,q),F=n.mul(b,F),F=n.add(F,R),R=n.add(U,U),U=n.add(R,U),U=n.add(U,q),U=n.mul(U,F),B=n.add(B,U),q=n.mul(A,D),q=n.add(q,q),U=n.mul(q,F),I=n.sub(I,U),R=n.mul(q,Z),R=n.add(R,R),R=n.add(R,R),new v(I,B,R)}add(b){T(b);let{X:m,Y:g,Z:S}=this,{X:A,Y:D,Z:I}=b,B=n.ZERO,R=n.ZERO,U=n.ZERO,Z=s.a,q=n.mul(s.b,fn),F=n.mul(m,A),W=n.mul(g,D),J=n.mul(S,I),dt=n.add(m,g),X=n.add(A,D);dt=n.mul(dt,X),X=n.add(F,W),dt=n.sub(dt,X),X=n.add(m,S);let at=n.add(A,I);return X=n.mul(X,at),at=n.add(F,J),X=n.sub(X,at),at=n.add(g,S),B=n.add(D,I),at=n.mul(at,B),B=n.add(W,J),at=n.sub(at,B),U=n.mul(Z,X),B=n.mul(q,J),U=n.add(B,U),B=n.sub(W,U),U=n.add(W,U),R=n.mul(B,U),W=n.add(F,F),W=n.add(W,F),J=n.mul(Z,J),X=n.mul(q,X),W=n.add(W,J),J=n.sub(F,J),J=n.mul(Z,J),X=n.add(X,J),F=n.mul(W,X),R=n.add(R,F),F=n.mul(at,X),B=n.mul(dt,B),B=n.sub(B,F),F=n.mul(dt,W),U=n.mul(at,U),U=n.add(U,F),new v(B,R,U)}subtract(b){return this.add(b.negate())}is0(){return this.equals(v.ZERO)}multiply(b){let{endo:m}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let g,S,A=D=>N.cached(this,D,I=>zt(v,I));if(m){let{k1neg:D,k1:I,k2neg:B,k2:R}=P(b),{p:U,f:Z}=A(I),{p:q,f:F}=A(R);S=Z.add(F),g=O(m.beta,U,q,D,B)}else{let{p:D,f:I}=A(b);g=D,S=I}return zt(v,[g,S])[0]}multiplyUnsafe(b){let{endo:m}=t,g=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Wt||g.is0())return v.ZERO;if(b===He)return g;if(N.hasCache(this))return this.multiply(b);if(m){let{k1neg:S,k1:A,k2neg:D,k2:I}=P(b),{p1:B,p2:R}=aa(v,g,A,I);return O(m.beta,B,R,S,D)}else return N.unsafe(g,b)}multiplyAndAddUnsafe(b,m,g){let S=this.multiplyUnsafe(m).add(b.multiplyUnsafe(g));return S.is0()?void 0:S}toAffine(b){return M(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===He?!0:b?b(v,this):N.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===He?this:b?b(v,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return Mt(b,"isCompressed"),this.assertValidity(),d(v,this,b)}toHex(b=!0){return St(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return zt(v,b)}static msm(b,m){return Me(v,o,b,m)}static fromPrivateKey(b){return v.BASE.multiply(Ve(o,b))}}v.BASE=new v(s.Gx,s.Gy,n.ONE),v.ZERO=new v(n.ZERO,n.ONE,n.ZERO),v.Fp=n,v.Fn=o;let C=o.BITS,N=new ke(v,t.endo?Math.ceil(C/2):C);return v.BASE.precompute(8),v}function Ta(e){return Uint8Array.of(e?2:3)}function Ca(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Jf(e,t={}){let{Fn:r}=e,n=t.randomBytes||Re,o=Object.assign(Ca(e.Fp,r),{seed:Lo(r.ORDER)});function s(d){try{return!!Ve(r,d)}catch{return!1}}function i(d,p){let{publicKey:x,publicKeyUncompressed:E}=o;try{let y=d.length;return p===!0&&y!==x||p===!1&&y!==E?!1:!!e.fromBytes(d)}catch{return!1}}function c(d=n(o.seed)){return Do(bt(d,o.seed,"seed"),r.ORDER)}function a(d,p=!0){return e.BASE.multiply(Ve(r,d)).toBytes(p)}function u(d){let p=c(d);return{secretKey:p,publicKey:a(p)}}function h(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let{secretKey:p,publicKey:x,publicKeyUncompressed:E}=o;if(r.allowedLengths||p===x)return;let y=z("key",d).length;return y===x||y===E}function f(d,p,x=!0){if(h(d)===!0)throw new Error("first arg must be private key");if(h(p)===!1)throw new Error("second arg must be public key");let E=Ve(r,d);return e.fromHex(p).multiply(E).toBytes(x)}return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:d=>Ve(r,d),precompute(d=8,p=e.BASE){return p.precompute(d,!1)}},lengths:o})}function tl(e,t,r={}){$r(t),se(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||Re,o=r.hmac||((m,...g)=>is(t,m,lt(...g))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:h,getSharedSecret:f,utils:l,lengths:d}=Jf(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},x="compact";function E(m){let g=c>>He;return m>g}function y(m,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return g}function _(m,g){cs(g);let S=d.signature,A=g==="compact"?S:g==="recovered"?S+1:void 0;return bt(m,A,`${g} signature`)}class w{constructor(g,S,A){this.r=y("r",g),this.s=y("s",S),A!=null&&(this.recovery=A),Object.freeze(this)}static fromBytes(g,S=x){_(g,S);let A;if(S==="der"){let{r:R,s:U}=Zt.toSig(bt(g));return new w(R,U)}S==="recovered"&&(A=g[0],S="compact",g=g.subarray(1));let D=i.BYTES,I=g.subarray(0,D),B=g.subarray(D,D*2);return new w(i.fromBytes(I),i.fromBytes(B),A)}static fromHex(g,S){return this.fromBytes(le(g),S)}addRecoveryBit(g){return new w(this.r,this.s,g)}recoverPublicKey(g){let S=s.ORDER,{r:A,s:D,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(c*Ba<S&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=I===2||I===3?A+c:A;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let U=s.toBytes(R),Z=e.fromBytes(lt(Ta((I&1)===0),U)),q=i.inv(R),F=P(z("msgHash",g)),W=i.create(-F*q),J=i.create(D*q),dt=e.BASE.multiplyUnsafe(W).add(Z.multiplyUnsafe(J));if(dt.is0())throw new Error("point at infinify");return dt.assertValidity(),dt}hasHighS(){return E(this.s)}toBytes(g=x){if(cs(g),g==="der")return le(Zt.hexFromSig(this));let S=i.toBytes(this.r),A=i.toBytes(this.s);if(g==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return lt(Uint8Array.of(this.recovery),S,A)}return lt(S,A)}toHex(g){return St(this.toBytes(g))}assertValidity(){}static fromCompact(g){return w.fromBytes(z("sig",g),"compact")}static fromDER(g){return w.fromBytes(z("sig",g),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return St(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return St(this.toBytes("compact"))}}let T=r.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");let S=Oe(g),A=g.length*8-a;return A>0?S>>BigInt(A):S},P=r.bits2int_modN||function(g){return i.create(T(g))},M=oe(a);function k(m){return gr("num < 2^"+a,m,Wt,M),i.toBytes(m)}function O(m,g){return bt(m,void 0,"message"),g?bt(t(m),void 0,"prehashed message"):m}function v(m,g,S){if(["recovered","canonical"].some(W=>W in S))throw new Error("sign() legacy options not supported");let{lowS:A,prehash:D,extraEntropy:I}=as(S,p);m=O(m,D);let B=P(m),R=Ve(i,g),U=[k(R),k(B)];if(I!=null&&I!==!1){let W=I===!0?n(d.secretKey):I;U.push(z("extraEntropy",W))}let Z=lt(...U),q=B;function F(W){let J=T(W);if(!i.isValidNot0(J))return;let dt=i.inv(J),X=e.BASE.multiply(J).toAffine(),at=i.create(X.x);if(at===Wt)return;let Ur=i.create(dt*i.create(q+at*R));if(Ur===Wt)return;let $s=(X.x===at?0:2)|Number(X.y&He),js=Ur;return A&&E(Ur)&&(js=i.neg(Ur),$s^=1),new w(at,js,$s)}return{seed:Z,k2sig:F}}function C(m,g,S={}){m=z("message",m);let{seed:A,k2sig:D}=v(m,g,S);return $i(t.outputLen,i.BYTES,o)(A,D)}function N(m){let g,S=typeof m=="string"||Nt(m),A=!S&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!S&&!A)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(A)g=new w(m.r,m.s);else if(S){try{g=w.fromBytes(z("sig",m),"der")}catch(D){if(!(D instanceof Zt.Err))throw D}if(!g)try{g=w.fromBytes(z("sig",m),"compact")}catch{return!1}}return g||!1}function L(m,g,S,A={}){let{lowS:D,prehash:I,format:B}=as(A,p);if(S=z("publicKey",S),g=O(z("message",g),I),"strict"in A)throw new Error("options.strict was renamed to lowS");let R=B===void 0?N(m):w.fromBytes(z("sig",m),B);if(R===!1)return!1;try{let U=e.fromBytes(S);if(D&&R.hasHighS())return!1;let{r:Z,s:q}=R,F=P(g),W=i.inv(q),J=i.create(F*W),dt=i.create(Z*W),X=e.BASE.multiplyUnsafe(J).add(U.multiplyUnsafe(dt));return X.is0()?!1:i.create(X.x)===Z}catch{return!1}}function b(m,g,S={}){let{prehash:A}=as(S,p);return g=O(g,A),w.fromBytes(m,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:h,getSharedSecret:f,utils:l,lengths:d,Point:e,sign:C,verify:L,recoverPublicKey:b,Signature:w,hash:t})}function el(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=xt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function rl(e){let{CURVE:t,curveOpts:r}=el(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function nl(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Xr(r.Fn.ORDER,r.Fn.BITS))})}function La(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=rl(e),s=Qf(t,r),i=tl(s,n,o);return nl(e,i)}function Da(e,t){let r=n=>La({...e,hash:n});return{...r(t),create:r}}var ls={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ol={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Pa=BigInt(2);function sl(e){let t=ls.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,h=u*u*e%t,f=j(h,r,t)*h%t,l=j(f,r,t)*h%t,d=j(l,Pa,t)*u%t,p=j(d,o,t)*d%t,x=j(p,s,t)*p%t,E=j(x,c,t)*x%t,y=j(E,a,t)*E%t,_=j(y,c,t)*x%t,w=j(_,r,t)*h%t,T=j(w,i,t)*p%t,P=j(T,n,t)*u%t,M=j(P,Pa,t);if(!fs.eql(fs.sqr(M),e))throw new Error("Cannot find square root");return M}var fs=xt(ls.p,{sqrt:sl}),$e=Da({...ls,Fp:fs,lowS:!0,endo:ol},Ki);function Ra(e,t,r,n){let o=ir.digest(r instanceof Uint8Array?r:r.subarray());if(rn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),$e.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new wr(String(s))});try{return n?.signal?.throwIfAborted(),$e.verify(t,o.digest,e)}catch(s){throw new wr(String(s))}}var ln=class{type="secp256k1";raw;_key;constructor(t){this._key=Na(t),this.raw=Oa(this._key)}toMultihash(){return At.digest(Le(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r,n){return Ra(this._key,r,t,n)}};function Ua(e){return new ln(e)}function Oa(e){return $e.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Na(e){try{return $e.ProjectivePoint.fromHex(e),e}catch(t){throw new Mr(String(t))}}function ka(e){let{Type:t,Data:r}=_r.decode(e.digest),n=r??new Uint8Array;switch(t){case Et.Ed25519:return ma(n);case Et.secp256k1:return Ua(n);case Et.ECDSA:return Si(n);default:throw new er}}function Le(e){return _r.encode({Type:Et[e.type],Data:e.raw})}var Ma=Symbol.for("nodejs.util.inspect.custom"),il=114,Ar=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()})`}[Kn]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(il,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ft(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ft(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ma](){return`PeerId(${this.toString()})`}},hn=class extends Ar{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},dn=class extends Ar{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},pn=class extends Ar{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},al=2336,mn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(V(this.url))}[Ma](){return`PeerId(${this.url})`}[Kn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(al,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=$(t)),t.toString()===this.toString())}};function gn(e){if(ul(e))return new hn({multihash:e});if(cl(e))try{let t=ka(e);if(t.type==="Ed25519")return new dn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new pn({multihash:e,publicKey:t})}catch{let r=$(e.digest);return new mn(new URL(r))}throw new Fr("Supplied PeerID Multihash is invalid")}function cl(e){return e.code===At.code}function ul(e){return e.code===ir.code}function hs(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function yn(e){let t=ue(G.decode(`z${e}`));return gn(t)}var bn=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.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 hs(this.set.entries(),t=>{let r=yn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=yn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return hs(this.set.values(),t=>yn(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function ds(){return new bn}var ps={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Fa={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ka=new globalThis.TextEncoder;function fl(e,t){let r=ps[t],n=Fa[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function ll(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=ps[t],o=Fa[t],s=e;for(;s.length>0;){let i=Ka.encodeInto(s,r);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(r[c]),o=BigInt.asUintN(t,o*n)}return o}function ms(e,{size:t=32,utf8Buffer:r}={}){if(!ps[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof e=="string"){if(r)return ll(e,t,r);e=Ka.encode(e)}return fl(e,t)}var Ir={hash:e=>Number(ms(e,{size:32})),hashV:(e,t)=>hl(Ir.hash(e,t))};function hl(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),V(t,"base16")}var gs=64,Ct=class{fp;h;seed;constructor(t,r,n,o=2){if(o>gs)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=It(o);for(let c=0;c<i.length;c++)i[c]=s[c];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ft(this.fp,t.fp):!1}};function be(e,t){return Math.floor(Math.random()*(t-e))+e}var xe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Ct))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Ct))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=t,!0;return!0}swap(t){if(!(t instanceof Ct))throw new TypeError("Invalid Fingerprint");let r=be(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=t,n}remove(t){if(!(t instanceof Ct))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var dl=500,Br=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Ir,this.seed=t.seed??be(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=V(t));let r=new Ct(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new xe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new xe(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[be(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize));for(let c=0;c<dl;c++){let a=this.buckets[i].swap(r);if(a!=null&&(i=(i^a.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize)),this.buckets[i].add(a)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=V(t));let r=new Ct(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(t){typeof t=="string"&&(t=V(t));let r=new Ct(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},pl={1:.5,2:.84,4:.95,8:.98};function ml(e=.001){return e>.002?2:e>1e-5?4:8}function za(e,t=.001){let r=ml(t),n=pl[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),gs);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var xn=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??Ir,this.seed=t.seed??be(0,Math.pow(2,10)),this.filterSeries=[new Br({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=V(t)),this.has(t))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new Br({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(t)}has(t){typeof t=="string"&&(t=V(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=V(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,r)=>t+r.count,0)}};function ys(e,t=.001,r){return new xn({...za(e,t),...r??{}})}var wn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}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 r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,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 h=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let l=Number.parseInt(f,t);if(!Number.isNaN(l))return l});if(h===void 0)break;if(s*=t,s+=h,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[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];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;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 r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var qa=45,gl=15,je=new wn;function En(e){if(!(e.length>gl))return je.new(e).parseWith(()=>je.readIPv4Addr())}function vn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>qa))return je.new(e).parseWith(()=>je.readIPv6Addr())}function Ge(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>qa)return;let r=je.new(e).parseWith(()=>je.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function Va(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Ha(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function bs(e){switch(e.length){case we:return e.join(".");case Ee:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function $a(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function ja(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var we=4,Ee=16,py=parseInt("0xFFFF",16),yl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Tr(e,t){t.length===Ee&&e.length===we&&Va(t,0,11)&&(t=t.slice(12)),t.length===we&&e.length===Ee&&Ha(e,yl,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function Ga(e,t){if(typeof t=="string"&&(t=Ge(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function xs(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=we,o=En(t);if(o==null&&(n=Ee,o=vn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+e);let i=ws(s,8*n);return{network:Tr(o,i),mask:i}}function ws(e,t){if(t!==8*we&&t!==8*Ee)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var Ze=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=xs(t));else{let n=Ge(t);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Ge(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ws(o,8*n.length);this.network=Tr(n,this.mask)}}contains(t){return Ga({network:this.network,mask:this.mask},t)}toString(){let t=$a(this.mask),r=t!==-1?String(t):ja(this.mask);return bs(this.network)+"/"+r}};function Za(e,t){return new Ze(e).contains(t)}var it=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Xt=class extends Error{static name="ValidationError";name="ValidationError"},Cr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Sn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function We(e){return!!En(e)}function _n(e){return!!vn(e)}function vs(e){return t=>$(t,e)}function Ss(e){return t=>V(t,e)}function Xe(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function ve(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Wa(e){let t=e.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 r=V(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=ve(n);return Rt([r,o],r.length+o.length)}function Xa(e){let t=e.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 r=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=ve(n);return Rt([r,o],r.length+o.length)}function _s(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=$(t,"base32"),o=Xe(r);return`${n}:${o}`}var As=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new it("Invalid byte value in IP address");t[n]=o}),t},Ya=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=We(r[n]),i;s&&(i=As(r[n]),r[n]=$(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,$(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new it("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Qa=function(e){if(e.byteLength!==4)throw new it("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Ja=function(e){if(e.byteLength!==16)throw new it("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new it(`Invalid IPv6 address "${r}"`)}};function tc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new it(`Invalid IPv6 address "${e}"`)}}var Es=Object.values(ar).map(e=>e.decoder),bl=(function(){let e=Es[0].or(Es[1]);return Es.slice(2).forEach(t=>e=e.or(t)),e})();function ec(e){return bl.decode(e)}function rc(e){return t=>e.encoder.encode(t)}function xl(e){if(parseInt(e).toString()!==e)throw new Xt("Value must be an integer")}function wl(e){if(e<0)throw new Xt("Value must be a positive integer, or zero")}function El(e){return t=>{if(t>e)throw new Xt(`Value must be smaller than or equal to ${e}`)}}function vl(...e){return t=>{for(let r of e)r(t)}}var Lr=vl(xl,wl,El(65535));var ot=-1,Is=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Sn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},vt=new Is,Ql=[{code:4,name:"ip4",size:32,valueToBytes:As,bytesToValue:Qa,validate:e=>{if(!We(e))throw new Xt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ve,bytesToValue:Xe,validate:Lr},{code:273,name:"udp",size:16,valueToBytes:ve,bytesToValue:Xe,validate:Lr},{code:33,name:"dccp",size:16,valueToBytes:ve,bytesToValue:Xe,validate:Lr},{code:41,name:"ip6",size:128,valueToBytes:Ya,bytesToValue:Ja,stringToValue:tc,validate:e=>{if(!_n(e))throw new Xt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ot},{code:43,name:"ipcidr",size:8,bytesToValue:vs("base10"),valueToBytes:Ss("base10")},{code:53,name:"dns",size:ot,resolvable:!0},{code:54,name:"dns4",size:ot,resolvable:!0},{code:55,name:"dns6",size:ot,resolvable:!0},{code:56,name:"dnsaddr",size:ot,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:ve,bytesToValue:Xe,validate:Lr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ot,path:!0,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ot,bytesToValue:vs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ss("base58btc")(e):tt.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:_s,valueToBytes:Wa},{code:445,name:"onion3",size:296,bytesToValue:_s,valueToBytes:Xa},{code:446,name:"garlic64",size:ot},{code:447,name:"garlic32",size:ot},{code:448,name:"tls"},{code:449,name:"sni",size:ot},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ot,bytesToValue:rc(eo),valueToBytes:ec},{code:480,name:"http"},{code:481,name:"http-path",size:ot,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ot}];Ql.forEach(e=>{vt.addProtocol(e)});function nc(e){let t=[],r=0;for(;r<e.length;){let n=Er(e,r),o=vt.getProtocol(n),s=gt(n),i=Jl(o,e,r+s),c=0;i>0&&o.size===ot&&(c=gt(i));let a=s+c+i,u={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(i>0){let h=r+s+c,f=e.subarray(h,h+i);u.value=o.bytesToValue?.(f)??$(f)}t.push(u),r+=a}return t}function oc(e){let t=0,r=[];for(let n of e){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)??V(n.value),c=i.byteLength,o.size===ot&&(a=gt(c)));let u=new Uint8Array(s+a+c),h=0;Ke(n.code,u,h),h+=s,i!=null&&(o.size===ot&&(Ke(c,u,h),h+=a),u.set(i,h)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Rt(r,t)}function sc(e){if(e.charAt(0)!=="/")throw new it('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let c=s===e.length-1;if(i==="/"||c){let a=vt.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new it(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new it(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new it("Incomplete multiaddr");return t}function ic(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=vt.getProtocol(t.code);if(r==null)throw new it(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Jl(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Er(t,r)}var th=Symbol.for("nodejs.util.inspect.custom"),Ps=Symbol.for("@multiformats/multiaddr"),eh=[53,54,55,56],Ds=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function rh(e){if(e==null&&(e="/"),cc(e))return e.getComponents();if(e instanceof Uint8Array)return nc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),sc(e);if(Array.isArray(e))return e;throw new it("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Tn=class e{[Ps]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=rh(t),r.validate!==!1&&nh(this)}get bytes(){return this.#r==null&&(this.#r=oc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=ic(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,r,n,o,s="";for(let{code:c,name:a,value:u}of this.#t)c===42&&(s=`%${u??""}`),eh.includes(c)&&(r="tcp",o=443,n=`${u??""}${s}`,t=c===55?6:4),(c===6||c===273)&&(r=a==="tcp"?"tcp":"udp",o=parseInt(u??"")),(c===4||c===41)&&(r="tcp",n=`${u??""}${s}`,t=c===41?6:4);if(t==null||r==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:r,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:r})=>{let n=vt.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:r})=>{if(r==null)return[t];let n=vt.getProtocol(t),o=[t];return r!=null&&o.push(n.valueToBytes?.(r)??V(r)),o})}stringTuples(){return this.#t.map(({code:t,value:r})=>r==null?[t]:[t,r])}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Cr(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let r=t.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?$(G.decode(`z${n}`),"base58btc"):$(tt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(vt.getProtocol(t.code).path)return t.value??null;return null}equals(t){return ft(this.bytes,t.bytes)}async resolve(t){let r=this.protos().find(s=>s.resolvable);if(r==null)return[this];let n=ac.get(r.name);if(n==null)throw new Ds(`no available resolver for ${r.name}`);return(await n(this,t)).map(s=>Rr(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[th](){return`Multiaddr(${this.toString()})`}};function nh(e){e.getComponents().forEach(t=>{let r=vt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}var ac=new Map;function cc(e){return!!e?.[Ps]}function Rr(e){return new Tn(e)}function uc(e){try{for(let{code:t,value:r}of e.getComponents())if(r!=null&&t===41)return Za("2000::/3",r)}catch{}return!1}function fc(e){try{for(let{code:t}of e.getComponents())if(t!==42)return t===4||t===41}catch{}return!1}var hc=Bc(lc(),1),oh=["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"],sh=oh.map(e=>new hc.Netmask(e));function Rs(e){for(let t of sh)if(t.contains(e))return!0;return!1}function ih(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function ah(e){let t=e.split(":");if(t.length<2)return!1;let r=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(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return Rs(o)}function ch(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function uh(e){let t=e.split(":"),r=t[t.length-1];return Rs(r)}function fh(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^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(e)||/^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(e)||/^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(e)||/^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(e)||/^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(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function dc(e){if(We(e))return Rs(e);if(ih(e))return ah(e);if(ch(e))return uh(e);if(_n(e))return fh(e)}function Os(e){try{if(!fc(e))return!1;let[[,t]]=e.stringTuples();return t==null?!1:dc(t)??!1}catch{}return!0}function Qe(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}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}},Je=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 r=this.head;this.head=r.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 r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ns=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Ln(e={}){return lh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function lh(e,t){t=t??{};let r=t.onEnd,n=new Je,o,s,i,c=Qe(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((E,y)=>{s=_=>{s=null,n.push(_);try{E(e(n))}catch(w){y(w)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Qe()})}},u=E=>s!=null?s(E):(n.push(E),o),h=E=>(n=new Je,s!=null?s({error:E}):(n.push({error:E}),o)),f=E=>{if(i)return o;if(t?.objectMode!==!0&&E?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:E})},l=E=>i?o:(i=!0,E!=null?h(E):u({done:!0})),d=()=>(n=new Je,l(),{done:!0}),p=E=>(l(E),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:d,throw:p,push:f,end:l,get readableLength(){return n.size},onEmpty:async E=>{let y=E?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let _,w;y!=null&&(_=new Promise((T,P)=>{w=()=>{P(new Ns)},y.addEventListener("abort",w)}));try{await Promise.race([c.promise,_])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},r==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(E){return x.throw(E),r!=null&&(r(E),r=void 0),{done:!0}},return(){return x.return(),r!=null&&(r(),r=void 0),{done:!0}},push:f,end(E){return x.end(E),r!=null&&(r(E),r=void 0),o},get readableLength(){return x.readableLength},onEmpty:E=>x.onEmpty(E)},o}var Us=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ks=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},pc=e=>globalThis.DOMException===void 0?new ks(e):new DOMException(e),mc=e=>{let t=e.reason===void 0?pc("This operation was aborted."):e.reason;return t instanceof Error?t:pc(t)};function Ms(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,u=new Promise((h,f)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:d}=t;d.aborted&&f(mc(d)),c=()=>{f(mc(d))},d.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(h,f);return}let l=new Us;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(d){f(d)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?h():o instanceof Error?f(o):(l.message=o??`Promise timed out after ${r} milliseconds`,f(l))},r),(async()=>{try{h(await e)}catch(d){f(d)}})()}).finally(()=>{u.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var hh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function dh(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[t].flat(),a=[],{addListener:u,removeListener:h}=hh(e),f=(...d)=>{let p=r.multiArgs?d:d[0];r.filter&&!r.filter(p)||(a.push(p),r.count===a.length&&(n(),s(a)))},l=d=>{n(),i(d)};n=()=>{for(let d of c)h(d,f);for(let d of r.rejectionEvents)h(d,l)};for(let d of c)u(d,f);for(let d of r.rejectionEvents)u(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});if(o.cancel=n,typeof r.timeout=="number"){let s=Ms(o,{milliseconds:r.timeout});return s.cancel=n,s}return o}function tr(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=dh(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Nr(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Dn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Se=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function ph(e){return e.reason}async function Pn(e,t,r){if(t==null)return e;let n=r?.translateError??ph;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Rn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Qe(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Dt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function mh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var On=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=mh(),this.status="queued",this.fn=t,this.options=r,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((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Dt),this.cleanup())}async join(t={}){let r=new Rn(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Pn(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.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 Nn=class extends Kr{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=Nr(this.emitEmpty.bind(this),1),this.emitIdle=Nr(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 r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,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,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Dn;let n=new On(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).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 Dt)}),this.clear()}async onEmpty(t){this.size!==0&&await tr(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await tr(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await tr(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 r=Ln({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),r.end(a)},o=a=>{a.detail!=null&&r.push(a.detail)},s=a=>{n(a.detail.error)},i=()=>{n()},c=()=>{n(new Dt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",c);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",c),n()}}};function Un(e){let t=new globalThis.AbortController;function r(){t.abort();for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let s of e){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}var gh=4194304,kn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ks=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},zs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},qs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function yh(e){return typeof e?.closeRead=="function"}function bh(e){return typeof e?.close=="function"}function Fs(e){return yh(e)?e.readStatus==="closing"||e.readStatus==="closed":bh(e)?e.status!=="open":!1}function xh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function wh(e,t){let r=t?.maxBufferSize??gh,n=new et,o=Promise.withResolvers(),s=!1;if(!xh(e))throw new _t("Argument should be a Stream or a Multiaddr");let i=h=>{if(t?.stopPropagation,n.append(h.data),n.byteLength>r){let f=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${f} > ${r}`))}o.resolve()};e.addEventListener("message",i);let c=h=>{h.error!=null?o.reject(h.error):o.resolve()};e.addEventListener("close",c);let a=()=>{o.resolve()};e.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(h){if(s===!0)throw new kn("Stream was unwrapped");if(Fs(e)){if(h?.bytes==null)return null;if(n.byteLength<h.bytes)throw new Se(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let f=h?.bytes??1;for(;;){if(n.byteLength>=f){o.resolve();break}if(await Pn(o.promise,h?.signal),Fs(e)){if(n.byteLength===0&&h?.bytes==null)return null;break}o=Promise.withResolvers()}let l=h?.bytes??n.byteLength;if(n.byteLength<l){if(Fs(e))throw new Se(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return u.read(h)}let d=n.sublist(0,l);return n.consume(l),d},async write(h,f){if(s===!0)throw new kn("Stream was unwrapped");e.send(h)||await tr(e,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function Eh(e,t={}){let r=wh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=gt(t.maxDataLength));let n=t?.lengthDecoder??Er,o=t?.lengthEncoder??ga;return{async read(i){let c=-1,a=new et;for(;;){let h=await r.read({...i,bytes:1});if(h==null)break;a.append(h);try{c=n(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(c<0)throw new Ks("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new qs(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new zs(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:c});if(u==null)throw new Se(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw new Se(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(i,c){await r.write(new et(o(i.byteLength),i),c)},async writeV(i,c){let a=new et(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function Vs(e,t){let r=Eh(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.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:()=>r.unwrap()};return n}var Mn=class extends Nn{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function gc(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal};if(r?.timeout!=null){let h=Un([o.signal,AbortSignal.timeout(r.timeout)]);u.signal=h}s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let c=Nr(i,r?.debounce??100),a=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{s||(clearTimeout(n),c())},start:()=>{a||(a=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),a=!1}}}var Hs=class extends Map{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function yc(e){let{name:t,metrics:r}=e,n;return r!=null?n=new Hs({name:t,metrics:r}):n=new Map,n}var bc="libp2p",xc="autonat",wc="1.0.0";var H;(function(e){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=e.MessageType||(e.MessageType={}));let r;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(r||(r={})),(function(u){u.codec=()=>qe(r)})(t=e.MessageType||(e.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=e.ResponseStatus||(e.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=()=>qe(o)})(n=e.ResponseStatus||(e.ResponseStatus={}));let s;(function(u){let h;u.codec=()=>(h==null&&(h=Gt((f,l,d={})=>{if(d.lengthDelimited!==!1&&l.fork(),f.id!=null&&(l.uint32(10),l.bytes(f.id)),f.addrs!=null)for(let p of f.addrs)l.uint32(18),l.bytes(p);d.lengthDelimited!==!1&&l.ldelim()},(f,l,d={})=>{let p={addrs:[]},x=l==null?f.len:f.pos+l;for(;f.pos<x;){let E=f.uint32();switch(E>>>3){case 1:{p.id=f.bytes();break}case 2:{if(d.limits?.addrs!=null&&p.addrs.length===d.limits.addrs)throw new cn('Decode error - map field "addrs" had too many elements');p.addrs.push(f.bytes());break}default:{f.skipType(E&7);break}}}return p})),h),u.encode=f=>jt(f,u.codec()),u.decode=(f,l)=>$t(f,u.codec(),l)})(s=e.PeerInfo||(e.PeerInfo={}));let i;(function(u){let h;u.codec=()=>(h==null&&(h=Gt((f,l,d={})=>{d.lengthDelimited!==!1&&l.fork(),f.peer!=null&&(l.uint32(10),e.PeerInfo.codec().encode(f.peer,l)),d.lengthDelimited!==!1&&l.ldelim()},(f,l,d={})=>{let p={},x=l==null?f.len:f.pos+l;for(;f.pos<x;){let E=f.uint32();switch(E>>>3){case 1:{p.peer=e.PeerInfo.codec().decode(f,f.uint32(),{limits:d.limits?.peer});break}default:{f.skipType(E&7);break}}}return p})),h),u.encode=f=>jt(f,u.codec()),u.decode=(f,l)=>$t(f,u.codec(),l)})(i=e.Dial||(e.Dial={}));let c;(function(u){let h;u.codec=()=>(h==null&&(h=Gt((f,l,d={})=>{d.lengthDelimited!==!1&&l.fork(),f.status!=null&&(l.uint32(8),e.ResponseStatus.codec().encode(f.status,l)),f.statusText!=null&&(l.uint32(18),l.string(f.statusText)),f.addr!=null&&(l.uint32(26),l.bytes(f.addr)),d.lengthDelimited!==!1&&l.ldelim()},(f,l,d={})=>{let p={},x=l==null?f.len:f.pos+l;for(;f.pos<x;){let E=f.uint32();switch(E>>>3){case 1:{p.status=e.ResponseStatus.codec().decode(f);break}case 2:{p.statusText=f.string();break}case 3:{p.addr=f.bytes();break}default:{f.skipType(E&7);break}}}return p})),h),u.encode=f=>jt(f,u.codec()),u.decode=(f,l)=>$t(f,u.codec(),l)})(c=e.DialResponse||(e.DialResponse={}));let a;e.codec=()=>(a==null&&(a=Gt((u,h,f={})=>{f.lengthDelimited!==!1&&h.fork(),u.type!=null&&(h.uint32(8),e.MessageType.codec().encode(u.type,h)),u.dial!=null&&(h.uint32(18),e.Dial.codec().encode(u.dial,h)),u.dialResponse!=null&&(h.uint32(26),e.DialResponse.codec().encode(u.dialResponse,h)),f.lengthDelimited!==!1&&h.ldelim()},(u,h,f={})=>{let l={},d=h==null?u.len:u.pos+h;for(;u.pos<d;){let p=u.uint32();switch(p>>>3){case 1:{l.type=e.MessageType.codec().decode(u);break}case 2:{l.dial=e.Dial.codec().decode(u,u.uint32(),{limits:f.limits?.dial});break}case 3:{l.dialResponse=e.DialResponse.codec().decode(u,u.uint32(),{limits:f.limits?.dialResponse});break}default:{u.skipType(p&7);break}}}return l})),a),e.encode=u=>jt(u,e.codec()),e.decode=(u,h)=>$t(u,e.codec(),h)})(H||(H={}));var Bh=4,Th=8,Fn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${r.protocolPrefix??bc}/${xc}/${wc}`,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.connectionThreshold=r.connectionThreshold??80,this.maxMessageSize=r.maxMessageSize??8192,this.dialResults=yc({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=gc(this.findRandomPeers.bind(this),6e4),this.addressFilter=ys(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Zs]=["@libp2p/autonat"];get[Ws](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,r)=>{this.handleIncomingAutonatStream(t,r).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,r)=>{this.verifyExternalAddresses(r).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 r=Un([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:r})){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:r})}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,r){let n=AbortSignal.timeout(this.timeout);try{let o=Vs(t,{maxDataLength:this.maxMessageSize}).pb(H),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,r,{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,r,n){let o=this.components.addressManager.getAddresses().map(f=>f.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,c=s.peer;if(c?.id==null)return this.log.error("PeerId missing from message"),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=ue(c.id);i=gn(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!r.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,r.remotePeer),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let a=c.addrs.map(f=>Rr(f)).filter(f=>{try{let l=f.toOptions();return Os(f)?!1:l.host!==r.remoteAddr.toOptions().host?(this.log.trace("not dialing %a - target host did not match remote host %a",f,r.remoteAddr),!1):o.includes(l.host)?!1:this.components.transportManager.dialTransportForMultiaddr(f)==null?(this.log.trace("not dialing %a - transport unsupported",f),!1):!0}catch{return!1}}).map(f=>(f.getPeerId()==null&&(f=f.encapsulate(`/p2p/${i.toString()}`)),f));if(a.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",a.map(f=>f.toString()).join(", "),i);let u="",h=a[0];for(let f of a){let l;h=f;try{if(l=await this.components.connectionManager.openConnection(f,n),!l.remoteAddr.equals(f))throw this.log.error("tried to dial %a but dialed %a",f,l.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,f),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.OK,addr:l.remoteAddr.decapsulateCode(421).bytes}}}catch(d){this.log.error("could not dial %p - %e",i,d),u=d.message}finally{l!=null&&await l.close()}}return{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:h.bytes}}}getFirstUnverifiedMultiaddr(t,r){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())||o.multiaddr.toOptions().family===6&&(!r||!uc(o.multiaddr))||Os(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:ds(),queue:new Mn({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:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>i.toOptions().family===6),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,r,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=Vs(i).pb(H),[,a]=await Promise.all([c.write({type:H.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),c.read({signal:s})]);if(a.type!==H.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!==H.ResponseStatus.OK&&u!==H.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,a.dialResponse.status);return}if(o.networkSegments.includes(r)){this.log.trace("%a results included network segment %s",n.multiaddr,r);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(r),u===H.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===H.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Bh&&this.confirmAddress(o),o.failure===Th&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(c){i.abort(c)}}}hasConnectionCapacity(){let r=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return r/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 r=t.toOptions();return r.family===4?r.host.split(".")[0].padStart(3,"0"):r.host.split(":")[0].padStart(4,"0")}};function Ch(e={}){return t=>new Fn(t,e)}return Tc(Lh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|