@libp2p/autonat 2.0.31 → 2.0.32-776cb432d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PAutonat=(()=>{var Ma=Object.create;var mr=Object.defineProperty;var Fa=Object.getOwnPropertyDescriptor;var Ka=Object.getOwnPropertyNames;var za=Object.getPrototypeOf,qa=Object.prototype.hasOwnProperty;var Ha=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)mr(r,e,{get:t[e],enumerable:!0})},ps=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ka(t))!qa.call(r,o)&&o!==e&&mr(r,o,{get:()=>t[o],enumerable:!(n=Fa(t,o))||n.enumerable});return r};var Va=(r,t,e)=>(e=r!=null?Ma(za(r)):{},ps(t||!r||!r.__esModule?mr(e,"default",{value:r,enumerable:!0}):e,r)),ja=r=>ps(mr({},"__esModule",{value:!0}),r);var da=Ha(dr=>{(function(){var r,t,e,n,o,s,i,c;c=function(a){var u,l,f,h;return u=(a&255<<24)>>>24,l=(a&255<<16)>>>16,f=(a&65280)>>>8,h=a&255,[u,l,f,h].join(".")},i=function(a){var u,l,f,h,x,g;for(u=[],f=h=0;h<=3&&a.length!==0;f=++h){if(f>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}g=t(a),x=g[0],l=g[1],a=a.substring(l),u.push(x)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(a){return a.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(a){var u,l,f,h,x;for(h=0,u=10,l="9",f=0,a.length>1&&a[f]==="0"&&(a[f+1]==="x"||a[f+1]==="X"?(f+=2,u=16):"0"<=a[f+1]&&a[f+1]<="9"&&(f++,u=8,l="7")),x=f;f<a.length;){if("0"<=a[f]&&a[f]<=l)h=h*u+(e(a[f])-n)>>>0;else if(u===16)if("a"<=a[f]&&a[f]<="f")h=h*u+(10+e(a[f])-s)>>>0;else if("A"<=a[f]&&a[f]<="F")h=h*u+(10+e(a[f])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===x)throw new Error("empty octet");return[h,f]},r=function(){function a(u,l){var f,h,x,g;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(g=u.split("/",2),u=g[0],l=g[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(m){throw f=m,new Error("Invalid mask: "+l)}for(h=x=32;x>=0;h=--x)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(u)&this.maskLong)>>>0}catch(m){throw f=m,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var l,f,h;for(h=i(this.first),f=i(this.last),l=0;h<=f;)u(c(h),h,l),l++,h++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a}(),dr.ip2long=i,dr.long2ip=c,dr.Netmask=r}).call(dr)});var el={};bt(el,{autoNAT:()=>tl});var yn=Symbol.for("@libp2p/peer-id");var kt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Ut=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},gr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var yr=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 xr=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 ms=Symbol.for("@libp2p/service-capabilities"),gs=Symbol.for("@libp2p/service-dependencies");var Sn={};bt(Sn,{base58btc:()=>$,base58flickr:()=>Xa});var Ll=new Uint8Array(0);function ys(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 Nt(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 xs(r){return new TextEncoder().encode(r)}function bs(r){return new TextDecoder().decode(r)}function Ga(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function f(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var m=0,v=0,R=0,F=g.length;R!==F&&g[R]===0;)R++,m++;for(var E=(F-R)*l+1>>>0,d=new Uint8Array(E);R!==F;){for(var b=g[R],I=0,B=E-1;(b!==0||I<v)&&B!==-1;B--,I++)b+=256*d[B]>>>0,d[B]=b%c>>>0,b=b/c>>>0;if(b!==0)throw new Error("Non-zero carry");v=I,R++}for(var L=E-v;L!==E&&d[L]===0;)L++;for(var k=a.repeat(m);L<E;++L)k+=r.charAt(d[L]);return k}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var m=0;if(g[m]!==" "){for(var v=0,R=0;g[m]===a;)v++,m++;for(var F=(g.length-m)*u+1>>>0,E=new Uint8Array(F);g[m];){var d=e[g.charCodeAt(m)];if(d===255)return;for(var b=0,I=F-1;(d!==0||b<R)&&I!==-1;I--,b++)d+=c*E[I]>>>0,E[I]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");R=b,m++}if(g[m]!==" "){for(var B=F-R;B!==F&&E[B]===0;)B++;for(var L=new Uint8Array(v+(F-B)),k=v;B!==F;)L[k++]=E[B++];return L}}}function x(g){var m=h(g);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:x}}var $a=Ga,Za=$a,Es=Za;var xn=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")}},bn=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 Ss(this,t)}},wn=class{decoders;constructor(t){this.decoders=t}or(t){return Ss(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 Ss(r,t){return new wn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var En=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 xn(t,e,n),this.decoder=new bn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ve({name:r,prefix:t,encode:e,decode:n}){return new En(r,t,e,n)}function Qt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Es(e,r);return ve({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function Wa(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,u=0;for(let l=0;l<s;++l){let f=o[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,c+=e,c>=8&&(c-=8,i[u++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ya(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ve({prefix:t,name:r,encode(o){return Ya(o,n,e)},decode(o){return Wa(o,n,e,r)}})}var $=Qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xa=Qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var vn={};bt(vn,{base32:()=>Ot,base32hex:()=>ec,base32hexpad:()=>nc,base32hexpadupper:()=>oc,base32hexupper:()=>rc,base32pad:()=>Ja,base32padupper:()=>tc,base32upper:()=>Qa,base32z:()=>sc});var Ot=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Qa=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ja=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),tc=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ec=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rc=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),nc=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),oc=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),sc=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var An={};bt(An,{base36:()=>Ve,base36upper:()=>ic});var Ve=Qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ic=Qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ac=_s,vs=128,cc=127,uc=~cc,fc=Math.pow(2,31);function _s(r,t,e){t=t||[],e=e||0;for(var n=e;r>=fc;)t[e++]=r&255|vs,r/=128;for(;r&uc;)t[e++]=r&255|vs,r>>>=7;return t[e]=r|0,_s.bytes=e-n+1,t}var lc=_n,hc=128,As=127;function _n(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw _n.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&As)<<o:(i&As)*Math.pow(2,o),o+=7}while(i>=hc);return _n.bytes=s-n,e}var dc=Math.pow(2,7),pc=Math.pow(2,14),mc=Math.pow(2,21),gc=Math.pow(2,28),yc=Math.pow(2,35),xc=Math.pow(2,42),bc=Math.pow(2,49),wc=Math.pow(2,56),Ec=Math.pow(2,63),Sc=function(r){return r<dc?1:r<pc?2:r<mc?3:r<gc?4:r<yc?5:r<xc?6:r<bc?7:r<wc?8:r<Ec?9:10},vc={encode:ac,decode:lc,encodingLength:Sc},Ac=vc,je=Ac;function Ge(r,t=0){return[je.decode(r,t),je.decode.bytes]}function Ae(r,t,e=0){return je.encode(r,t,e),t}function _e(r){return je.encodingLength(r)}function ie(r,t){let e=t.byteLength,n=_e(r),o=n+_e(e),s=new Uint8Array(o+e);return Ae(r,s,0),Ae(e,s,n),s.set(t,o),new Ie(r,e,t,s)}function Mt(r){let t=Nt(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 Ie(e,o,i,t)}function Is(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ys(r.bytes,e.bytes)}}var Ie=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Bs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ic(e,In(r),t??$.encoder);default:return Bc(e,In(r),t??Ot.encoder)}}var Ls=new WeakMap;function In(r){let t=Ls.get(r);if(t==null){let e=new Map;return Ls.set(r,e),e}return t}var ot=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!==Lc)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=ie(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&&Is(t.multihash,n.multihash)}toString(t){return Bs(this,t)}toJSON(){return{"/":Bs(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??Ts(n,o,s.bytes))}else if(e[Tc]===!0){let{version:n,multihash:o,code:s}=e,i=Mt(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=Ts(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=Nt(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 Ie(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,c=n(),a=n(),u=e+a,l=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:l,size:u}}static parse(t,e){let[n,o]=_c(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 In(s).set(n,t),s}};function _c(r,t){switch(r[0]){case"Q":{let e=t??$;return[$.prefix,e.decode(`${$.prefix}${r}`)]}case $.prefix:{let e=t??$;return[$.prefix,e.decode(r)]}case Ot.prefix:{let e=t??Ot;return[Ot.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 Ic(r,t,e){let{prefix:n}=e;if(n!==$.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 Bc(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,Lc=18;function Ts(r,t,e){let n=_e(r),o=n+_e(t),s=new Uint8Array(o+e.byteLength);return Ae(r,s,0),Ae(t,s,n),s.set(e,o),s}var Tc=Symbol.for("@ipld/js-cid/CID");var Bn={};bt(Bn,{identity:()=>_t});var Rs=0,Rc="identity",Ps=Nt;function Pc(r){return ie(Rs,Ps(r))}var _t={code:Rs,name:Rc,encode:Ps,digest:Pc};function dt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function It(r=0){return new Uint8Array(r)}function yt(r=0){return new Uint8Array(r)}function wt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=yt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Cs=Symbol.for("@achingbrain/uint8arraylist");function Ds(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 wr(r){return!!r?.[Cs]}var rt=class r{bufs;length;[Cs]=!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(wr(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(wr(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=Ds(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ds(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(wr(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 wt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:wt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,l=e>c&&e<=a;if(u&&l){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(l){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!wr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=a;f+=l){l=0;for(let h=u;h>=0;h--){let x=this.get(f+h);if(n[h]!==x){l=Math.max(1,h-c[x]);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=yt(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=It(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=It(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=It(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=yt(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=It(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=It(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=It(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=It(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=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!dt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Ln={};bt(Ln,{base10:()=>Dc});var Dc=Qt({prefix:"9",name:"base10",alphabet:"0123456789"});var Tn={};bt(Tn,{base16:()=>Cc,base16upper:()=>kc});var Cc=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),kc=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Rn={};bt(Rn,{base2:()=>Uc});var Uc=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pn={};bt(Pn,{base256emoji:()=>Kc});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}"),Nc=ks.reduce((r,t,e)=>(r[e]=t,r),[]),Oc=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 Mc(r){return r.reduce((t,e)=>(t+=Nc[e],t),"")}function Fc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Oc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Kc=ve({prefix:"\u{1F680}",name:"base256emoji",encode:Mc,decode:Fc});var Dn={};bt(Dn,{base64:()=>zc,base64pad:()=>qc,base64url:()=>Hc,base64urlpad:()=>Vc});var zc=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qc=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Hc=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Vc=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Cn={};bt(Cn,{base8:()=>jc});var jc=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var kn={};bt(kn,{identity:()=>Gc});var Gc=ve({prefix:"\0",name:"identity",encode:r=>bs(r),decode:r=>xs(r)});var lh=new TextEncoder,hh=new TextDecoder;var On={};bt(On,{sha256:()=>Ze,sha512:()=>Wc});function Nn({name:r,code:t,encode:e}){return new Un(r,t,e)}var Un=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?ie(this.code,e):e.then(n=>ie(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ns(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ze=Nn({name:"sha2-256",code:18,encode:Ns("SHA-256")}),Wc=Nn({name:"sha2-512",code:19,encode:Ns("SHA-512")});var We={...kn,...Rn,...Cn,...Ln,...Tn,...vn,...An,...Sn,...Dn,...Pn},Ah={...On,...Bn};function Ms(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Os=Ms("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Mn=Ms("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=yt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Yc={utf8:Os,"utf-8":Os,hex:We.base16,latin1:Mn,ascii:Mn,binary:Mn,...We},Er=Yc;function Q(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function G(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Xc=parseInt("11111",2),Fn=parseInt("10000000",2),Qc=parseInt("01111111",2),Fs={0:Ye,1:Ye,2:Jc,3:ru,4:nu,5:eu,6:tu,16:Ye,22:Ye,48:Ye};function Kn(r,t={offset:0}){let e=r[t.offset]&Xc;if(t.offset++,Fs[e]!=null)return Fs[e](r,t);throw new Error("No decoder for tag "+e)}function Xe(r,t){let e=0;if((r[t.offset]&Fn)===Fn){let n=r[t.offset]&Qc,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=Kn(r,t);if(n===null)break;e.push(n)}return e}function Jc(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 tu(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 c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let l=0;for(let f=0;f<a.length;f++)l+=a[f]<<f*7;c+=`.${l}`,a=[]}}return c}function eu(r,t){return t.offset++,null}function ru(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 nu(r,t){let e=Xe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function ou(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new rt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function zn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=ou(r.byteLength);return new rt(Uint8Array.from([t.byteLength|Fn]),t)}function Ks(r){let t=new rt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new rt(Uint8Array.from([2]),zn(t),t)}function zs(r){let t=Uint8Array.from([0]),e=new rt(t,r);return new rt(Uint8Array.from([3]),zn(e),e)}function Sr(r,t=48){let e=new rt;for(let n of r)e.append(n);return new rt(Uint8Array.from([t]),zn(e),e)}async function qs(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var su=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),iu=Uint8Array.from([6,5,43,129,4,0,34]),au=Uint8Array.from([6,5,43,129,4,0,35]),cu={ext:!0,kty:"EC",crv:"P-256"},uu={ext:!0,kty:"EC",crv:"P-384"},fu={ext:!0,kty:"EC",crv:"P-521"},qn=32,Hn=48,Vn=66;function Hs(r){let t=Kn(r);return Vs(t)}function Vs(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===qn*2+1)return n=G(t.subarray(e,e+qn),"base64url"),o=G(t.subarray(e+qn),"base64url"),new Be({...cu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Hn*2+1)return n=G(t.subarray(e,e+Hn),"base64url"),o=G(t.subarray(e+Hn),"base64url"),new Be({...uu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Vn*2+1)return n=G(t.subarray(e,e+Vn),"base64url"),o=G(t.subarray(e+Vn),"base64url"),new Be({...fu,key_ops:["verify"],x:n,y:o});throw new Ut(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function js(r){return Sr([Ks(Uint8Array.from([1])),Sr([lu(r.crv)],160),Sr([zs(new rt(Uint8Array.from([4]),Q(r.x??"","base64url"),Q(r.y??"","base64url")))],161)]).subarray()}function lu(r){if(r==="P-256")return su;if(r==="P-384")return iu;if(r==="P-521")return au;throw new Ut(`Invalid curve ${r}`)}var Be=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=js(this.jwk)),this._raw}toMultihash(){return _t.digest(Le(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,e){return qs(this.jwk,e,t)}};var ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function hu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function vr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ce(r,...t){if(!hu(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 Gs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");vr(r.outputLen),vr(r.blockLen)}function Re(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 $s(r,t){ce(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Kt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ar(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Bt(r,t){return r<<32-t|r>>>t}function Zs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Qe(r){return typeof r=="string"&&(r=Zs(r)),ce(r),r}function jn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ce(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 Te=class{};function Gn(r){let t=n=>r().update(Qe(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function _r(r=32){if(ae&&typeof ae.getRandomValues=="function")return ae.getRandomValues(new Uint8Array(r));if(ae&&typeof ae.randomBytes=="function")return Uint8Array.from(ae.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function du(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),c=Number(e&s),a=n?4:0,u=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+u,c,n)}function Ws(r,t,e){return r&t^~r&e}function Ys(r,t,e){return r&t^r&e^t&e}var Je=class extends Te{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=Ar(this.buffer)}update(t){Re(this),t=Qe(t),ce(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Ar(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),$s(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Kt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;du(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Ar(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,l[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ir=BigInt(4294967295),Xs=BigInt(32);function pu(r,t=!1){return t?{h:Number(r&Ir),l:Number(r>>Xs&Ir)}:{h:Number(r>>Xs&Ir)|0,l:Number(r&Ir)|0}}function Qs(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=pu(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var $n=(r,t,e)=>r>>>e,Zn=(r,t,e)=>r<<32-e|t>>>e,ue=(r,t,e)=>r>>>e|t<<32-e,fe=(r,t,e)=>r<<32-e|t>>>e,tr=(r,t,e)=>r<<64-e|t>>>e-32,er=(r,t,e)=>r>>>e-32|t<<64-e;function Pt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Js=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ti=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ei=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ri=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ni=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),oi=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var gu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jt=new Uint32Array(64),Wn=class extends Je{constructor(t=32){super(64,t,8,!1),this.A=zt[0]|0,this.B=zt[1]|0,this.C=zt[2]|0,this.D=zt[3]|0,this.E=zt[4]|0,this.F=zt[5]|0,this.G=zt[6]|0,this.H=zt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)Jt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Jt[f-15],x=Jt[f-2],g=Bt(h,7)^Bt(h,18)^h>>>3,m=Bt(x,17)^Bt(x,19)^x>>>10;Jt[f]=m+Jt[f-7]+g+Jt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Bt(c,6)^Bt(c,11)^Bt(c,25),x=l+h+Ws(c,a,u)+gu[f]+Jt[f]|0,m=(Bt(n,2)^Bt(n,13)^Bt(n,22))+Ys(n,o,s)|0;l=u,u=a,a=c,c=i+x|0,i=s,s=o,o=n,n=x+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){Kt(Jt)}destroy(){this.set(0,0,0,0,0,0,0,0),Kt(this.buffer)}};var si=Qs(["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))),yu=si[0],xu=si[1],te=new Uint32Array(80),ee=new Uint32Array(80),Yn=class extends Je{constructor(t=64){super(128,t,16,!1),this.Ah=ct[0]|0,this.Al=ct[1]|0,this.Bh=ct[2]|0,this.Bl=ct[3]|0,this.Ch=ct[4]|0,this.Cl=ct[5]|0,this.Dh=ct[6]|0,this.Dl=ct[7]|0,this.Eh=ct[8]|0,this.El=ct[9]|0,this.Fh=ct[10]|0,this.Fl=ct[11]|0,this.Gh=ct[12]|0,this.Gl=ct[13]|0,this.Hh=ct[14]|0,this.Hl=ct[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:f,Fl:h,Gh:x,Gl:g,Hh:m,Hl:v}=this;return[t,e,n,o,s,i,c,a,u,l,f,h,x,g,m,v]}set(t,e,n,o,s,i,c,a,u,l,f,h,x,g,m,v){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=x|0,this.Gl=g|0,this.Hh=m|0,this.Hl=v|0}process(t,e){for(let E=0;E<16;E++,e+=4)te[E]=t.getUint32(e),ee[E]=t.getUint32(e+=4);for(let E=16;E<80;E++){let d=te[E-15]|0,b=ee[E-15]|0,I=ue(d,b,1)^ue(d,b,8)^$n(d,b,7),B=fe(d,b,1)^fe(d,b,8)^Zn(d,b,7),L=te[E-2]|0,k=ee[E-2]|0,O=ue(L,k,19)^tr(L,k,61)^$n(L,k,6),P=fe(L,k,19)^er(L,k,61)^Zn(L,k,6),U=ei(B,P,ee[E-7],ee[E-16]),C=ri(U,I,O,te[E-7],te[E-16]);te[E]=C|0,ee[E]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:f,El:h,Fh:x,Fl:g,Gh:m,Gl:v,Hh:R,Hl:F}=this;for(let E=0;E<80;E++){let d=ue(f,h,14)^ue(f,h,18)^tr(f,h,41),b=fe(f,h,14)^fe(f,h,18)^er(f,h,41),I=f&x^~f&m,B=h&g^~h&v,L=ni(F,b,B,xu[E],ee[E]),k=oi(L,R,d,I,yu[E],te[E]),O=L|0,P=ue(n,o,28)^tr(n,o,34)^tr(n,o,39),U=fe(n,o,28)^er(n,o,34)^er(n,o,39),C=n&s^n&c^s&c,tt=o&i^o&a^i&a;R=m|0,F=v|0,m=x|0,v=g|0,x=f|0,g=h|0,{h:f,l:h}=Pt(u|0,l|0,k|0,O|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let A=Js(O,U,tt);n=ti(A,k,P,C),o=A|0}({h:n,l:o}=Pt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Pt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Pt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=Pt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=Pt(this.Eh|0,this.El|0,f|0,h|0),{h:x,l:g}=Pt(this.Fh|0,this.Fl|0,x|0,g|0),{h:m,l:v}=Pt(this.Gh|0,this.Gl|0,m|0,v|0),{h:R,l:F}=Pt(this.Hh|0,this.Hl|0,R|0,F|0),this.set(n,o,s,i,c,a,u,l,f,h,x,g,m,v,R,F)}roundClean(){Kt(te,ee)}destroy(){Kt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ii=Gn(()=>new Wn);var ai=Gn(()=>new Yn);var to=BigInt(0),Jn=BigInt(1);function Pe(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function eo(r){if(!Pe(r))throw new Error("Uint8Array expected")}function Dt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function rr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function fi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?to:BigInt("0x"+r)}var li=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",bu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function re(r){if(eo(r),li)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=bu[r[e]];return t}var qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ci(r){if(r>=qt._0&&r<=qt._9)return r-qt._0;if(r>=qt.A&&r<=qt.F)return r-(qt.A-10);if(r>=qt.a&&r<=qt.f)return r-(qt.a-10)}function nr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(li)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=ci(r.charCodeAt(s)),c=ci(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Ht(r){return fi(re(r))}function le(r){return eo(r),fi(re(Uint8Array.from(r).reverse()))}function he(r,t){return nr(r.toString(16).padStart(t*2,"0"))}function De(r,t){return he(r,t).reverse()}function W(r,t,e){let n;if(typeof t=="string")try{n=nr(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Pe(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}function ne(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];eo(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 Xn=r=>typeof r=="bigint"&&to<=r;function Br(r,t,e){return Xn(r)&&Xn(t)&&Xn(e)&&t<=r&&r<e}function Et(r,t,e,n){if(!Br(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function hi(r){let t;for(t=0;r>to;r>>=Jn,t+=1);return t}var de=r=>(Jn<<BigInt(r))-Jn,Qn=r=>new Uint8Array(r),ui=r=>Uint8Array.from(r);function di(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=Qn(r),o=Qn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...f)=>e(o,n,...f),a=(f=Qn(0))=>{o=c(ui([0]),f),n=c(),f.length!==0&&(o=c(ui([1]),f),n=c())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=c();let x=n.slice();h.push(x),f+=n.length}return ne(...h)};return(f,h)=>{i(),a(f);let x;for(;!(x=h(u()));)a();return i(),x}}var wu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Pe(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Vt(r,t,e={}){let n=(o,s,i)=>{let c=wu[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}function Ce(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 pt=BigInt(0),st=BigInt(1),pe=BigInt(2),Eu=BigInt(3),mi=BigInt(4),gi=BigInt(5),yi=BigInt(8);function j(r,t){let e=r%t;return e>=pt?e:t+e}function Y(r,t,e){let n=r;for(;t-- >pt;)n*=n,n%=e;return n}function Lr(r,t){if(r===pt)throw new Error("invert: expected non-zero number");if(t<=pt)throw new Error("invert: expected positive modulus, got "+t);let e=j(r,t),n=t,o=pt,s=st,i=st,c=pt;for(;e!==pt;){let u=n/e,l=n%e,f=o-i*u,h=s-c*u;n=e,e=l,o=i,s=c,i=f,c=h}if(n!==st)throw new Error("invert: does not exist");return j(o,t)}function xi(r,t){let e=(r.ORDER+st)/mi,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function Su(r,t){let e=(r.ORDER-gi)/yi,n=r.mul(t,pe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,pe),o),c=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(c),t))throw new Error("Cannot find square root");return c}function vu(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-st,e=0;for(;t%pe===pt;)t/=pe,e++;let n=pe,o=jt(r);for(;pi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return xi;let s=o.pow(n,t),i=(t+st)/pe;return function(a,u){if(a.is0(u))return u;if(pi(a,u)!==1)throw new Error("Cannot find square root");let l=e,f=a.mul(a.ONE,s),h=a.pow(u,t),x=a.pow(u,i);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let g=1,m=a.sqr(h);for(;!a.eql(m,a.ONE);)if(g++,m=a.sqr(m),g===l)throw new Error("Cannot find square root");let v=st<<BigInt(l-g-1),R=a.pow(f,v);l=g,f=a.sqr(R),h=a.mul(h,f),x=a.mul(x,R)}return x}}function Au(r){return r%mi===Eu?xi:r%yi===gi?Su:vu(r)}var bi=(r,t)=>(j(r,t)&st)===st,_u=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ro(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=_u.reduce((n,o)=>(n[o]="function",n),t);return Vt(r,e)}function Iu(r,t,e){if(e<pt)throw new Error("invalid exponent, negatives unsupported");if(e===pt)return r.ONE;if(e===st)return t;let n=r.ONE,o=t;for(;e>pt;)e&st&&(n=r.mul(n,o)),o=r.sqr(o),e>>=st;return n}function ke(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function pi(r,t){let e=(r.ORDER-st)/pe,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 no(r,t){t!==void 0&&vr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function jt(r,t,e=!1,n={}){if(r<=pt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=no(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:de(o),ZERO:pt,ONE:st,create:a=>j(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return pt<=a&&a<r},is0:a=>a===pt,isOdd:a=>(a&st)===st,neg:a=>j(-a,r),eql:(a,u)=>a===u,sqr:a=>j(a*a,r),add:(a,u)=>j(a+u,r),sub:(a,u)=>j(a-u,r),mul:(a,u)=>j(a*u,r),pow:(a,u)=>Iu(c,a,u),div:(a,u)=>j(a*Lr(u,r),r),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>Lr(a,r),sqrt:n.sqrt||(a=>(i||(i=Au(r)),i(c,a))),toBytes:a=>e?De(a,s):he(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?le(a):Ht(a)},invertBatch:a=>ke(c,a),cmov:(a,u,l)=>l?u:a});return Object.freeze(c)}function wi(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 oo(r){let t=wi(r);return t+Math.ceil(t/2)}function Ei(r,t,e=!1){let n=r.length,o=wi(t),s=oo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?le(r):Ht(r),c=j(i,t-st)+st;return e?De(c,o):he(c,o)}var Si=BigInt(0),uo=BigInt(1);function so(r,t){let e=t.negate();return r?e:t}function Ai(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function io(r,t){Ai(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=de(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function vi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=uo);let u=t*n,l=u+Math.abs(c)-1,f=c===0,h=c<0,x=t%2!==0;return{nextN:a,offset:l,isZero:f,isNeg:h,isNegF:x,offsetF:u}}function Bu(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 Lu(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 ao=new WeakMap,_i=new WeakMap;function co(r){return _i.get(r)||1}function Tr(r,t){return{constTimeNegate:so,hasPrecomputes(e){return co(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Si;)n&uo&&(o=o.add(s)),s=s.double(),n>>=uo;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=io(n,t),i=[],c=e,a=c;for(let u=0;u<o;u++){a=c,i.push(a);for(let l=1;l<s;l++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,c=io(e,t);for(let a=0;a<c.windows;a++){let{nextN:u,offset:l,isZero:f,isNeg:h,isNegF:x,offsetF:g}=vi(o,a,c);o=u,f?i=i.add(so(x,n[g])):s=s.add(so(h,n[l]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=io(e,t);for(let c=0;c<i.windows&&o!==Si;c++){let{nextN:a,offset:u,isZero:l,isNeg:f}=vi(o,c,i);if(o=a,!l){let h=n[u];s=s.add(f?h.negate():h)}}return s},getPrecomputes(e,n,o){let s=ao.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&ao.set(n,o(s))),s},wNAFCached(e,n,o){let s=co(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=co(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Ai(n,t),_i.set(e,n),ao.delete(e)}}}function Rr(r,t,e,n){Bu(e,r),Lu(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,c=hi(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=de(a),l=new Array(Number(u)+1).fill(i),f=Math.floor((t.BITS-1)/a)*a,h=i;for(let x=f;x>=0;x-=a){l.fill(i);for(let m=0;m<s;m++){let v=n[m],R=Number(v>>BigInt(x)&u);l[R]=l[R].add(e[m])}let g=i;for(let m=l.length-1,v=i;m>0;m--)v=v.add(l[m]),g=g.add(v);if(h=h.add(g),x!==0)for(let m=0;m<a;m++)h=h.double()}return h}function or(r){return ro(r.Fp),Vt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...no(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ct=BigInt(0),mt=BigInt(1),Ii=BigInt(2),Tu=BigInt(8),Ru={zip215:!0};function Pu(r){let t=or(r);return Vt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Bi(r){let t=Pu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,u=Ii<<BigInt(c*8)-mt,l=e.create,f=jt(t.n,t.nBitLength);function h(w,p){let y=e.sqr(w),_=e.sqr(p),D=e.add(e.mul(t.a,y),_),N=e.add(e.ONE,e.mul(t.d,e.mul(y,_)));return e.eql(D,N)}if(!h(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let x=t.uvRatio||((w,p)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(p))}}catch{return{isValid:!1,value:Ct}}}),g=t.adjustScalarBytes||(w=>w),m=t.domain||((w,p,y)=>{if(Dt("phflag",y),p.length||y)throw new Error("Contexts/pre-hash are not supported");return w});function v(w,p,y=!1){let _=y?mt:Ct;Et("coordinate "+w,p,_,u)}function R(w){if(!(w instanceof d))throw new Error("ExtendedPoint expected")}let F=Ce((w,p)=>{let{ex:y,ey:_,ez:D}=w,N=w.is0();p==null&&(p=N?Tu:e.inv(D));let M=l(y*p),K=l(_*p),z=l(D*p);if(N)return{x:Ct,y:mt};if(z!==mt)throw new Error("invZ was invalid");return{x:M,y:K}}),E=Ce(w=>{let{a:p,d:y}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:_,ey:D,ez:N,et:M}=w,K=l(_*_),z=l(D*D),H=l(N*N),et=l(H*H),J=l(K*p),at=l(H*l(J+z)),gt=l(et+l(y*l(K*z)));if(at!==gt)throw new Error("bad point: equation left != right (1)");let nt=l(_*D),ut=l(N*M);if(nt!==ut)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(p,y,_,D){v("x",p),v("y",y),v("z",_,!0),v("t",D),this.ex=p,this.ey=y,this.ez=_,this.et=D,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof d)throw new Error("extended point not allowed");let{x:y,y:_}=p||{};return v("x",y),v("y",_),new d(y,_,mt,l(y*_))}static normalizeZ(p){let y=ke(e,p.map(_=>_.ez));return p.map((_,D)=>_.toAffine(y[D])).map(d.fromAffine)}static msm(p,y){return Rr(d,f,p,y)}_setWindowSize(p){B.setWindowSize(this,p)}assertValidity(){E(this)}equals(p){R(p);let{ex:y,ey:_,ez:D}=this,{ex:N,ey:M,ez:K}=p,z=l(y*K),H=l(N*D),et=l(_*K),J=l(M*D);return z===H&&et===J}is0(){return this.equals(d.ZERO)}negate(){return new d(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:p}=t,{ex:y,ey:_,ez:D}=this,N=l(y*y),M=l(_*_),K=l(Ii*l(D*D)),z=l(p*N),H=y+_,et=l(l(H*H)-N-M),J=z+M,at=J-K,gt=z-M,nt=l(et*at),ut=l(J*gt),xt=l(et*gt),At=l(at*J);return new d(nt,ut,At,xt)}add(p){R(p);let{a:y,d:_}=t,{ex:D,ey:N,ez:M,et:K}=this,{ex:z,ey:H,ez:et,et:J}=p,at=l(D*z),gt=l(N*H),nt=l(K*_*J),ut=l(M*et),xt=l((D+N)*(z+H)-at-gt),At=ut-nt,qe=ut+nt,ds=l(gt-y*at),ka=l(xt*At),Ua=l(qe*ds),Na=l(xt*ds),Oa=l(At*qe);return new d(ka,Ua,Oa,Na)}subtract(p){return this.add(p.negate())}wNAF(p){return B.wNAFCached(this,p,d.normalizeZ)}multiply(p){let y=p;Et("scalar",y,mt,n);let{p:_,f:D}=this.wNAF(y);return d.normalizeZ([_,D])[0]}multiplyUnsafe(p,y=d.ZERO){let _=p;return Et("scalar",_,Ct,n),_===Ct?I:this.is0()||_===mt?this:B.wNAFCachedUnsafe(this,_,d.normalizeZ,y)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return B.unsafeLadder(this,n).is0()}toAffine(p){return F(this,p)}clearCofactor(){let{h:p}=t;return p===mt?this:this.multiplyUnsafe(p)}static fromHex(p,y=!1){let{d:_,a:D}=t,N=e.BYTES;p=W("pointHex",p,N),Dt("zip215",y);let M=p.slice(),K=p[N-1];M[N-1]=K&-129;let z=le(M),H=y?u:e.ORDER;Et("pointHex.y",z,Ct,H);let et=l(z*z),J=l(et-mt),at=l(_*et-D),{isValid:gt,value:nt}=x(J,at);if(!gt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(nt&mt)===mt,xt=(K&128)!==0;if(!y&&nt===Ct&&xt)throw new Error("Point.fromHex: x=0 and x_0=1");return xt!==ut&&(nt=l(-nt)),d.fromAffine({x:nt,y:z})}static fromPrivateKey(p){let{scalar:y}=O(p);return b.multiply(y)}toRawBytes(){let{x:p,y}=this.toAffine(),_=De(y,e.BYTES);return _[_.length-1]|=p&mt?128:0,_}toHex(){return re(this.toRawBytes())}}d.BASE=new d(t.Gx,t.Gy,mt,l(t.Gx*t.Gy)),d.ZERO=new d(Ct,mt,mt,Ct);let{BASE:b,ZERO:I}=d,B=Tr(d,c*8);function L(w){return j(w,n)}function k(w){return L(le(w))}function O(w){let p=e.BYTES;w=W("private key",w,p);let y=W("hashed private key",s(w),2*p),_=g(y.slice(0,p)),D=y.slice(p,2*p),N=k(_);return{head:_,prefix:D,scalar:N}}function P(w){let{head:p,prefix:y,scalar:_}=O(w),D=b.multiply(_),N=D.toRawBytes();return{head:p,prefix:y,scalar:_,point:D,pointBytes:N}}function U(w){return P(w).pointBytes}function C(w=Uint8Array.of(),...p){let y=ne(...p);return k(s(m(y,W("context",w),!!o)))}function tt(w,p,y={}){w=W("message",w),o&&(w=o(w));let{prefix:_,scalar:D,pointBytes:N}=P(p),M=C(y.context,_,w),K=b.multiply(M).toRawBytes(),z=C(y.context,K,N,w),H=L(M+z*D);Et("signature.s",H,Ct,n);let et=ne(K,De(H,e.BYTES));return W("result",et,e.BYTES*2)}let A=Ru;function S(w,p,y,_=A){let{context:D,zip215:N}=_,M=e.BYTES;w=W("signature",w,2*M),p=W("message",p),y=W("publicKey",y,M),N!==void 0&&Dt("zip215",N),o&&(p=o(p));let K=le(w.slice(M,2*M)),z,H,et;try{z=d.fromHex(y,N),H=d.fromHex(w.slice(0,M),N),et=b.multiplyUnsafe(K)}catch{return!1}if(!N&&z.isSmallOrder())return!1;let J=C(D,H.toRawBytes(),z.toRawBytes(),p);return H.add(z.multiplyUnsafe(J)).subtract(et).clearCofactor().equals(d.ZERO)}return b._setWindowSize(8),{CURVE:t,getPublicKey:U,sign:tt,verify:S,ExtendedPoint:d,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,p=d.BASE){return p._setWindowSize(w),p.multiply(BigInt(3)),p}}}}var fo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Li=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Bd=BigInt(0),Du=BigInt(1),Ti=BigInt(2),Ld=BigInt(3),Cu=BigInt(5),ku=BigInt(8);function Uu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=fo,c=r*r%s*r%s,a=Y(c,Ti,s)*c%s,u=Y(a,Du,s)*r%s,l=Y(u,Cu,s)*u%s,f=Y(l,t,s)*l%s,h=Y(f,e,s)*f%s,x=Y(h,n,s)*h%s,g=Y(x,o,s)*x%s,m=Y(g,o,s)*x%s,v=Y(m,t,s)*l%s;return{pow_p_5_8:Y(v,Ti,s)*r%s,b2:c}}function Nu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ou(r,t){let e=fo,n=j(t*t*t,e),o=j(n*n*t,e),s=Uu(r*o).pow_p_5_8,i=j(r*n*s,e),c=j(t*i*i,e),a=i,u=j(i*Li,e),l=c===r,f=c===j(-r,e),h=c===j(-r*Li,e);return l&&(i=a),(f||h)&&(i=u),bi(i,e)&&(i=j(-i,e)),{isValid:l||f,value:i}}var Ri=jt(fo,void 0,!0),Mu={a:Ri.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ri,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:ku,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ai,randomBytes:_r,adjustScalarBytes:Nu,uvRatio:Ou},Pi=Bi(Mu);var Pr=32;function Di(r,t,e){return Pi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Dr=class{type="Ed25519";raw;constructor(t){this.raw=lo(t,Pr)}toMultihash(){return _t.digest(Le(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e){return Di(this.raw,e,t)}};function ki(r){return r=lo(r,Pr),new Dr(r)}function lo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Ut(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Ku=Math.pow(2,7),zu=Math.pow(2,14),qu=Math.pow(2,21),ho=Math.pow(2,28),po=Math.pow(2,35),mo=Math.pow(2,42),go=Math.pow(2,49),q=128,ft=127;function lt(r){if(r<Ku)return 1;if(r<zu)return 2;if(r<qu)return 3;if(r<ho)return 4;if(r<po)return 5;if(r<mo)return 6;if(r<go)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function yo(r,t,e=0){switch(lt(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Hu(r,t,e=0){switch(lt(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function xo(r,t){let e=r[t],n=0;if(n+=e&ft,e<q||(e=r[t+1],n+=(e&ft)<<7,e<q)||(e=r[t+2],n+=(e&ft)<<14,e<q)||(e=r[t+3],n+=(e&ft)<<21,e<q)||(e=r[t+4],n+=(e&ft)*ho,e<q)||(e=r[t+5],n+=(e&ft)*po,e<q)||(e=r[t+6],n+=(e&ft)*mo,e<q)||(e=r[t+7],n+=(e&ft)*go,e<q))return n;throw new RangeError("Could not decode varint")}function Vu(r,t){let e=r.get(t),n=0;if(n+=e&ft,e<q||(e=r.get(t+1),n+=(e&ft)<<7,e<q)||(e=r.get(t+2),n+=(e&ft)<<14,e<q)||(e=r.get(t+3),n+=(e&ft)<<21,e<q)||(e=r.get(t+4),n+=(e&ft)*ho,e<q)||(e=r.get(t+5),n+=(e&ft)*po,e<q)||(e=r.get(t+6),n+=(e&ft)*mo,e<q)||(e=r.get(t+7),n+=(e&ft)*go,e<q))return n;throw new RangeError("Could not decode varint")}function oe(r,t,e=0){return t==null&&(t=yt(lt(r))),t instanceof Uint8Array?yo(r,t,e):Hu(r,t,e)}function Gt(r,t=0){return r instanceof Uint8Array?xo(r,t):Vu(r,t)}var wo=new Float32Array([-0]),se=new Uint8Array(wo.buffer);function Ui(r,t,e){wo[0]=r,t[e]=se[0],t[e+1]=se[1],t[e+2]=se[2],t[e+3]=se[3]}function Ni(r,t){return se[0]=r[t],se[1]=r[t+1],se[2]=r[t+2],se[3]=r[t+3],wo[0]}var Eo=new Float64Array([-0]),ht=new Uint8Array(Eo.buffer);function Oi(r,t,e){Eo[0]=r,t[e]=ht[0],t[e+1]=ht[1],t[e+2]=ht[2],t[e+3]=ht[3],t[e+4]=ht[4],t[e+5]=ht[5],t[e+6]=ht[6],t[e+7]=ht[7]}function Mi(r,t){return ht[0]=r[t],ht[1]=r[t+1],ht[2]=r[t+2],ht[3]=r[t+3],ht[4]=r[t+4],ht[5]=r[t+5],ht[6]=r[t+6],ht[7]=r[t+7],Eo[0]}var ju=BigInt(Number.MAX_SAFE_INTEGER),Gu=BigInt(Number.MIN_SAFE_INTEGER),St=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 me;if(t<ju&&t>Gu)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>Fi&&(o=0n,++n>Fi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return me;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):me}},me=new St(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var Fi=4294967296n;function Ki(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 zi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function So(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 Lt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Cr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var vo=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,Lt(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 Lt(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=Ni(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=Mi(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 Lt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return zi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(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 St(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 Lt(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 Lt(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 Lt(this,8);let t=Cr(this.buf,this.pos+=4),e=Cr(this.buf,this.pos+=4);return new St(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=xo(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 Ao(r){return new vo(r instanceof Uint8Array?r:r.subarray())}function $t(r,t,e){let n=Ao(r);return t.decode(n,void 0,e)}function _o(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return yt(i);o+i>t&&(n=yt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var ge=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Io(){}var Lo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},$u=_o();function Zu(r){return globalThis.Buffer!=null?yt(r):$u(r)}var ir=class{len;head;tail;states;constructor(){this.len=0,this.head=new ge(Io,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ge(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new To((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(kr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=St.fromBigInt(t);return this._push(kr,e.length(),e)}uint64Number(t){return this._push(yo,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=St.fromBigInt(t).zzEncode();return this._push(kr,e.length(),e)}sint64Number(t){let e=St.fromNumber(t).zzEncode();return this._push(kr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Bo,1,t?1:0)}fixed32(t){return this._push(sr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=St.fromBigInt(t);return this._push(sr,4,e.lo)._push(sr,4,e.hi)}fixed64Number(t){let e=St.fromNumber(t);return this._push(sr,4,e.lo)._push(sr,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(Ui,4,t)}double(t){return this._push(Oi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Bo,1,0):this.uint32(e)._push(Yu,e,t)}string(t){let e=Ki(t);return e!==0?this.uint32(e)._push(So,e,t):this._push(Bo,1,0)}fork(){return this.states=new Lo(this),this.head=this.tail=new ge(Io,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 ge(Io,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=Zu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Bo(r,t,e){t[e]=r&255}function Wu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var To=class extends ge{next;constructor(t,e){super(Wu,t,e),this.next=void 0}};function kr(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 sr(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 Yu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ir.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Xu,t,r),this},ir.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Qu,t,r),this});function Xu(r,t,e){t.set(r,e)}function Qu(r,t,e){r.length<40?So(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Q(r),e)}function Ro(){return new ir}function Zt(r,t){let e=Ro();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ue;(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"})(Ue||(Ue={}));function Ur(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ne(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Ur("enum",Ue.VARINT,e,n)}function Wt(r,t){return Ur("message",Ue.LENGTH_DELIMITED,r,t)}var Nr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var vt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(vt||(vt={}));var Po;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Po||(Po={}));(function(r){r.codec=()=>Ne(Po)})(vt||(vt={}));var ar;(function(r){let t;r.codec=()=>(t==null&&(t=Wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),vt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=vt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(ar||(ar={}));var Do;(function(r){let t;r.codec=()=>(t==null&&(t=Wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),vt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=vt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(Do||(Do={}));var cr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Or=class extends Te{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Gs(t);let n=Qe(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),Kt(s)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),ce(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:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Co=(r,t,e)=>new Or(r,t).update(e).digest();Co.create=(r,t)=>new Or(r,t);function Hi(r){r.lowS!==void 0&&Dt("lowS",r.lowS),r.prehash!==void 0&&Dt("prehash",r.prehash)}function tf(r){let t=or(r);Vt(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var No=class extends Error{constructor(t=""){super(t)}},Yt={Err:No,_tlv:{encode:(r,t)=>{let{Err:e}=Yt;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=rr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?rr(o.length/2|128):"";return rr(r)+s+o+t},decode(r,t){let{Err:e}=Yt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Yt;if(r<Xt)throw new t("integer: negative integers are not allowed");let e=rr(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}=Yt;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 Ht(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Yt,o=W("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l}=n.decode(2,a);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=Yt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};function ko(r,t){return re(he(r,t))}var Xt=BigInt(0),it=BigInt(1),P0=BigInt(2),Uo=BigInt(3),ef=BigInt(4);function rf(r){let t=tf(r),{Fp:e}=t,n=jt(t.n,t.nBitLength),o=t.toBytes||((E,d,b)=>{let I=d.toAffine();return ne(Uint8Array.from([4]),e.toBytes(I.x),e.toBytes(I.y))}),s=t.fromBytes||(E=>{let d=E.subarray(1),b=e.fromBytes(d.subarray(0,e.BYTES)),I=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:b,y:I}});function i(E){let{a:d,b}=t,I=e.sqr(E),B=e.mul(I,E);return e.add(e.add(B,e.mul(E,d)),b)}function c(E,d){let b=e.sqr(d),I=i(E);return e.eql(b,I)}if(!c(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let a=e.mul(e.pow(t.a,Uo),ef),u=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(a,u)))throw new Error("bad curve params: a or b");function l(E){return Br(E,it,t.n)}function f(E){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:I,n:B}=t;if(d&&typeof E!="bigint"){if(Pe(E)&&(E=re(E)),typeof E!="string"||!d.includes(E.length))throw new Error("invalid private key");E=E.padStart(b*2,"0")}let L;try{L=typeof E=="bigint"?E:Ht(W("private key",E,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof E)}return I&&(L=j(L,B)),Et("private key",L,it,B),L}function h(E){if(!(E instanceof m))throw new Error("ProjectivePoint expected")}let x=Ce((E,d)=>{let{px:b,py:I,pz:B}=E;if(e.eql(B,e.ONE))return{x:b,y:I};let L=E.is0();d==null&&(d=L?e.ONE:e.inv(B));let k=e.mul(b,d),O=e.mul(I,d),P=e.mul(B,d);if(L)return{x:e.ZERO,y:e.ZERO};if(!e.eql(P,e.ONE))throw new Error("invZ was invalid");return{x:k,y:O}}),g=Ce(E=>{if(E.is0()){if(t.allowInfinityPoint&&!e.is0(E.py))return;throw new Error("bad point: ZERO")}let{x:d,y:b}=E.toAffine();if(!e.isValid(d)||!e.isValid(b))throw new Error("bad point: x or y not FE");if(!c(d,b))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(d,b,I){if(d==null||!e.isValid(d))throw new Error("x required");if(b==null||!e.isValid(b)||e.is0(b))throw new Error("y required");if(I==null||!e.isValid(I))throw new Error("z required");this.px=d,this.py=b,this.pz=I,Object.freeze(this)}static fromAffine(d){let{x:b,y:I}=d||{};if(!d||!e.isValid(b)||!e.isValid(I))throw new Error("invalid affine point");if(d instanceof m)throw new Error("projective point not allowed");let B=L=>e.eql(L,e.ZERO);return B(b)&&B(I)?m.ZERO:new m(b,I,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let b=ke(e,d.map(I=>I.pz));return d.map((I,B)=>I.toAffine(b[B])).map(m.fromAffine)}static fromHex(d){let b=m.fromAffine(s(W("pointHex",d)));return b.assertValidity(),b}static fromPrivateKey(d){return m.BASE.multiply(f(d))}static msm(d,b){return Rr(m,n,d,b)}_setWindowSize(d){F.setWindowSize(this,d)}assertValidity(){g(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){h(d);let{px:b,py:I,pz:B}=this,{px:L,py:k,pz:O}=d,P=e.eql(e.mul(b,O),e.mul(L,B)),U=e.eql(e.mul(I,O),e.mul(k,B));return P&&U}negate(){return new m(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b}=t,I=e.mul(b,Uo),{px:B,py:L,pz:k}=this,O=e.ZERO,P=e.ZERO,U=e.ZERO,C=e.mul(B,B),tt=e.mul(L,L),A=e.mul(k,k),S=e.mul(B,L);return S=e.add(S,S),U=e.mul(B,k),U=e.add(U,U),O=e.mul(d,U),P=e.mul(I,A),P=e.add(O,P),O=e.sub(tt,P),P=e.add(tt,P),P=e.mul(O,P),O=e.mul(S,O),U=e.mul(I,U),A=e.mul(d,A),S=e.sub(C,A),S=e.mul(d,S),S=e.add(S,U),U=e.add(C,C),C=e.add(U,C),C=e.add(C,A),C=e.mul(C,S),P=e.add(P,C),A=e.mul(L,k),A=e.add(A,A),C=e.mul(A,S),O=e.sub(O,C),U=e.mul(A,tt),U=e.add(U,U),U=e.add(U,U),new m(O,P,U)}add(d){h(d);let{px:b,py:I,pz:B}=this,{px:L,py:k,pz:O}=d,P=e.ZERO,U=e.ZERO,C=e.ZERO,tt=t.a,A=e.mul(t.b,Uo),S=e.mul(b,L),T=e.mul(I,k),w=e.mul(B,O),p=e.add(b,I),y=e.add(L,k);p=e.mul(p,y),y=e.add(S,T),p=e.sub(p,y),y=e.add(b,B);let _=e.add(L,O);return y=e.mul(y,_),_=e.add(S,w),y=e.sub(y,_),_=e.add(I,B),P=e.add(k,O),_=e.mul(_,P),P=e.add(T,w),_=e.sub(_,P),C=e.mul(tt,y),P=e.mul(A,w),C=e.add(P,C),P=e.sub(T,C),C=e.add(T,C),U=e.mul(P,C),T=e.add(S,S),T=e.add(T,S),w=e.mul(tt,w),y=e.mul(A,y),T=e.add(T,w),w=e.sub(S,w),w=e.mul(tt,w),y=e.add(y,w),S=e.mul(T,y),U=e.add(U,S),S=e.mul(_,y),P=e.mul(p,P),P=e.sub(P,S),S=e.mul(p,T),C=e.mul(_,C),C=e.add(C,S),new m(P,U,C)}subtract(d){return this.add(d.negate())}is0(){return this.equals(m.ZERO)}wNAF(d){return F.wNAFCached(this,d,m.normalizeZ)}multiplyUnsafe(d){let{endo:b,n:I}=t;Et("scalar",d,Xt,I);let B=m.ZERO;if(d===Xt)return B;if(this.is0()||d===it)return this;if(!b||F.hasPrecomputes(this))return F.wNAFCachedUnsafe(this,d,m.normalizeZ);let{k1neg:L,k1:k,k2neg:O,k2:P}=b.splitScalar(d),U=B,C=B,tt=this;for(;k>Xt||P>Xt;)k&it&&(U=U.add(tt)),P&it&&(C=C.add(tt)),tt=tt.double(),k>>=it,P>>=it;return L&&(U=U.negate()),O&&(C=C.negate()),C=new m(e.mul(C.px,b.beta),C.py,C.pz),U.add(C)}multiply(d){let{endo:b,n:I}=t;Et("scalar",d,it,I);let B,L;if(b){let{k1neg:k,k1:O,k2neg:P,k2:U}=b.splitScalar(d),{p:C,f:tt}=this.wNAF(O),{p:A,f:S}=this.wNAF(U);C=F.constTimeNegate(k,C),A=F.constTimeNegate(P,A),A=new m(e.mul(A.px,b.beta),A.py,A.pz),B=C.add(A),L=tt.add(S)}else{let{p:k,f:O}=this.wNAF(d);B=k,L=O}return m.normalizeZ([B,L])[0]}multiplyAndAddUnsafe(d,b,I){let B=m.BASE,L=(O,P)=>P===Xt||P===it||!O.equals(B)?O.multiplyUnsafe(P):O.multiply(P),k=L(this,b).add(L(d,I));return k.is0()?void 0:k}toAffine(d){return x(this,d)}isTorsionFree(){let{h:d,isTorsionFree:b}=t;if(d===it)return!0;if(b)return b(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:b}=t;return d===it?this:b?b(m,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Dt("isCompressed",d),this.assertValidity(),o(m,this,d)}toHex(d=!0){return Dt("isCompressed",d),re(this.toRawBytes(d))}}m.BASE=new m(t.Gx,t.Gy,e.ONE),m.ZERO=new m(e.ZERO,e.ONE,e.ZERO);let{endo:v,nBitLength:R}=t,F=Tr(m,v?Math.ceil(R/2):R);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:f,weierstrassEquation:i,isWithinCurveOrder:l}}function nf(r){let t=or(r);return Vt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Vi(r){let t=nf(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,c=2*e.BYTES+1;function a(A){return j(A,n)}function u(A){return Lr(A,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:h,isWithinCurveOrder:x}=rf({...t,toBytes(A,S,T){let w=S.toAffine(),p=e.toBytes(w.x),y=ne;return Dt("isCompressed",T),T?y(Uint8Array.from([S.hasEvenY()?2:3]),p):y(Uint8Array.from([4]),p,e.toBytes(w.y))},fromBytes(A){let S=A.length,T=A[0],w=A.subarray(1);if(S===i&&(T===2||T===3)){let p=Ht(w);if(!Br(p,it,e.ORDER))throw new Error("Point is not on curve");let y=h(p),_;try{_=e.sqrt(y)}catch(M){let K=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+K)}let D=(_&it)===it;return(T&1)===1!==D&&(_=e.neg(_)),{x:p,y:_}}else if(S===c&&T===4){let p=e.fromBytes(w.subarray(0,e.BYTES)),y=e.fromBytes(w.subarray(e.BYTES,2*e.BYTES));return{x:p,y}}else{let p=i,y=c;throw new Error("invalid Point, expected length of "+p+", or uncompressed "+y+", got "+S)}}});function g(A){let S=n>>it;return A>S}function m(A){return g(A)?a(-A):A}let v=(A,S,T)=>Ht(A.slice(S,T));class R{constructor(S,T,w){Et("r",S,it,n),Et("s",T,it,n),this.r=S,this.s=T,w!=null&&(this.recovery=w),Object.freeze(this)}static fromCompact(S){let T=o;return S=W("compactSignature",S,T*2),new R(v(S,0,T),v(S,T,2*T))}static fromDER(S){let{r:T,s:w}=Yt.toSig(W("DER",S));return new R(T,w)}assertValidity(){}addRecoveryBit(S){return new R(this.r,this.s,S)}recoverPublicKey(S){let{r:T,s:w,recovery:p}=this,y=B(W("msgHash",S));if(p==null||![0,1,2,3].includes(p))throw new Error("recovery id invalid");let _=p===2||p===3?T+t.n:T;if(_>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(p&1)===0?"02":"03",N=l.fromHex(D+ko(_,e.BYTES)),M=u(_),K=a(-y*M),z=a(w*M),H=l.BASE.multiplyAndAddUnsafe(N,K,z);if(!H)throw new Error("point at infinify");return H.assertValidity(),H}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new R(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return nr(this.toDERHex())}toDERHex(){return Yt.hexFromSig(this)}toCompactRawBytes(){return nr(this.toCompactHex())}toCompactHex(){let S=o;return ko(this.r,S)+ko(this.s,S)}}let F={isValidPrivateKey(A){try{return f(A),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let A=oo(t.n);return Ei(t.randomBytes(A),t.n)},precompute(A=8,S=l.BASE){return S._setWindowSize(A),S.multiply(BigInt(3)),S}};function E(A,S=!0){return l.fromPrivateKey(A).toRawBytes(S)}function d(A){if(typeof A=="bigint")return!1;if(A instanceof l)return!0;let T=W("key",A).length,w=e.BYTES,p=w+1,y=2*w+1;if(!(t.allowedPrivateKeyLengths||o===p))return T===p||T===y}function b(A,S,T=!0){if(d(A)===!0)throw new Error("first arg must be private key");if(d(S)===!1)throw new Error("second arg must be public key");return l.fromHex(S).multiply(f(A)).toRawBytes(T)}let I=t.bits2int||function(A){if(A.length>8192)throw new Error("input is too large");let S=Ht(A),T=A.length*8-s;return T>0?S>>BigInt(T):S},B=t.bits2int_modN||function(A){return a(I(A))},L=de(s);function k(A){return Et("num < 2^"+s,A,Xt,L),he(A,o)}function O(A,S,T=P){if(["recovered","canonical"].some(J=>J in T))throw new Error("sign() legacy options not supported");let{hash:w,randomBytes:p}=t,{lowS:y,prehash:_,extraEntropy:D}=T;y==null&&(y=!0),A=W("msgHash",A),Hi(T),_&&(A=W("prehashed msgHash",w(A)));let N=B(A),M=f(S),K=[k(M),k(N)];if(D!=null&&D!==!1){let J=D===!0?p(e.BYTES):D;K.push(W("extraEntropy",J))}let z=ne(...K),H=N;function et(J){let at=I(J);if(!x(at))return;let gt=u(at),nt=l.BASE.multiply(at).toAffine(),ut=a(nt.x);if(ut===Xt)return;let xt=a(gt*a(H+ut*M));if(xt===Xt)return;let At=(nt.x===ut?0:2)|Number(nt.y&it),qe=xt;return y&&g(xt)&&(qe=m(xt),At^=1),new R(ut,qe,At)}return{seed:z,k2sig:et}}let P={lowS:t.lowS,prehash:!1},U={lowS:t.lowS,prehash:!1};function C(A,S,T=P){let{seed:w,k2sig:p}=O(A,S,T),y=t;return di(y.hash.outputLen,y.nByteLength,y.hmac)(w,p)}l.BASE._setWindowSize(8);function tt(A,S,T,w=U){let p=A;S=W("msgHash",S),T=W("publicKey",T);let{lowS:y,prehash:_,format:D}=w;if(Hi(w),"strict"in w)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let N=typeof p=="string"||Pe(p),M=!N&&!D&&typeof p=="object"&&p!==null&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!N&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let K,z;try{if(M&&(K=new R(p.r,p.s)),N){try{D!=="compact"&&(K=R.fromDER(p))}catch(At){if(!(At instanceof Yt.Err))throw At}!K&&D!=="der"&&(K=R.fromCompact(p))}z=l.fromHex(T)}catch{return!1}if(!K||y&&K.hasHighS())return!1;_&&(S=t.hash(S));let{r:H,s:et}=K,J=B(S),at=u(et),gt=a(J*at),nt=a(H*at),ut=l.BASE.multiplyAndAddUnsafe(z,gt,nt)?.toAffine();return ut?a(ut.x)===H:!1}return{CURVE:t,getPublicKey:E,getSharedSecret:b,sign:C,verify:tt,ProjectivePoint:l,Signature:R,utils:F}}function of(r){return{hash:r,hmac:(t,...e)=>Co(r,t,jn(...e)),randomBytes:_r}}function ji(r,t){let e=n=>Vi({...r,...of(n)});return{...e(t),create:e}}var Zi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Gi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),sf=BigInt(0),af=BigInt(1),Oo=BigInt(2),$i=(r,t)=>(r+t/Oo)/t;function cf(r){let t=Zi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=Y(l,e,t)*l%t,h=Y(f,e,t)*l%t,x=Y(h,Oo,t)*u%t,g=Y(x,o,t)*x%t,m=Y(g,s,t)*g%t,v=Y(m,c,t)*m%t,R=Y(v,a,t)*v%t,F=Y(R,c,t)*m%t,E=Y(F,e,t)*l%t,d=Y(E,i,t)*g%t,b=Y(d,n,t)*u%t,I=Y(b,Oo,t);if(!Mo.eql(Mo.sqr(I),r))throw new Error("Cannot find square root");return I}var Mo=jt(Zi,void 0,void 0,{sqrt:cf}),Oe=ji({a:sf,b:BigInt(7),Fp:Mo,n:Gi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Gi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-af*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=$i(s*r,t),a=$i(-n*r,t),u=j(r-c*e-a*o,t),l=j(-c*n-a*s,t),f=u>i,h=l>i;if(f&&(u=t-u),h&&(l=t-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},ii);function Wi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Yi(r,t,e){let n=Ze.digest(e instanceof Uint8Array?e:e.subarray());if(Wi(n))return n.then(({digest:o})=>Oe.verify(t,o,r)).catch(o=>{throw new cr(String(o))});try{return Oe.verify(t,n.digest,r)}catch(o){throw new cr(String(o))}}var Mr=class{type="secp256k1";raw;_key;constructor(t){this._key=Qi(t),this.raw=Xi(this._key)}toMultihash(){return _t.digest(Le(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e){return Yi(this._key,e,t)}};function Ji(r){return new Mr(r)}function Xi(r){return Oe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Qi(r){try{return Oe.ProjectivePoint.fromHex(r),r}catch(t){throw new gr(String(t))}}function ta(r){let{Type:t,Data:e}=ar.decode(r.digest),n=e??new Uint8Array;switch(t){case vt.Ed25519:return ki(n);case vt.secp256k1:return Ji(n);case vt.ECDSA:return Hs(n);default:throw new He}}function Le(r){return ar.encode({Type:vt[r.type],Data:r.raw})}var ea=Symbol.for("nodejs.util.inspect.custom"),uf=114,ur=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[yn]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ot.createV1(uf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ea](){return`PeerId(${this.toString()})`}},Fr=class extends ur{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Kr=class extends ur{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},zr=class extends ur{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ff=2336,qr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(Q(this.url))}[ea](){return`PeerId(${this.url})`}[yn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ot.createV1(ff,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=G(t)),t.toString()===this.toString())}};function Hr(r){if(hf(r))return new Fr({multihash:r});if(lf(r))try{let t=ta(r);if(t.type==="Ed25519")return new Kr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new zr({multihash:r,publicKey:t})}catch{let e=G(r.digest);return new qr(new URL(e))}throw new yr("Supplied PeerID Multihash is invalid")}function lf(r){return r.code===_t.code}function hf(r){return r.code===Ze.code}function Fo(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 Vr(r){let t=Mt($.decode(`z${r}`));return Hr(t)}var jr=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Fo(this.set.entries(),t=>{let e=Vr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Vr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Fo(this.set.values(),t=>Vr(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 Ko(){return new jr}var zo={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ra={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},na=new globalThis.TextEncoder;function df(r,t){let e=zo[t],n=ra[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function pf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=zo[t],o=ra[t],s=r;for(;s.length>0;){let i=na.encodeInto(s,e);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(e[c]),o=BigInt.asUintN(t,o*n)}return o}function qo(r,{size:t=32,utf8Buffer:e}={}){if(!zo[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 pf(r,t,e);r=na.encode(r)}return df(r,t)}var fr={hash:r=>Number(qo(r,{size:32})),hashV:(r,t)=>mf(fr.hash(r,t))};function mf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),Q(t,"base16")}var Ho=64,Tt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Ho)throw new TypeError("Invalid Fingerprint Size");let s=e.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=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?dt(this.fp,t.fp):!1}};function ye(r,t){return Math.floor(Math.random()*(t-r))+r}var xe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Tt))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 Tt))throw new TypeError("Invalid Fingerprint");let e=ye(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var gf=500,lr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??fr,this.seed=t.seed??ye(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=Q(t));let e=new Tt(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 xe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new xe(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[ye(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize));for(let c=0;c<gf;c++){let a=this.buckets[i].swap(e);if(a!=null&&(i=(i^a.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize)),this.buckets[i].add(a)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=Q(t));let e=new Tt(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=Q(t));let e=new Tt(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}},yf={1:.5,2:.84,4:.95,8:.98};function xf(r=.001){return r>.002?2:r>1e-5?4:8}function oa(r,t=.001){let e=xf(t),n=yf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Ho);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Gr=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??fr,this.seed=t.seed??ye(0,Math.pow(2,10)),this.filterSeries=[new lr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=Q(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new lr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=Q(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=Q(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 Vo(r,t=.001,e){return new Gr({...oa(r,t),...e??{}})}var $r=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return e.set(s.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var sa=45,bf=15,Me=new $r;function Zr(r){if(!(r.length>bf))return Me.new(r).parseWith(()=>Me.readIPv4Addr())}function Wr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>sa))return Me.new(r).parseWith(()=>Me.readIPv6Addr())}function be(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>sa)return;let e=Me.new(r).parseWith(()=>Me.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 ia(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 aa(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 jo(r){switch(r.length){case we:return r.join(".");case Ee:{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 ca(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 ua(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var we=4,Ee=16,Lm=parseInt("0xFFFF",16),wf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function hr(r,t){t.length===Ee&&r.length===we&&ia(t,0,11)&&(t=t.slice(12)),t.length===we&&r.length===Ee&&aa(r,wf,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 fa(r,t){if(typeof t=="string"&&(t=be(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 Go(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=we,o=Zr(t);if(o==null&&(n=Ee,o=Wr(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=$o(s,8*n);return{network:hr(o,i),mask:i}}function $o(r,t){if(t!==8*we&&t!==8*Ee)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 Fe=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Go(t));else{let n=be(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=be(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=$o(o,8*n.length);this.network=hr(n,this.mask)}}contains(t){return fa({network:this.network,mask:this.mask},t)}toString(){let t=ca(this.mask),e=t!==-1?String(t):ua(this.mask);return jo(this.network)+"/"+e}};function la(r,t){return new Fe(r).contains(t)}var Ef=41;function ha(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===Ef)return la("2000::/3",e)}catch{}return!1}function Yr(r){return!!Zr(r)}function Xr(r){return!!Wr(r)}function Qr(r){return!!be(r)}var pa=Va(da(),1),Sf=["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"],vf=Sf.map(r=>new pa.Netmask(r));function Zo(r){for(let t of vf)if(t.contains(r))return!0;return!1}function Af(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function _f(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 Zo(o)}function If(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Bf(r){let t=r.split(":"),e=t[t.length-1];return Zo(e)}function Lf(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 ma(r){return Yr(r)?Zo(r):Af(r)?_f(r):If(r)?Bf(r):Xr(r)?Lf(r):void 0}function ga(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function Wo(r){try{if(!ga(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:ma(t)??!1}catch{}return!0}function Rt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Jr=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}},Ke=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Jr(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 Jr(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 Yo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ya(r={}){return Tf(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 Tf(r,t){t=t??{};let e=t.onEnd,n=new Ke,o,s,i,c=Rt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((v,R)=>{s=F=>{s=null,n.push(F);try{v(r(n))}catch(E){R(E)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Rt()})}},u=v=>s!=null?s(v):(n.push(v),o),l=v=>(n=new Ke,s!=null?s({error:v}):(n.push({error:v}),o)),f=v=>{if(i)return o;if(t?.objectMode!==!0&&v?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:v})},h=v=>i?o:(i=!0,v!=null?l(v):u({done:!0})),x=()=>(n=new Ke,h(),{done:!0}),g=v=>(h(v),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:x,throw:g,push:f,end:h,get readableLength(){return n.size},onEmpty:async v=>{let R=v?.signal;if(R?.throwIfAborted(),n.isEmpty())return;let F,E;R!=null&&(F=new Promise((d,b)=>{E=()=>{b(new Yo)},R.addEventListener("abort",E)}));try{await Promise.race([c.promise,F])}finally{E!=null&&R!=null&&R?.removeEventListener("abort",E)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(v){return m.throw(v),e!=null&&(e(v),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(v){return m.end(v),e!=null&&(e(v),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:v=>m.onEmpty(v)},o}var Xo=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 tn(r,t,e,n){let o=new Xo(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function c(){e?.removeEventListener("abort",l),r.removeEventListener(t,a),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let a=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){c(),i(h);return}c(),s(f)},u=f=>{c(),i(f.detail)},l=()=>{c(),i(o)};e?.addEventListener("abort",l),r.addEventListener(t,a),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}function Qo(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 en=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var rn=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 Se(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new rn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new rn(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 nn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Rt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new kt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Pf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var on=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=Pf(),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 kt),this.cleanup())}async join(t={}){let e=new nn(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 Se(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 sn=class extends xr{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=Qo(this.emitEmpty.bind(this),1),this.emitIdle=Qo(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 en;let n=new on(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 kt)}),this.clear()}async onEmpty(t){this.size!==0&&await tn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await tn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await tn(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=ya({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),e.end(a)},o=a=>{a.detail!=null&&e.push(a.detail)},s=a=>{n(a.detail)},i=()=>{n()},c=()=>{n(new kt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",c);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",c),n()}}};var an=class extends sn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function cn(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 xa(r,t,e){let n,o;function s(){let c={signal:o.signal};if(e?.timeout!=null){let a=cn([o.signal,AbortSignal.timeout(e.timeout)]);c.signal=a}Promise.resolve().then(async()=>{await r(c)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{setInterval:c=>{t=c,n!=null&&(clearTimeout(n),n=setTimeout(s,t))},setTimeout:c=>{e==null&&(e={}),e.timeout=c},start:()=>{i||(i=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),i=!1}}}var ba=Yr,Df=Xr,Jo=function(r){let t=0;if(r=r.toString().trim(),ba(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Df(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ba(e[n]),i;s&&(i=Jo(e[n]),e[n]=G(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,G(i.slice(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++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},wa=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ze={},ts={},kf=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];kf.forEach(r=>{let t=Uf(...r);ts[t.code]=t,ze[t.name]=t});function Uf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function V(r){if(typeof r=="number"){if(ts[r]!=null)return ts[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ze[r]!=null)return ze[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Vg=V("ip4"),jg=V("ip6"),Gg=V("ipcidr");function os(r,t){switch(V(r).code){case 4:case 41:return Of(t);case 42:return ns(t);case 43:return G(t,"base10");case 6:case 273:case 33:case 132:return va(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ns(t);case 421:return zf(t);case 444:return Sa(t);case 445:return Sa(t);case 466:return Kf(t);case 481:return globalThis.encodeURIComponent(ns(t));default:return G(t,"base16")}}function ss(r,t){switch(V(r).code){case 4:return Ea(t);case 41:return Ea(t);case 42:return rs(t);case 43:return Q(t,"base10");case 6:case 273:case 33:case 132:return is(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return rs(t);case 421:return Mf(t);case 444:return qf(t);case 445:return Hf(t);case 466:return Ff(t);case 481:return rs(globalThis.decodeURIComponent(t));default:return Q(t,"base16")}}var es=Object.values(We).map(r=>r.decoder),Nf=function(){let r=es[0].or(es[1]);return es.slice(2).forEach(t=>r=r.or(t)),r}();function Ea(r){if(!Qr(r))throw new Error("invalid ip address");return Jo(r)}function Of(r){let t=wa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Qr(t))throw new Error("invalid ip address");return t}function is(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function va(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function rs(r){let t=Q(r),e=Uint8Array.from(oe(t.length));return wt([e,t],e.length+t.length)}function ns(r){let t=Gt(r);if(r=r.slice(lt(t)),r.length!==t)throw new Error("inconsistent lengths");return G(r)}function Mf(r){let t;r[0]==="Q"||r[0]==="1"?t=Mt($.decode(`z${r}`)).bytes:t=ot.parse(r).multihash.bytes;let e=Uint8Array.from(oe(t.length));return wt([e,t],e.length+t.length)}function Ff(r){let t=Nf.decode(r),e=Uint8Array.from(oe(t.length));return wt([e,t],e.length+t.length)}function Kf(r){let t=Gt(r),e=r.slice(lt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+G(e,"base64url")}function zf(r){let t=Gt(r),e=r.slice(lt(t));if(e.length!==t)throw new Error("inconsistent lengths");return G(e,"base58btc")}function qf(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=Ot.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=is(n);return wt([e,o],e.length+o.length)}function Hf(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=Ot.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=is(n);return wt([e,o],e.length+o.length)}function Sa(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=G(t,"base32"),o=va(e);return`${n}:${o}`}function Aa(r){r=as(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],c=V(i);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(s++,s>=o.length)throw new un("invalid address: "+r);if(c.path===!0){n=as(o.slice(s).join("/")),t.push([c.code,ss(c.code,n)]),e.push([c.code,n]);break}let a=ss(c.code,o[s]);t.push([c.code,a]),e.push([c.code,os(c.code,a)])}return{string:_a(e),bytes:fn(t),tuples:t,stringTuples:e,path:n}}function cs(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Gt(r,o),i=lt(s),c=V(s),a=Vf(c,r.slice(o+i));if(a===0){t.push([s]),e.push([s]),o+=i;continue}let u=r.slice(o+i,o+i+a);if(o+=a+i,o>r.length)throw new un("Invalid address Uint8Array: "+G(r,"base16"));t.push([s,u]);let l=os(s,u);if(e.push([s,l]),c.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:_a(e),tuples:t,stringTuples:e,path:n}}function _a(r){let t=[];return r.map(e=>{let n=V(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),as(t.join("/"))}function fn(r){return wt(r.map(t=>{let e=V(t[0]),n=Uint8Array.from(oe(e.code));return t.length>1&&t[1]!=null&&(n=wt([n,t[1]])),n}))}function Vf(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Gt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+lt(e)}}function as(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var un=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var jf=Symbol.for("nodejs.util.inspect.custom"),fs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Gf=[V("dns").code,V("dns4").code,V("dns6").code,V("dnsaddr").code],us=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},ln=class r{bytes;#t;#e;#r;#n;[fs]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=cs(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Aa(t)}else if(Ba(t))e=cs(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=V("tcp"),c=V("udp"),a=V("ip4"),u=V("ip6"),l=V("dns6"),f=V("ip6zone");for(let[x,g]of this.stringTuples())x===f.code&&(s=`%${g??""}`),Gf.includes(x)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${g??""}${s}`,t=x===l.code?6:4),(x===i.code||x===c.code)&&(e=V(x).name==="tcp"?"tcp":"udp",o=parseInt(g??"")),(x===a.code||x===u.code)&&(e=V(x).name==="tcp"?"tcp":"udp",n=`${g??""}${s}`,t=x===u.code?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}}protos(){return this.#e.map(([t])=>Object.assign({},V(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>V(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(fn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===ze.p2p.code&&t.push([n,o]),n===ze["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?G($.decode(`z${n}`),"base58btc"):G(ot.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return dt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Ia.get(e.name);if(n==null)throw new us(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>pr(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(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[jf](){return`Multiaddr(${this.#t})`}};var Ia=new Map;function Ba(r){return!!r?.[fs]}function pr(r){return new ln(r)}var ls=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Rt(),this.haveNext=Rt()}[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=Rt(),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=Rt(),await Se(this.readNext.promise,e?.signal,e)}};function La(){return new ls}var hn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ta(r,t){let e=La();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let c of i)await e.push(c);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 rt;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:a,value:u}=await Se(n.next(),i?.signal);return a===!0?null:u}for(;o.byteLength<i.bytes;){let{value:a,done:u}=await Se(n.next(),i?.signal);if(u===!0)throw new hn("unexpected end of input");o.append(a)}let c=o.sublist(0,i.bytes);return o.consume(i.bytes),c},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,c):await e.push(i.subarray(),c)},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 dn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},pn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},mn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ra(r,t={}){let e=Ta(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=lt(t.maxDataLength));let n=t?.lengthDecoder??Gt,o=t?.lengthEncoder??oe;return{read:async i=>{let c=-1,a=new rt;for(;;){a.append(await e.read({...i,bytes:1}));try{c=n(a)}catch(u){if(u instanceof RangeError)continue;throw u}if(c<0)throw new dn("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new mn("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new pn("message length too long");return e.read({...i,bytes:c})},write:async(i,c)=>{await e.write(new rt(o(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new rt(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(a,c)},unwrap:()=>e.unwrap()}}function hs(r,t){let e=Ra(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Pa="libp2p",Da="autonat",Ca="1.0.0";var Z;(function(r){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(u){u.codec=()=>Ne(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(u){u.codec=()=>Ne(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let l;u.codec=()=>(l==null&&(l=Wt((f,h,x={})=>{if(x.lengthDelimited!==!1&&h.fork(),f.id!=null&&(h.uint32(10),h.bytes(f.id)),f.addrs!=null)for(let g of f.addrs)h.uint32(18),h.bytes(g);x.lengthDelimited!==!1&&h.ldelim()},(f,h,x={})=>{let g={addrs:[]},m=h==null?f.len:f.pos+h;for(;f.pos<m;){let v=f.uint32();switch(v>>>3){case 1:{g.id=f.bytes();break}case 2:{if(x.limits?.addrs!=null&&g.addrs.length===x.limits.addrs)throw new Nr('Decode error - map field "addrs" had too many elements');g.addrs.push(f.bytes());break}default:{f.skipType(v&7);break}}}return g})),l),u.encode=f=>Zt(f,u.codec()),u.decode=(f,h)=>$t(f,u.codec(),h)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let l;u.codec=()=>(l==null&&(l=Wt((f,h,x={})=>{x.lengthDelimited!==!1&&h.fork(),f.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(f.peer,h)),x.lengthDelimited!==!1&&h.ldelim()},(f,h,x={})=>{let g={},m=h==null?f.len:f.pos+h;for(;f.pos<m;){let v=f.uint32();switch(v>>>3){case 1:{g.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:x.limits?.peer});break}default:{f.skipType(v&7);break}}}return g})),l),u.encode=f=>Zt(f,u.codec()),u.decode=(f,h)=>$t(f,u.codec(),h)})(i=r.Dial||(r.Dial={}));let c;(function(u){let l;u.codec=()=>(l==null&&(l=Wt((f,h,x={})=>{x.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)),x.lengthDelimited!==!1&&h.ldelim()},(f,h,x={})=>{let g={},m=h==null?f.len:f.pos+h;for(;f.pos<m;){let v=f.uint32();switch(v>>>3){case 1:{g.status=r.ResponseStatus.codec().decode(f);break}case 2:{g.statusText=f.string();break}case 3:{g.addr=f.bytes();break}default:{f.skipType(v&7);break}}}return g})),l),u.encode=f=>Zt(f,u.codec()),u.decode=(f,h)=>$t(f,u.codec(),h)})(c=r.DialResponse||(r.DialResponse={}));let a;r.codec=()=>(a==null&&(a=Wt((u,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),u.type!=null&&(l.uint32(8),r.MessageType.codec().encode(u.type,l)),u.dial!=null&&(l.uint32(18),r.Dial.codec().encode(u.dial,l)),u.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(u.dialResponse,l)),f.lengthDelimited!==!1&&l.ldelim()},(u,l,f={})=>{let h={},x=l==null?u.len:u.pos+l;for(;u.pos<x;){let g=u.uint32();switch(g>>>3){case 1:{h.type=r.MessageType.codec().decode(u);break}case 2:{h.dial=r.Dial.codec().decode(u,u.uint32(),{limits:f.limits?.dial});break}case 3:{h.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:f.limits?.dialResponse});break}default:{u.skipType(g&7);break}}}return h})),a),r.encode=u=>Zt(u,r.codec()),r.decode=(u,l)=>$t(u,r.codec(),l)})(Z||(Z={}));var Qf=4,Jf=8,gn=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??Pa}/${Da}/${Ca}`,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=new Map,this.findPeers=xa(this.findRandomPeers.bind(this),6e4),this.addressFilter=Vo(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ms]=["@libp2p/autonat"];get[gs](){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=cn([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=hs(t.stream,{maxDataLength:this.maxMessageSize}).pb(Z);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:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,c=s.peer;if(c?.id==null)return this.log.error("PeerId missing from message"),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Mt(c.id);i=Hr(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let a=c.addrs.map(f=>pr(f)).filter(f=>{let h=f.toOptions();return Wo(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(a.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",a.map(f=>f.toString()).join(", "),i);let u="",l=a[0];for await(let f of a){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:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(V("p2p").code).bytes}}}catch(x){this.log.error("could not dial %p - %e",i,x),u=x.message}finally{h!=null&&await h.close()}}return{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:l.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||o.multiaddr.toOptions().family===6&&(!e||!ha(o.multiaddr))||Wo(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:Ko(),queue:new an({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>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 c=hs(i).pb(Z),[,a]=await Promise.all([c.write({type:Z.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),c.read({signal:s})]);if(a.type!==Z.MessageType.DIAL_RESPONSE||a.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,a);return}let u=a.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==Z.ResponseStatus.OK&&u!==Z.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,a.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),u===Z.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===Z.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Qf&&this.confirmAddress(o),o.failure===Jf&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(c){i.abort(c)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};function tl(r={}){return t=>new gn(t,r)}return ja(el);})();
2
+ "use strict";var Libp2PAutonat=(()=>{var Ma=Object.create;var mr=Object.defineProperty;var Fa=Object.getOwnPropertyDescriptor;var Ka=Object.getOwnPropertyNames;var za=Object.getPrototypeOf,qa=Object.prototype.hasOwnProperty;var Ha=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)mr(r,e,{get:t[e],enumerable:!0})},ps=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ka(t))!qa.call(r,o)&&o!==e&&mr(r,o,{get:()=>t[o],enumerable:!(n=Fa(t,o))||n.enumerable});return r};var Va=(r,t,e)=>(e=r!=null?Ma(za(r)):{},ps(t||!r||!r.__esModule?mr(e,"default",{value:r,enumerable:!0}):e,r)),ja=r=>ps(mr({},"__esModule",{value:!0}),r);var da=Ha(dr=>{(function(){var r,t,e,n,o,s,i,c;c=function(a){var u,l,f,h;return u=(a&255<<24)>>>24,l=(a&255<<16)>>>16,f=(a&65280)>>>8,h=a&255,[u,l,f,h].join(".")},i=function(a){var u,l,f,h,x,g;for(u=[],f=h=0;h<=3&&a.length!==0;f=++h){if(f>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}g=t(a),x=g[0],l=g[1],a=a.substring(l),u.push(x)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(a){return a.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(a){var u,l,f,h,x;for(h=0,u=10,l="9",f=0,a.length>1&&a[f]==="0"&&(a[f+1]==="x"||a[f+1]==="X"?(f+=2,u=16):"0"<=a[f+1]&&a[f+1]<="9"&&(f++,u=8,l="7")),x=f;f<a.length;){if("0"<=a[f]&&a[f]<=l)h=h*u+(e(a[f])-n)>>>0;else if(u===16)if("a"<=a[f]&&a[f]<="f")h=h*u+(10+e(a[f])-s)>>>0;else if("A"<=a[f]&&a[f]<="F")h=h*u+(10+e(a[f])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===x)throw new Error("empty octet");return[h,f]},r=function(){function a(u,l){var f,h,x,g;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(g=u.split("/",2),u=g[0],l=g[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(m){throw f=m,new Error("Invalid mask: "+l)}for(h=x=32;x>=0;h=--x)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(u)&this.maskLong)>>>0}catch(m){throw f=m,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var l,f,h;for(h=i(this.first),f=i(this.last),l=0;h<=f;)u(c(h),h,l),l++,h++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a}(),dr.ip2long=i,dr.long2ip=c,dr.Netmask=r}).call(dr)});var rl={};bt(rl,{autoNAT:()=>el});var yn=Symbol.for("@libp2p/peer-id");var kt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Ut=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},gr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var yr=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 xr=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 ms=Symbol.for("@libp2p/service-capabilities"),gs=Symbol.for("@libp2p/service-dependencies");var Sn={};bt(Sn,{base58btc:()=>$,base58flickr:()=>Qa});var Tl=new Uint8Array(0);function ys(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 Nt(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 xs(r){return new TextEncoder().encode(r)}function bs(r){return new TextDecoder().decode(r)}function Ga(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function f(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var m=0,v=0,R=0,F=g.length;R!==F&&g[R]===0;)R++,m++;for(var E=(F-R)*l+1>>>0,d=new Uint8Array(E);R!==F;){for(var b=g[R],I=0,B=E-1;(b!==0||I<v)&&B!==-1;B--,I++)b+=256*d[B]>>>0,d[B]=b%c>>>0,b=b/c>>>0;if(b!==0)throw new Error("Non-zero carry");v=I,R++}for(var L=E-v;L!==E&&d[L]===0;)L++;for(var k=a.repeat(m);L<E;++L)k+=r.charAt(d[L]);return k}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var m=0;if(g[m]!==" "){for(var v=0,R=0;g[m]===a;)v++,m++;for(var F=(g.length-m)*u+1>>>0,E=new Uint8Array(F);g[m];){var d=e[g.charCodeAt(m)];if(d===255)return;for(var b=0,I=F-1;(d!==0||b<R)&&I!==-1;I--,b++)d+=c*E[I]>>>0,E[I]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");R=b,m++}if(g[m]!==" "){for(var B=F-R;B!==F&&E[B]===0;)B++;for(var L=new Uint8Array(v+(F-B)),k=v;B!==F;)L[k++]=E[B++];return L}}}function x(g){var m=h(g);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:x}}var $a=Ga,Za=$a,Es=Za;var xn=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")}},bn=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 Ss(this,t)}},wn=class{decoders;constructor(t){this.decoders=t}or(t){return Ss(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 Ss(r,t){return new wn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var En=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 xn(t,e,n),this.decoder=new bn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ve({name:r,prefix:t,encode:e,decode:n}){return new En(r,t,e,n)}function Qt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Es(e,r);return ve({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function Wa(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,i+=e,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=e||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ya(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Xa(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Xa(n);return ve({prefix:t,name:r,encode(s){return Ya(s,n,e)},decode(s){return Wa(s,o,e,r)}})}var $=Qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Qa=Qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var vn={};bt(vn,{base32:()=>Ot,base32hex:()=>rc,base32hexpad:()=>oc,base32hexpadupper:()=>sc,base32hexupper:()=>nc,base32pad:()=>tc,base32padupper:()=>ec,base32upper:()=>Ja,base32z:()=>ic});var Ot=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ja=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tc=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ec=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rc=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nc=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),oc=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),sc=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ic=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var An={};bt(An,{base36:()=>Ve,base36upper:()=>ac});var Ve=Qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ac=Qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var cc=_s,vs=128,uc=127,fc=~uc,lc=Math.pow(2,31);function _s(r,t,e){t=t||[],e=e||0;for(var n=e;r>=lc;)t[e++]=r&255|vs,r/=128;for(;r&fc;)t[e++]=r&255|vs,r>>>=7;return t[e]=r|0,_s.bytes=e-n+1,t}var hc=_n,dc=128,As=127;function _n(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw _n.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&As)<<o:(i&As)*Math.pow(2,o),o+=7}while(i>=dc);return _n.bytes=s-n,e}var pc=Math.pow(2,7),mc=Math.pow(2,14),gc=Math.pow(2,21),yc=Math.pow(2,28),xc=Math.pow(2,35),bc=Math.pow(2,42),wc=Math.pow(2,49),Ec=Math.pow(2,56),Sc=Math.pow(2,63),vc=function(r){return r<pc?1:r<mc?2:r<gc?3:r<yc?4:r<xc?5:r<bc?6:r<wc?7:r<Ec?8:r<Sc?9:10},Ac={encode:cc,decode:hc,encodingLength:vc},_c=Ac,je=_c;function Ge(r,t=0){return[je.decode(r,t),je.decode.bytes]}function Ae(r,t,e=0){return je.encode(r,t,e),t}function _e(r){return je.encodingLength(r)}function ie(r,t){let e=t.byteLength,n=_e(r),o=n+_e(e),s=new Uint8Array(o+e);return Ae(r,s,0),Ae(e,s,n),s.set(t,o),new Ie(r,e,t,s)}function Mt(r){let t=Nt(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 Ie(e,o,i,t)}function Is(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ys(r.bytes,e.bytes)}}var Ie=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Bs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Bc(e,In(r),t??$.encoder);default:return Lc(e,In(r),t??Ot.encoder)}}var Ls=new WeakMap;function In(r){let t=Ls.get(r);if(t==null){let e=new Map;return Ls.set(r,e),e}return t}var ot=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!==Tc)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=ie(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&&Is(t.multihash,n.multihash)}toString(t){return Bs(this,t)}toJSON(){return{"/":Bs(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??Ts(n,o,s.bytes))}else if(e[Rc]===!0){let{version:n,multihash:o,code:s}=e,i=Mt(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=Ts(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=Nt(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 Ie(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,c=n(),a=n(),u=e+a,l=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:l,size:u}}static parse(t,e){let[n,o]=Ic(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 In(s).set(n,t),s}};function Ic(r,t){switch(r[0]){case"Q":{let e=t??$;return[$.prefix,e.decode(`${$.prefix}${r}`)]}case $.prefix:{let e=t??$;return[$.prefix,e.decode(r)]}case Ot.prefix:{let e=t??Ot;return[Ot.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 Bc(r,t,e){let{prefix:n}=e;if(n!==$.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 Lc(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,Tc=18;function Ts(r,t,e){let n=_e(r),o=n+_e(t),s=new Uint8Array(o+e.byteLength);return Ae(r,s,0),Ae(t,s,n),s.set(e,o),s}var Rc=Symbol.for("@ipld/js-cid/CID");var Bn={};bt(Bn,{identity:()=>_t});var Rs=0,Pc="identity",Ps=Nt;function Dc(r){return ie(Rs,Ps(r))}var _t={code:Rs,name:Pc,encode:Ps,digest:Dc};function dt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function It(r=0){return new Uint8Array(r)}function yt(r=0){return new Uint8Array(r)}function wt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=yt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Cs=Symbol.for("@achingbrain/uint8arraylist");function Ds(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 wr(r){return!!r?.[Cs]}var rt=class r{bufs;length;[Cs]=!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(wr(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(wr(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=Ds(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ds(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(wr(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 wt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:wt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,l=e>c&&e<=a;if(u&&l){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(l){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!wr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=a;f+=l){l=0;for(let h=u;h>=0;h--){let x=this.get(f+h);if(n[h]!==x){l=Math.max(1,h-c[x]);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=yt(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=It(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=It(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=It(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=yt(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=It(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=It(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=It(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=It(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=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!dt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Ln={};bt(Ln,{base10:()=>Cc});var Cc=Qt({prefix:"9",name:"base10",alphabet:"0123456789"});var Tn={};bt(Tn,{base16:()=>kc,base16upper:()=>Uc});var kc=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Uc=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Rn={};bt(Rn,{base2:()=>Nc});var Nc=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pn={};bt(Pn,{base256emoji:()=>zc});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}"),Oc=ks.reduce((r,t,e)=>(r[e]=t,r),[]),Mc=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 Fc(r){return r.reduce((t,e)=>(t+=Oc[e],t),"")}function Kc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Mc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var zc=ve({prefix:"\u{1F680}",name:"base256emoji",encode:Fc,decode:Kc});var Dn={};bt(Dn,{base64:()=>qc,base64pad:()=>Hc,base64url:()=>Vc,base64urlpad:()=>jc});var qc=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Hc=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vc=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),jc=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Cn={};bt(Cn,{base8:()=>Gc});var Gc=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var kn={};bt(kn,{identity:()=>$c});var $c=ve({prefix:"\0",name:"identity",encode:r=>bs(r),decode:r=>xs(r)});var hh=new TextEncoder,dh=new TextDecoder;var On={};bt(On,{sha256:()=>Ze,sha512:()=>Yc});function Nn({name:r,code:t,encode:e}){return new Un(r,t,e)}var Un=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?ie(this.code,e):e.then(n=>ie(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ns(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ze=Nn({name:"sha2-256",code:18,encode:Ns("SHA-256")}),Yc=Nn({name:"sha2-512",code:19,encode:Ns("SHA-512")});var We={...kn,...Rn,...Cn,...Ln,...Tn,...vn,...An,...Sn,...Dn,...Pn},_h={...On,...Bn};function Ms(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Os=Ms("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Mn=Ms("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=yt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Xc={utf8:Os,"utf-8":Os,hex:We.base16,latin1:Mn,ascii:Mn,binary:Mn,...We},Er=Xc;function Q(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function G(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Qc=parseInt("11111",2),Fn=parseInt("10000000",2),Jc=parseInt("01111111",2),Fs={0:Ye,1:Ye,2:tu,3:nu,4:ou,5:ru,6:eu,16:Ye,22:Ye,48:Ye};function Kn(r,t={offset:0}){let e=r[t.offset]&Qc;if(t.offset++,Fs[e]!=null)return Fs[e](r,t);throw new Error("No decoder for tag "+e)}function Xe(r,t){let e=0;if((r[t.offset]&Fn)===Fn){let n=r[t.offset]&Jc,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=Kn(r,t);if(n===null)break;e.push(n)}return e}function tu(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 eu(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 c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let l=0;for(let f=0;f<a.length;f++)l+=a[f]<<f*7;c+=`.${l}`,a=[]}}return c}function ru(r,t){return t.offset++,null}function nu(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 ou(r,t){let e=Xe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function su(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new rt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function zn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=su(r.byteLength);return new rt(Uint8Array.from([t.byteLength|Fn]),t)}function Ks(r){let t=new rt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new rt(Uint8Array.from([2]),zn(t),t)}function zs(r){let t=Uint8Array.from([0]),e=new rt(t,r);return new rt(Uint8Array.from([3]),zn(e),e)}function Sr(r,t=48){let e=new rt;for(let n of r)e.append(n);return new rt(Uint8Array.from([t]),zn(e),e)}async function qs(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var iu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),au=Uint8Array.from([6,5,43,129,4,0,34]),cu=Uint8Array.from([6,5,43,129,4,0,35]),uu={ext:!0,kty:"EC",crv:"P-256"},fu={ext:!0,kty:"EC",crv:"P-384"},lu={ext:!0,kty:"EC",crv:"P-521"},qn=32,Hn=48,Vn=66;function Hs(r){let t=Kn(r);return Vs(t)}function Vs(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===qn*2+1)return n=G(t.subarray(e,e+qn),"base64url"),o=G(t.subarray(e+qn),"base64url"),new Be({...uu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Hn*2+1)return n=G(t.subarray(e,e+Hn),"base64url"),o=G(t.subarray(e+Hn),"base64url"),new Be({...fu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Vn*2+1)return n=G(t.subarray(e,e+Vn),"base64url"),o=G(t.subarray(e+Vn),"base64url"),new Be({...lu,key_ops:["verify"],x:n,y:o});throw new Ut(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function js(r){return Sr([Ks(Uint8Array.from([1])),Sr([hu(r.crv)],160),Sr([zs(new rt(Uint8Array.from([4]),Q(r.x??"","base64url"),Q(r.y??"","base64url")))],161)]).subarray()}function hu(r){if(r==="P-256")return iu;if(r==="P-384")return au;if(r==="P-521")return cu;throw new Ut(`Invalid curve ${r}`)}var Be=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=js(this.jwk)),this._raw}toMultihash(){return _t.digest(Le(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,e){return qs(this.jwk,e,t)}};var ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function du(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function vr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ce(r,...t){if(!du(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 Gs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");vr(r.outputLen),vr(r.blockLen)}function Re(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 $s(r,t){ce(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Kt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ar(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Bt(r,t){return r<<32-t|r>>>t}function Zs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Qe(r){return typeof r=="string"&&(r=Zs(r)),ce(r),r}function jn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ce(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 Te=class{};function Gn(r){let t=n=>r().update(Qe(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function _r(r=32){if(ae&&typeof ae.getRandomValues=="function")return ae.getRandomValues(new Uint8Array(r));if(ae&&typeof ae.randomBytes=="function")return Uint8Array.from(ae.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function pu(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),c=Number(e&s),a=n?4:0,u=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+u,c,n)}function Ws(r,t,e){return r&t^~r&e}function Ys(r,t,e){return r&t^r&e^t&e}var Je=class extends Te{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=Ar(this.buffer)}update(t){Re(this),t=Qe(t),ce(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Ar(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),$s(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Kt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;pu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Ar(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,l[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ir=BigInt(4294967295),Xs=BigInt(32);function mu(r,t=!1){return t?{h:Number(r&Ir),l:Number(r>>Xs&Ir)}:{h:Number(r>>Xs&Ir)|0,l:Number(r&Ir)|0}}function Qs(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=mu(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var $n=(r,t,e)=>r>>>e,Zn=(r,t,e)=>r<<32-e|t>>>e,ue=(r,t,e)=>r>>>e|t<<32-e,fe=(r,t,e)=>r<<32-e|t>>>e,tr=(r,t,e)=>r<<64-e|t>>>e-32,er=(r,t,e)=>r>>>e-32|t<<64-e;function Pt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Js=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ti=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ei=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ri=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ni=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),oi=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var yu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jt=new Uint32Array(64),Wn=class extends Je{constructor(t=32){super(64,t,8,!1),this.A=zt[0]|0,this.B=zt[1]|0,this.C=zt[2]|0,this.D=zt[3]|0,this.E=zt[4]|0,this.F=zt[5]|0,this.G=zt[6]|0,this.H=zt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)Jt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Jt[f-15],x=Jt[f-2],g=Bt(h,7)^Bt(h,18)^h>>>3,m=Bt(x,17)^Bt(x,19)^x>>>10;Jt[f]=m+Jt[f-7]+g+Jt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Bt(c,6)^Bt(c,11)^Bt(c,25),x=l+h+Ws(c,a,u)+yu[f]+Jt[f]|0,m=(Bt(n,2)^Bt(n,13)^Bt(n,22))+Ys(n,o,s)|0;l=u,u=a,a=c,c=i+x|0,i=s,s=o,o=n,n=x+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){Kt(Jt)}destroy(){this.set(0,0,0,0,0,0,0,0),Kt(this.buffer)}};var si=Qs(["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))),xu=si[0],bu=si[1],te=new Uint32Array(80),ee=new Uint32Array(80),Yn=class extends Je{constructor(t=64){super(128,t,16,!1),this.Ah=ct[0]|0,this.Al=ct[1]|0,this.Bh=ct[2]|0,this.Bl=ct[3]|0,this.Ch=ct[4]|0,this.Cl=ct[5]|0,this.Dh=ct[6]|0,this.Dl=ct[7]|0,this.Eh=ct[8]|0,this.El=ct[9]|0,this.Fh=ct[10]|0,this.Fl=ct[11]|0,this.Gh=ct[12]|0,this.Gl=ct[13]|0,this.Hh=ct[14]|0,this.Hl=ct[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:f,Fl:h,Gh:x,Gl:g,Hh:m,Hl:v}=this;return[t,e,n,o,s,i,c,a,u,l,f,h,x,g,m,v]}set(t,e,n,o,s,i,c,a,u,l,f,h,x,g,m,v){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=x|0,this.Gl=g|0,this.Hh=m|0,this.Hl=v|0}process(t,e){for(let E=0;E<16;E++,e+=4)te[E]=t.getUint32(e),ee[E]=t.getUint32(e+=4);for(let E=16;E<80;E++){let d=te[E-15]|0,b=ee[E-15]|0,I=ue(d,b,1)^ue(d,b,8)^$n(d,b,7),B=fe(d,b,1)^fe(d,b,8)^Zn(d,b,7),L=te[E-2]|0,k=ee[E-2]|0,O=ue(L,k,19)^tr(L,k,61)^$n(L,k,6),P=fe(L,k,19)^er(L,k,61)^Zn(L,k,6),U=ei(B,P,ee[E-7],ee[E-16]),C=ri(U,I,O,te[E-7],te[E-16]);te[E]=C|0,ee[E]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:f,El:h,Fh:x,Fl:g,Gh:m,Gl:v,Hh:R,Hl:F}=this;for(let E=0;E<80;E++){let d=ue(f,h,14)^ue(f,h,18)^tr(f,h,41),b=fe(f,h,14)^fe(f,h,18)^er(f,h,41),I=f&x^~f&m,B=h&g^~h&v,L=ni(F,b,B,bu[E],ee[E]),k=oi(L,R,d,I,xu[E],te[E]),O=L|0,P=ue(n,o,28)^tr(n,o,34)^tr(n,o,39),U=fe(n,o,28)^er(n,o,34)^er(n,o,39),C=n&s^n&c^s&c,tt=o&i^o&a^i&a;R=m|0,F=v|0,m=x|0,v=g|0,x=f|0,g=h|0,{h:f,l:h}=Pt(u|0,l|0,k|0,O|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let A=Js(O,U,tt);n=ti(A,k,P,C),o=A|0}({h:n,l:o}=Pt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Pt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Pt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=Pt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=Pt(this.Eh|0,this.El|0,f|0,h|0),{h:x,l:g}=Pt(this.Fh|0,this.Fl|0,x|0,g|0),{h:m,l:v}=Pt(this.Gh|0,this.Gl|0,m|0,v|0),{h:R,l:F}=Pt(this.Hh|0,this.Hl|0,R|0,F|0),this.set(n,o,s,i,c,a,u,l,f,h,x,g,m,v,R,F)}roundClean(){Kt(te,ee)}destroy(){Kt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ii=Gn(()=>new Wn);var ai=Gn(()=>new Yn);var to=BigInt(0),Jn=BigInt(1);function Pe(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function eo(r){if(!Pe(r))throw new Error("Uint8Array expected")}function Dt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function rr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function fi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?to:BigInt("0x"+r)}var li=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",wu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function re(r){if(eo(r),li)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=wu[r[e]];return t}var qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ci(r){if(r>=qt._0&&r<=qt._9)return r-qt._0;if(r>=qt.A&&r<=qt.F)return r-(qt.A-10);if(r>=qt.a&&r<=qt.f)return r-(qt.a-10)}function nr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(li)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=ci(r.charCodeAt(s)),c=ci(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Ht(r){return fi(re(r))}function le(r){return eo(r),fi(re(Uint8Array.from(r).reverse()))}function he(r,t){return nr(r.toString(16).padStart(t*2,"0"))}function De(r,t){return he(r,t).reverse()}function W(r,t,e){let n;if(typeof t=="string")try{n=nr(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Pe(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}function ne(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];eo(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 Xn=r=>typeof r=="bigint"&&to<=r;function Br(r,t,e){return Xn(r)&&Xn(t)&&Xn(e)&&t<=r&&r<e}function Et(r,t,e,n){if(!Br(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function hi(r){let t;for(t=0;r>to;r>>=Jn,t+=1);return t}var de=r=>(Jn<<BigInt(r))-Jn,Qn=r=>new Uint8Array(r),ui=r=>Uint8Array.from(r);function di(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=Qn(r),o=Qn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...f)=>e(o,n,...f),a=(f=Qn(0))=>{o=c(ui([0]),f),n=c(),f.length!==0&&(o=c(ui([1]),f),n=c())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=c();let x=n.slice();h.push(x),f+=n.length}return ne(...h)};return(f,h)=>{i(),a(f);let x;for(;!(x=h(u()));)a();return i(),x}}var Eu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Pe(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Vt(r,t,e={}){let n=(o,s,i)=>{let c=Eu[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}function Ce(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 pt=BigInt(0),st=BigInt(1),pe=BigInt(2),Su=BigInt(3),mi=BigInt(4),gi=BigInt(5),yi=BigInt(8);function j(r,t){let e=r%t;return e>=pt?e:t+e}function Y(r,t,e){let n=r;for(;t-- >pt;)n*=n,n%=e;return n}function Lr(r,t){if(r===pt)throw new Error("invert: expected non-zero number");if(t<=pt)throw new Error("invert: expected positive modulus, got "+t);let e=j(r,t),n=t,o=pt,s=st,i=st,c=pt;for(;e!==pt;){let u=n/e,l=n%e,f=o-i*u,h=s-c*u;n=e,e=l,o=i,s=c,i=f,c=h}if(n!==st)throw new Error("invert: does not exist");return j(o,t)}function xi(r,t){let e=(r.ORDER+st)/mi,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function vu(r,t){let e=(r.ORDER-gi)/yi,n=r.mul(t,pe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,pe),o),c=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(c),t))throw new Error("Cannot find square root");return c}function Au(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-st,e=0;for(;t%pe===pt;)t/=pe,e++;let n=pe,o=jt(r);for(;pi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return xi;let s=o.pow(n,t),i=(t+st)/pe;return function(a,u){if(a.is0(u))return u;if(pi(a,u)!==1)throw new Error("Cannot find square root");let l=e,f=a.mul(a.ONE,s),h=a.pow(u,t),x=a.pow(u,i);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let g=1,m=a.sqr(h);for(;!a.eql(m,a.ONE);)if(g++,m=a.sqr(m),g===l)throw new Error("Cannot find square root");let v=st<<BigInt(l-g-1),R=a.pow(f,v);l=g,f=a.sqr(R),h=a.mul(h,f),x=a.mul(x,R)}return x}}function _u(r){return r%mi===Su?xi:r%yi===gi?vu:Au(r)}var bi=(r,t)=>(j(r,t)&st)===st,Iu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ro(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Iu.reduce((n,o)=>(n[o]="function",n),t);return Vt(r,e)}function Bu(r,t,e){if(e<pt)throw new Error("invalid exponent, negatives unsupported");if(e===pt)return r.ONE;if(e===st)return t;let n=r.ONE,o=t;for(;e>pt;)e&st&&(n=r.mul(n,o)),o=r.sqr(o),e>>=st;return n}function ke(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function pi(r,t){let e=(r.ORDER-st)/pe,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 no(r,t){t!==void 0&&vr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function jt(r,t,e=!1,n={}){if(r<=pt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=no(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:de(o),ZERO:pt,ONE:st,create:a=>j(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return pt<=a&&a<r},is0:a=>a===pt,isOdd:a=>(a&st)===st,neg:a=>j(-a,r),eql:(a,u)=>a===u,sqr:a=>j(a*a,r),add:(a,u)=>j(a+u,r),sub:(a,u)=>j(a-u,r),mul:(a,u)=>j(a*u,r),pow:(a,u)=>Bu(c,a,u),div:(a,u)=>j(a*Lr(u,r),r),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>Lr(a,r),sqrt:n.sqrt||(a=>(i||(i=_u(r)),i(c,a))),toBytes:a=>e?De(a,s):he(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?le(a):Ht(a)},invertBatch:a=>ke(c,a),cmov:(a,u,l)=>l?u:a});return Object.freeze(c)}function wi(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 oo(r){let t=wi(r);return t+Math.ceil(t/2)}function Ei(r,t,e=!1){let n=r.length,o=wi(t),s=oo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?le(r):Ht(r),c=j(i,t-st)+st;return e?De(c,o):he(c,o)}var Si=BigInt(0),uo=BigInt(1);function so(r,t){let e=t.negate();return r?e:t}function Ai(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function io(r,t){Ai(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=de(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function vi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=uo);let u=t*n,l=u+Math.abs(c)-1,f=c===0,h=c<0,x=t%2!==0;return{nextN:a,offset:l,isZero:f,isNeg:h,isNegF:x,offsetF:u}}function Lu(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 Tu(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 ao=new WeakMap,_i=new WeakMap;function co(r){return _i.get(r)||1}function Tr(r,t){return{constTimeNegate:so,hasPrecomputes(e){return co(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Si;)n&uo&&(o=o.add(s)),s=s.double(),n>>=uo;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=io(n,t),i=[],c=e,a=c;for(let u=0;u<o;u++){a=c,i.push(a);for(let l=1;l<s;l++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,c=io(e,t);for(let a=0;a<c.windows;a++){let{nextN:u,offset:l,isZero:f,isNeg:h,isNegF:x,offsetF:g}=vi(o,a,c);o=u,f?i=i.add(so(x,n[g])):s=s.add(so(h,n[l]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=io(e,t);for(let c=0;c<i.windows&&o!==Si;c++){let{nextN:a,offset:u,isZero:l,isNeg:f}=vi(o,c,i);if(o=a,!l){let h=n[u];s=s.add(f?h.negate():h)}}return s},getPrecomputes(e,n,o){let s=ao.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&ao.set(n,o(s))),s},wNAFCached(e,n,o){let s=co(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=co(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Ai(n,t),_i.set(e,n),ao.delete(e)}}}function Rr(r,t,e,n){Lu(e,r),Tu(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,c=hi(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=de(a),l=new Array(Number(u)+1).fill(i),f=Math.floor((t.BITS-1)/a)*a,h=i;for(let x=f;x>=0;x-=a){l.fill(i);for(let m=0;m<s;m++){let v=n[m],R=Number(v>>BigInt(x)&u);l[R]=l[R].add(e[m])}let g=i;for(let m=l.length-1,v=i;m>0;m--)v=v.add(l[m]),g=g.add(v);if(h=h.add(g),x!==0)for(let m=0;m<a;m++)h=h.double()}return h}function or(r){return ro(r.Fp),Vt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...no(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ct=BigInt(0),mt=BigInt(1),Ii=BigInt(2),Ru=BigInt(8),Pu={zip215:!0};function Du(r){let t=or(r);return Vt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Bi(r){let t=Du(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,u=Ii<<BigInt(c*8)-mt,l=e.create,f=jt(t.n,t.nBitLength);function h(w,p){let y=e.sqr(w),_=e.sqr(p),D=e.add(e.mul(t.a,y),_),N=e.add(e.ONE,e.mul(t.d,e.mul(y,_)));return e.eql(D,N)}if(!h(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let x=t.uvRatio||((w,p)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(p))}}catch{return{isValid:!1,value:Ct}}}),g=t.adjustScalarBytes||(w=>w),m=t.domain||((w,p,y)=>{if(Dt("phflag",y),p.length||y)throw new Error("Contexts/pre-hash are not supported");return w});function v(w,p,y=!1){let _=y?mt:Ct;Et("coordinate "+w,p,_,u)}function R(w){if(!(w instanceof d))throw new Error("ExtendedPoint expected")}let F=Ce((w,p)=>{let{ex:y,ey:_,ez:D}=w,N=w.is0();p==null&&(p=N?Ru:e.inv(D));let M=l(y*p),K=l(_*p),z=l(D*p);if(N)return{x:Ct,y:mt};if(z!==mt)throw new Error("invZ was invalid");return{x:M,y:K}}),E=Ce(w=>{let{a:p,d:y}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:_,ey:D,ez:N,et:M}=w,K=l(_*_),z=l(D*D),H=l(N*N),et=l(H*H),J=l(K*p),at=l(H*l(J+z)),gt=l(et+l(y*l(K*z)));if(at!==gt)throw new Error("bad point: equation left != right (1)");let nt=l(_*D),ut=l(N*M);if(nt!==ut)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(p,y,_,D){v("x",p),v("y",y),v("z",_,!0),v("t",D),this.ex=p,this.ey=y,this.ez=_,this.et=D,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof d)throw new Error("extended point not allowed");let{x:y,y:_}=p||{};return v("x",y),v("y",_),new d(y,_,mt,l(y*_))}static normalizeZ(p){let y=ke(e,p.map(_=>_.ez));return p.map((_,D)=>_.toAffine(y[D])).map(d.fromAffine)}static msm(p,y){return Rr(d,f,p,y)}_setWindowSize(p){B.setWindowSize(this,p)}assertValidity(){E(this)}equals(p){R(p);let{ex:y,ey:_,ez:D}=this,{ex:N,ey:M,ez:K}=p,z=l(y*K),H=l(N*D),et=l(_*K),J=l(M*D);return z===H&&et===J}is0(){return this.equals(d.ZERO)}negate(){return new d(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:p}=t,{ex:y,ey:_,ez:D}=this,N=l(y*y),M=l(_*_),K=l(Ii*l(D*D)),z=l(p*N),H=y+_,et=l(l(H*H)-N-M),J=z+M,at=J-K,gt=z-M,nt=l(et*at),ut=l(J*gt),xt=l(et*gt),At=l(at*J);return new d(nt,ut,At,xt)}add(p){R(p);let{a:y,d:_}=t,{ex:D,ey:N,ez:M,et:K}=this,{ex:z,ey:H,ez:et,et:J}=p,at=l(D*z),gt=l(N*H),nt=l(K*_*J),ut=l(M*et),xt=l((D+N)*(z+H)-at-gt),At=ut-nt,qe=ut+nt,ds=l(gt-y*at),ka=l(xt*At),Ua=l(qe*ds),Na=l(xt*ds),Oa=l(At*qe);return new d(ka,Ua,Oa,Na)}subtract(p){return this.add(p.negate())}wNAF(p){return B.wNAFCached(this,p,d.normalizeZ)}multiply(p){let y=p;Et("scalar",y,mt,n);let{p:_,f:D}=this.wNAF(y);return d.normalizeZ([_,D])[0]}multiplyUnsafe(p,y=d.ZERO){let _=p;return Et("scalar",_,Ct,n),_===Ct?I:this.is0()||_===mt?this:B.wNAFCachedUnsafe(this,_,d.normalizeZ,y)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return B.unsafeLadder(this,n).is0()}toAffine(p){return F(this,p)}clearCofactor(){let{h:p}=t;return p===mt?this:this.multiplyUnsafe(p)}static fromHex(p,y=!1){let{d:_,a:D}=t,N=e.BYTES;p=W("pointHex",p,N),Dt("zip215",y);let M=p.slice(),K=p[N-1];M[N-1]=K&-129;let z=le(M),H=y?u:e.ORDER;Et("pointHex.y",z,Ct,H);let et=l(z*z),J=l(et-mt),at=l(_*et-D),{isValid:gt,value:nt}=x(J,at);if(!gt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(nt&mt)===mt,xt=(K&128)!==0;if(!y&&nt===Ct&&xt)throw new Error("Point.fromHex: x=0 and x_0=1");return xt!==ut&&(nt=l(-nt)),d.fromAffine({x:nt,y:z})}static fromPrivateKey(p){let{scalar:y}=O(p);return b.multiply(y)}toRawBytes(){let{x:p,y}=this.toAffine(),_=De(y,e.BYTES);return _[_.length-1]|=p&mt?128:0,_}toHex(){return re(this.toRawBytes())}}d.BASE=new d(t.Gx,t.Gy,mt,l(t.Gx*t.Gy)),d.ZERO=new d(Ct,mt,mt,Ct);let{BASE:b,ZERO:I}=d,B=Tr(d,c*8);function L(w){return j(w,n)}function k(w){return L(le(w))}function O(w){let p=e.BYTES;w=W("private key",w,p);let y=W("hashed private key",s(w),2*p),_=g(y.slice(0,p)),D=y.slice(p,2*p),N=k(_);return{head:_,prefix:D,scalar:N}}function P(w){let{head:p,prefix:y,scalar:_}=O(w),D=b.multiply(_),N=D.toRawBytes();return{head:p,prefix:y,scalar:_,point:D,pointBytes:N}}function U(w){return P(w).pointBytes}function C(w=Uint8Array.of(),...p){let y=ne(...p);return k(s(m(y,W("context",w),!!o)))}function tt(w,p,y={}){w=W("message",w),o&&(w=o(w));let{prefix:_,scalar:D,pointBytes:N}=P(p),M=C(y.context,_,w),K=b.multiply(M).toRawBytes(),z=C(y.context,K,N,w),H=L(M+z*D);Et("signature.s",H,Ct,n);let et=ne(K,De(H,e.BYTES));return W("result",et,e.BYTES*2)}let A=Pu;function S(w,p,y,_=A){let{context:D,zip215:N}=_,M=e.BYTES;w=W("signature",w,2*M),p=W("message",p),y=W("publicKey",y,M),N!==void 0&&Dt("zip215",N),o&&(p=o(p));let K=le(w.slice(M,2*M)),z,H,et;try{z=d.fromHex(y,N),H=d.fromHex(w.slice(0,M),N),et=b.multiplyUnsafe(K)}catch{return!1}if(!N&&z.isSmallOrder())return!1;let J=C(D,H.toRawBytes(),z.toRawBytes(),p);return H.add(z.multiplyUnsafe(J)).subtract(et).clearCofactor().equals(d.ZERO)}return b._setWindowSize(8),{CURVE:t,getPublicKey:U,sign:tt,verify:S,ExtendedPoint:d,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,p=d.BASE){return p._setWindowSize(w),p.multiply(BigInt(3)),p}}}}var fo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Li=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ld=BigInt(0),Cu=BigInt(1),Ti=BigInt(2),Td=BigInt(3),ku=BigInt(5),Uu=BigInt(8);function Nu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=fo,c=r*r%s*r%s,a=Y(c,Ti,s)*c%s,u=Y(a,Cu,s)*r%s,l=Y(u,ku,s)*u%s,f=Y(l,t,s)*l%s,h=Y(f,e,s)*f%s,x=Y(h,n,s)*h%s,g=Y(x,o,s)*x%s,m=Y(g,o,s)*x%s,v=Y(m,t,s)*l%s;return{pow_p_5_8:Y(v,Ti,s)*r%s,b2:c}}function Ou(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Mu(r,t){let e=fo,n=j(t*t*t,e),o=j(n*n*t,e),s=Nu(r*o).pow_p_5_8,i=j(r*n*s,e),c=j(t*i*i,e),a=i,u=j(i*Li,e),l=c===r,f=c===j(-r,e),h=c===j(-r*Li,e);return l&&(i=a),(f||h)&&(i=u),bi(i,e)&&(i=j(-i,e)),{isValid:l||f,value:i}}var Ri=jt(fo,void 0,!0),Fu={a:Ri.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ri,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Uu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ai,randomBytes:_r,adjustScalarBytes:Ou,uvRatio:Mu},Pi=Bi(Fu);var Pr=32;function Di(r,t,e){return Pi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Dr=class{type="Ed25519";raw;constructor(t){this.raw=lo(t,Pr)}toMultihash(){return _t.digest(Le(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e){return Di(this.raw,e,t)}};function ki(r){return r=lo(r,Pr),new Dr(r)}function lo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Ut(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var zu=Math.pow(2,7),qu=Math.pow(2,14),Hu=Math.pow(2,21),ho=Math.pow(2,28),po=Math.pow(2,35),mo=Math.pow(2,42),go=Math.pow(2,49),q=128,ft=127;function lt(r){if(r<zu)return 1;if(r<qu)return 2;if(r<Hu)return 3;if(r<ho)return 4;if(r<po)return 5;if(r<mo)return 6;if(r<go)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function yo(r,t,e=0){switch(lt(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Vu(r,t,e=0){switch(lt(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function xo(r,t){let e=r[t],n=0;if(n+=e&ft,e<q||(e=r[t+1],n+=(e&ft)<<7,e<q)||(e=r[t+2],n+=(e&ft)<<14,e<q)||(e=r[t+3],n+=(e&ft)<<21,e<q)||(e=r[t+4],n+=(e&ft)*ho,e<q)||(e=r[t+5],n+=(e&ft)*po,e<q)||(e=r[t+6],n+=(e&ft)*mo,e<q)||(e=r[t+7],n+=(e&ft)*go,e<q))return n;throw new RangeError("Could not decode varint")}function ju(r,t){let e=r.get(t),n=0;if(n+=e&ft,e<q||(e=r.get(t+1),n+=(e&ft)<<7,e<q)||(e=r.get(t+2),n+=(e&ft)<<14,e<q)||(e=r.get(t+3),n+=(e&ft)<<21,e<q)||(e=r.get(t+4),n+=(e&ft)*ho,e<q)||(e=r.get(t+5),n+=(e&ft)*po,e<q)||(e=r.get(t+6),n+=(e&ft)*mo,e<q)||(e=r.get(t+7),n+=(e&ft)*go,e<q))return n;throw new RangeError("Could not decode varint")}function oe(r,t,e=0){return t==null&&(t=yt(lt(r))),t instanceof Uint8Array?yo(r,t,e):Vu(r,t,e)}function Gt(r,t=0){return r instanceof Uint8Array?xo(r,t):ju(r,t)}var wo=new Float32Array([-0]),se=new Uint8Array(wo.buffer);function Ui(r,t,e){wo[0]=r,t[e]=se[0],t[e+1]=se[1],t[e+2]=se[2],t[e+3]=se[3]}function Ni(r,t){return se[0]=r[t],se[1]=r[t+1],se[2]=r[t+2],se[3]=r[t+3],wo[0]}var Eo=new Float64Array([-0]),ht=new Uint8Array(Eo.buffer);function Oi(r,t,e){Eo[0]=r,t[e]=ht[0],t[e+1]=ht[1],t[e+2]=ht[2],t[e+3]=ht[3],t[e+4]=ht[4],t[e+5]=ht[5],t[e+6]=ht[6],t[e+7]=ht[7]}function Mi(r,t){return ht[0]=r[t],ht[1]=r[t+1],ht[2]=r[t+2],ht[3]=r[t+3],ht[4]=r[t+4],ht[5]=r[t+5],ht[6]=r[t+6],ht[7]=r[t+7],Eo[0]}var Gu=BigInt(Number.MAX_SAFE_INTEGER),$u=BigInt(Number.MIN_SAFE_INTEGER),St=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 me;if(t<Gu&&t>$u)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>Fi&&(o=0n,++n>Fi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return me;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):me}},me=new St(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var Fi=4294967296n;function Ki(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 zi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function So(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 Lt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Cr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var vo=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,Lt(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 Lt(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=Ni(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=Mi(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 Lt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return zi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(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 St(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 Lt(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 Lt(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 Lt(this,8);let t=Cr(this.buf,this.pos+=4),e=Cr(this.buf,this.pos+=4);return new St(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=xo(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 Ao(r){return new vo(r instanceof Uint8Array?r:r.subarray())}function $t(r,t,e){let n=Ao(r);return t.decode(n,void 0,e)}function _o(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return yt(i);o+i>t&&(n=yt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var ge=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Io(){}var Lo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Zu=_o();function Wu(r){return globalThis.Buffer!=null?yt(r):Zu(r)}var ir=class{len;head;tail;states;constructor(){this.len=0,this.head=new ge(Io,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ge(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new To((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(kr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=St.fromBigInt(t);return this._push(kr,e.length(),e)}uint64Number(t){return this._push(yo,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=St.fromBigInt(t).zzEncode();return this._push(kr,e.length(),e)}sint64Number(t){let e=St.fromNumber(t).zzEncode();return this._push(kr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Bo,1,t?1:0)}fixed32(t){return this._push(sr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=St.fromBigInt(t);return this._push(sr,4,e.lo)._push(sr,4,e.hi)}fixed64Number(t){let e=St.fromNumber(t);return this._push(sr,4,e.lo)._push(sr,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(Ui,4,t)}double(t){return this._push(Oi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Bo,1,0):this.uint32(e)._push(Xu,e,t)}string(t){let e=Ki(t);return e!==0?this.uint32(e)._push(So,e,t):this._push(Bo,1,0)}fork(){return this.states=new Lo(this),this.head=this.tail=new ge(Io,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 ge(Io,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=Wu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Bo(r,t,e){t[e]=r&255}function Yu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var To=class extends ge{next;constructor(t,e){super(Yu,t,e),this.next=void 0}};function kr(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 sr(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 Xu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ir.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Qu,t,r),this},ir.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ju,t,r),this});function Qu(r,t,e){t.set(r,e)}function Ju(r,t,e){r.length<40?So(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Q(r),e)}function Ro(){return new ir}function Zt(r,t){let e=Ro();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ue;(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"})(Ue||(Ue={}));function Ur(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ne(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Ur("enum",Ue.VARINT,e,n)}function Wt(r,t){return Ur("message",Ue.LENGTH_DELIMITED,r,t)}var Nr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var vt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(vt||(vt={}));var Po;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Po||(Po={}));(function(r){r.codec=()=>Ne(Po)})(vt||(vt={}));var ar;(function(r){let t;r.codec=()=>(t==null&&(t=Wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),vt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=vt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(ar||(ar={}));var Do;(function(r){let t;r.codec=()=>(t==null&&(t=Wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),vt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=vt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(Do||(Do={}));var cr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Or=class extends Te{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Gs(t);let n=Qe(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),Kt(s)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),ce(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:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Co=(r,t,e)=>new Or(r,t).update(e).digest();Co.create=(r,t)=>new Or(r,t);function Hi(r){r.lowS!==void 0&&Dt("lowS",r.lowS),r.prehash!==void 0&&Dt("prehash",r.prehash)}function ef(r){let t=or(r);Vt(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var No=class extends Error{constructor(t=""){super(t)}},Yt={Err:No,_tlv:{encode:(r,t)=>{let{Err:e}=Yt;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=rr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?rr(o.length/2|128):"";return rr(r)+s+o+t},decode(r,t){let{Err:e}=Yt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Yt;if(r<Xt)throw new t("integer: negative integers are not allowed");let e=rr(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}=Yt;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 Ht(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Yt,o=W("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l}=n.decode(2,a);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=Yt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};function ko(r,t){return re(he(r,t))}var Xt=BigInt(0),it=BigInt(1),P0=BigInt(2),Uo=BigInt(3),rf=BigInt(4);function nf(r){let t=ef(r),{Fp:e}=t,n=jt(t.n,t.nBitLength),o=t.toBytes||((E,d,b)=>{let I=d.toAffine();return ne(Uint8Array.from([4]),e.toBytes(I.x),e.toBytes(I.y))}),s=t.fromBytes||(E=>{let d=E.subarray(1),b=e.fromBytes(d.subarray(0,e.BYTES)),I=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:b,y:I}});function i(E){let{a:d,b}=t,I=e.sqr(E),B=e.mul(I,E);return e.add(e.add(B,e.mul(E,d)),b)}function c(E,d){let b=e.sqr(d),I=i(E);return e.eql(b,I)}if(!c(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let a=e.mul(e.pow(t.a,Uo),rf),u=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(a,u)))throw new Error("bad curve params: a or b");function l(E){return Br(E,it,t.n)}function f(E){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:I,n:B}=t;if(d&&typeof E!="bigint"){if(Pe(E)&&(E=re(E)),typeof E!="string"||!d.includes(E.length))throw new Error("invalid private key");E=E.padStart(b*2,"0")}let L;try{L=typeof E=="bigint"?E:Ht(W("private key",E,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof E)}return I&&(L=j(L,B)),Et("private key",L,it,B),L}function h(E){if(!(E instanceof m))throw new Error("ProjectivePoint expected")}let x=Ce((E,d)=>{let{px:b,py:I,pz:B}=E;if(e.eql(B,e.ONE))return{x:b,y:I};let L=E.is0();d==null&&(d=L?e.ONE:e.inv(B));let k=e.mul(b,d),O=e.mul(I,d),P=e.mul(B,d);if(L)return{x:e.ZERO,y:e.ZERO};if(!e.eql(P,e.ONE))throw new Error("invZ was invalid");return{x:k,y:O}}),g=Ce(E=>{if(E.is0()){if(t.allowInfinityPoint&&!e.is0(E.py))return;throw new Error("bad point: ZERO")}let{x:d,y:b}=E.toAffine();if(!e.isValid(d)||!e.isValid(b))throw new Error("bad point: x or y not FE");if(!c(d,b))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(d,b,I){if(d==null||!e.isValid(d))throw new Error("x required");if(b==null||!e.isValid(b)||e.is0(b))throw new Error("y required");if(I==null||!e.isValid(I))throw new Error("z required");this.px=d,this.py=b,this.pz=I,Object.freeze(this)}static fromAffine(d){let{x:b,y:I}=d||{};if(!d||!e.isValid(b)||!e.isValid(I))throw new Error("invalid affine point");if(d instanceof m)throw new Error("projective point not allowed");let B=L=>e.eql(L,e.ZERO);return B(b)&&B(I)?m.ZERO:new m(b,I,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let b=ke(e,d.map(I=>I.pz));return d.map((I,B)=>I.toAffine(b[B])).map(m.fromAffine)}static fromHex(d){let b=m.fromAffine(s(W("pointHex",d)));return b.assertValidity(),b}static fromPrivateKey(d){return m.BASE.multiply(f(d))}static msm(d,b){return Rr(m,n,d,b)}_setWindowSize(d){F.setWindowSize(this,d)}assertValidity(){g(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){h(d);let{px:b,py:I,pz:B}=this,{px:L,py:k,pz:O}=d,P=e.eql(e.mul(b,O),e.mul(L,B)),U=e.eql(e.mul(I,O),e.mul(k,B));return P&&U}negate(){return new m(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b}=t,I=e.mul(b,Uo),{px:B,py:L,pz:k}=this,O=e.ZERO,P=e.ZERO,U=e.ZERO,C=e.mul(B,B),tt=e.mul(L,L),A=e.mul(k,k),S=e.mul(B,L);return S=e.add(S,S),U=e.mul(B,k),U=e.add(U,U),O=e.mul(d,U),P=e.mul(I,A),P=e.add(O,P),O=e.sub(tt,P),P=e.add(tt,P),P=e.mul(O,P),O=e.mul(S,O),U=e.mul(I,U),A=e.mul(d,A),S=e.sub(C,A),S=e.mul(d,S),S=e.add(S,U),U=e.add(C,C),C=e.add(U,C),C=e.add(C,A),C=e.mul(C,S),P=e.add(P,C),A=e.mul(L,k),A=e.add(A,A),C=e.mul(A,S),O=e.sub(O,C),U=e.mul(A,tt),U=e.add(U,U),U=e.add(U,U),new m(O,P,U)}add(d){h(d);let{px:b,py:I,pz:B}=this,{px:L,py:k,pz:O}=d,P=e.ZERO,U=e.ZERO,C=e.ZERO,tt=t.a,A=e.mul(t.b,Uo),S=e.mul(b,L),T=e.mul(I,k),w=e.mul(B,O),p=e.add(b,I),y=e.add(L,k);p=e.mul(p,y),y=e.add(S,T),p=e.sub(p,y),y=e.add(b,B);let _=e.add(L,O);return y=e.mul(y,_),_=e.add(S,w),y=e.sub(y,_),_=e.add(I,B),P=e.add(k,O),_=e.mul(_,P),P=e.add(T,w),_=e.sub(_,P),C=e.mul(tt,y),P=e.mul(A,w),C=e.add(P,C),P=e.sub(T,C),C=e.add(T,C),U=e.mul(P,C),T=e.add(S,S),T=e.add(T,S),w=e.mul(tt,w),y=e.mul(A,y),T=e.add(T,w),w=e.sub(S,w),w=e.mul(tt,w),y=e.add(y,w),S=e.mul(T,y),U=e.add(U,S),S=e.mul(_,y),P=e.mul(p,P),P=e.sub(P,S),S=e.mul(p,T),C=e.mul(_,C),C=e.add(C,S),new m(P,U,C)}subtract(d){return this.add(d.negate())}is0(){return this.equals(m.ZERO)}wNAF(d){return F.wNAFCached(this,d,m.normalizeZ)}multiplyUnsafe(d){let{endo:b,n:I}=t;Et("scalar",d,Xt,I);let B=m.ZERO;if(d===Xt)return B;if(this.is0()||d===it)return this;if(!b||F.hasPrecomputes(this))return F.wNAFCachedUnsafe(this,d,m.normalizeZ);let{k1neg:L,k1:k,k2neg:O,k2:P}=b.splitScalar(d),U=B,C=B,tt=this;for(;k>Xt||P>Xt;)k&it&&(U=U.add(tt)),P&it&&(C=C.add(tt)),tt=tt.double(),k>>=it,P>>=it;return L&&(U=U.negate()),O&&(C=C.negate()),C=new m(e.mul(C.px,b.beta),C.py,C.pz),U.add(C)}multiply(d){let{endo:b,n:I}=t;Et("scalar",d,it,I);let B,L;if(b){let{k1neg:k,k1:O,k2neg:P,k2:U}=b.splitScalar(d),{p:C,f:tt}=this.wNAF(O),{p:A,f:S}=this.wNAF(U);C=F.constTimeNegate(k,C),A=F.constTimeNegate(P,A),A=new m(e.mul(A.px,b.beta),A.py,A.pz),B=C.add(A),L=tt.add(S)}else{let{p:k,f:O}=this.wNAF(d);B=k,L=O}return m.normalizeZ([B,L])[0]}multiplyAndAddUnsafe(d,b,I){let B=m.BASE,L=(O,P)=>P===Xt||P===it||!O.equals(B)?O.multiplyUnsafe(P):O.multiply(P),k=L(this,b).add(L(d,I));return k.is0()?void 0:k}toAffine(d){return x(this,d)}isTorsionFree(){let{h:d,isTorsionFree:b}=t;if(d===it)return!0;if(b)return b(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:b}=t;return d===it?this:b?b(m,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Dt("isCompressed",d),this.assertValidity(),o(m,this,d)}toHex(d=!0){return Dt("isCompressed",d),re(this.toRawBytes(d))}}m.BASE=new m(t.Gx,t.Gy,e.ONE),m.ZERO=new m(e.ZERO,e.ONE,e.ZERO);let{endo:v,nBitLength:R}=t,F=Tr(m,v?Math.ceil(R/2):R);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:f,weierstrassEquation:i,isWithinCurveOrder:l}}function of(r){let t=or(r);return Vt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Vi(r){let t=of(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,c=2*e.BYTES+1;function a(A){return j(A,n)}function u(A){return Lr(A,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:h,isWithinCurveOrder:x}=nf({...t,toBytes(A,S,T){let w=S.toAffine(),p=e.toBytes(w.x),y=ne;return Dt("isCompressed",T),T?y(Uint8Array.from([S.hasEvenY()?2:3]),p):y(Uint8Array.from([4]),p,e.toBytes(w.y))},fromBytes(A){let S=A.length,T=A[0],w=A.subarray(1);if(S===i&&(T===2||T===3)){let p=Ht(w);if(!Br(p,it,e.ORDER))throw new Error("Point is not on curve");let y=h(p),_;try{_=e.sqrt(y)}catch(M){let K=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+K)}let D=(_&it)===it;return(T&1)===1!==D&&(_=e.neg(_)),{x:p,y:_}}else if(S===c&&T===4){let p=e.fromBytes(w.subarray(0,e.BYTES)),y=e.fromBytes(w.subarray(e.BYTES,2*e.BYTES));return{x:p,y}}else{let p=i,y=c;throw new Error("invalid Point, expected length of "+p+", or uncompressed "+y+", got "+S)}}});function g(A){let S=n>>it;return A>S}function m(A){return g(A)?a(-A):A}let v=(A,S,T)=>Ht(A.slice(S,T));class R{constructor(S,T,w){Et("r",S,it,n),Et("s",T,it,n),this.r=S,this.s=T,w!=null&&(this.recovery=w),Object.freeze(this)}static fromCompact(S){let T=o;return S=W("compactSignature",S,T*2),new R(v(S,0,T),v(S,T,2*T))}static fromDER(S){let{r:T,s:w}=Yt.toSig(W("DER",S));return new R(T,w)}assertValidity(){}addRecoveryBit(S){return new R(this.r,this.s,S)}recoverPublicKey(S){let{r:T,s:w,recovery:p}=this,y=B(W("msgHash",S));if(p==null||![0,1,2,3].includes(p))throw new Error("recovery id invalid");let _=p===2||p===3?T+t.n:T;if(_>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(p&1)===0?"02":"03",N=l.fromHex(D+ko(_,e.BYTES)),M=u(_),K=a(-y*M),z=a(w*M),H=l.BASE.multiplyAndAddUnsafe(N,K,z);if(!H)throw new Error("point at infinify");return H.assertValidity(),H}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new R(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return nr(this.toDERHex())}toDERHex(){return Yt.hexFromSig(this)}toCompactRawBytes(){return nr(this.toCompactHex())}toCompactHex(){let S=o;return ko(this.r,S)+ko(this.s,S)}}let F={isValidPrivateKey(A){try{return f(A),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let A=oo(t.n);return Ei(t.randomBytes(A),t.n)},precompute(A=8,S=l.BASE){return S._setWindowSize(A),S.multiply(BigInt(3)),S}};function E(A,S=!0){return l.fromPrivateKey(A).toRawBytes(S)}function d(A){if(typeof A=="bigint")return!1;if(A instanceof l)return!0;let T=W("key",A).length,w=e.BYTES,p=w+1,y=2*w+1;if(!(t.allowedPrivateKeyLengths||o===p))return T===p||T===y}function b(A,S,T=!0){if(d(A)===!0)throw new Error("first arg must be private key");if(d(S)===!1)throw new Error("second arg must be public key");return l.fromHex(S).multiply(f(A)).toRawBytes(T)}let I=t.bits2int||function(A){if(A.length>8192)throw new Error("input is too large");let S=Ht(A),T=A.length*8-s;return T>0?S>>BigInt(T):S},B=t.bits2int_modN||function(A){return a(I(A))},L=de(s);function k(A){return Et("num < 2^"+s,A,Xt,L),he(A,o)}function O(A,S,T=P){if(["recovered","canonical"].some(J=>J in T))throw new Error("sign() legacy options not supported");let{hash:w,randomBytes:p}=t,{lowS:y,prehash:_,extraEntropy:D}=T;y==null&&(y=!0),A=W("msgHash",A),Hi(T),_&&(A=W("prehashed msgHash",w(A)));let N=B(A),M=f(S),K=[k(M),k(N)];if(D!=null&&D!==!1){let J=D===!0?p(e.BYTES):D;K.push(W("extraEntropy",J))}let z=ne(...K),H=N;function et(J){let at=I(J);if(!x(at))return;let gt=u(at),nt=l.BASE.multiply(at).toAffine(),ut=a(nt.x);if(ut===Xt)return;let xt=a(gt*a(H+ut*M));if(xt===Xt)return;let At=(nt.x===ut?0:2)|Number(nt.y&it),qe=xt;return y&&g(xt)&&(qe=m(xt),At^=1),new R(ut,qe,At)}return{seed:z,k2sig:et}}let P={lowS:t.lowS,prehash:!1},U={lowS:t.lowS,prehash:!1};function C(A,S,T=P){let{seed:w,k2sig:p}=O(A,S,T),y=t;return di(y.hash.outputLen,y.nByteLength,y.hmac)(w,p)}l.BASE._setWindowSize(8);function tt(A,S,T,w=U){let p=A;S=W("msgHash",S),T=W("publicKey",T);let{lowS:y,prehash:_,format:D}=w;if(Hi(w),"strict"in w)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let N=typeof p=="string"||Pe(p),M=!N&&!D&&typeof p=="object"&&p!==null&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!N&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let K,z;try{if(M&&(K=new R(p.r,p.s)),N){try{D!=="compact"&&(K=R.fromDER(p))}catch(At){if(!(At instanceof Yt.Err))throw At}!K&&D!=="der"&&(K=R.fromCompact(p))}z=l.fromHex(T)}catch{return!1}if(!K||y&&K.hasHighS())return!1;_&&(S=t.hash(S));let{r:H,s:et}=K,J=B(S),at=u(et),gt=a(J*at),nt=a(H*at),ut=l.BASE.multiplyAndAddUnsafe(z,gt,nt)?.toAffine();return ut?a(ut.x)===H:!1}return{CURVE:t,getPublicKey:E,getSharedSecret:b,sign:C,verify:tt,ProjectivePoint:l,Signature:R,utils:F}}function sf(r){return{hash:r,hmac:(t,...e)=>Co(r,t,jn(...e)),randomBytes:_r}}function ji(r,t){let e=n=>Vi({...r,...sf(n)});return{...e(t),create:e}}var Zi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Gi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),af=BigInt(0),cf=BigInt(1),Oo=BigInt(2),$i=(r,t)=>(r+t/Oo)/t;function uf(r){let t=Zi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=Y(l,e,t)*l%t,h=Y(f,e,t)*l%t,x=Y(h,Oo,t)*u%t,g=Y(x,o,t)*x%t,m=Y(g,s,t)*g%t,v=Y(m,c,t)*m%t,R=Y(v,a,t)*v%t,F=Y(R,c,t)*m%t,E=Y(F,e,t)*l%t,d=Y(E,i,t)*g%t,b=Y(d,n,t)*u%t,I=Y(b,Oo,t);if(!Mo.eql(Mo.sqr(I),r))throw new Error("Cannot find square root");return I}var Mo=jt(Zi,void 0,void 0,{sqrt:uf}),Oe=ji({a:af,b:BigInt(7),Fp:Mo,n:Gi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Gi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-cf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=$i(s*r,t),a=$i(-n*r,t),u=j(r-c*e-a*o,t),l=j(-c*n-a*s,t),f=u>i,h=l>i;if(f&&(u=t-u),h&&(l=t-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},ii);function Wi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Yi(r,t,e){let n=Ze.digest(e instanceof Uint8Array?e:e.subarray());if(Wi(n))return n.then(({digest:o})=>Oe.verify(t,o,r)).catch(o=>{throw new cr(String(o))});try{return Oe.verify(t,n.digest,r)}catch(o){throw new cr(String(o))}}var Mr=class{type="secp256k1";raw;_key;constructor(t){this._key=Qi(t),this.raw=Xi(this._key)}toMultihash(){return _t.digest(Le(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e){return Yi(this._key,e,t)}};function Ji(r){return new Mr(r)}function Xi(r){return Oe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Qi(r){try{return Oe.ProjectivePoint.fromHex(r),r}catch(t){throw new gr(String(t))}}function ta(r){let{Type:t,Data:e}=ar.decode(r.digest),n=e??new Uint8Array;switch(t){case vt.Ed25519:return ki(n);case vt.secp256k1:return Ji(n);case vt.ECDSA:return Hs(n);default:throw new He}}function Le(r){return ar.encode({Type:vt[r.type],Data:r.raw})}var ea=Symbol.for("nodejs.util.inspect.custom"),ff=114,ur=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[yn]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ot.createV1(ff,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ea](){return`PeerId(${this.toString()})`}},Fr=class extends ur{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Kr=class extends ur{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},zr=class extends ur{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},lf=2336,qr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(Q(this.url))}[ea](){return`PeerId(${this.url})`}[yn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ot.createV1(lf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=G(t)),t.toString()===this.toString())}};function Hr(r){if(df(r))return new Fr({multihash:r});if(hf(r))try{let t=ta(r);if(t.type==="Ed25519")return new Kr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new zr({multihash:r,publicKey:t})}catch{let e=G(r.digest);return new qr(new URL(e))}throw new yr("Supplied PeerID Multihash is invalid")}function hf(r){return r.code===_t.code}function df(r){return r.code===Ze.code}function Fo(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 Vr(r){let t=Mt($.decode(`z${r}`));return Hr(t)}var jr=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Fo(this.set.entries(),t=>{let e=Vr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Vr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Fo(this.set.values(),t=>Vr(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 Ko(){return new jr}var zo={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ra={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},na=new globalThis.TextEncoder;function pf(r,t){let e=zo[t],n=ra[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function mf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=zo[t],o=ra[t],s=r;for(;s.length>0;){let i=na.encodeInto(s,e);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(e[c]),o=BigInt.asUintN(t,o*n)}return o}function qo(r,{size:t=32,utf8Buffer:e}={}){if(!zo[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return mf(r,t,e);r=na.encode(r)}return pf(r,t)}var fr={hash:r=>Number(qo(r,{size:32})),hashV:(r,t)=>gf(fr.hash(r,t))};function gf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),Q(t,"base16")}var Ho=64,Tt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Ho)throw new TypeError("Invalid Fingerprint Size");let s=e.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=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?dt(this.fp,t.fp):!1}};function ye(r,t){return Math.floor(Math.random()*(t-r))+r}var xe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Tt))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 Tt))throw new TypeError("Invalid Fingerprint");let e=ye(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var yf=500,lr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??fr,this.seed=t.seed??ye(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=Q(t));let e=new Tt(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 xe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new xe(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[ye(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize));for(let c=0;c<yf;c++){let a=this.buckets[i].swap(e);if(a!=null&&(i=(i^a.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize)),this.buckets[i].add(a)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=Q(t));let e=new Tt(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=Q(t));let e=new Tt(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}},xf={1:.5,2:.84,4:.95,8:.98};function bf(r=.001){return r>.002?2:r>1e-5?4:8}function oa(r,t=.001){let e=bf(t),n=xf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Ho);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Gr=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??fr,this.seed=t.seed??ye(0,Math.pow(2,10)),this.filterSeries=[new lr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=Q(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new lr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=Q(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=Q(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 Vo(r,t=.001,e){return new Gr({...oa(r,t),...e??{}})}var $r=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return e.set(s.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var sa=45,wf=15,Me=new $r;function Zr(r){if(!(r.length>wf))return Me.new(r).parseWith(()=>Me.readIPv4Addr())}function Wr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>sa))return Me.new(r).parseWith(()=>Me.readIPv6Addr())}function be(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>sa)return;let e=Me.new(r).parseWith(()=>Me.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 ia(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 aa(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 jo(r){switch(r.length){case we:return r.join(".");case Ee:{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 ca(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 ua(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var we=4,Ee=16,Lm=parseInt("0xFFFF",16),Ef=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function hr(r,t){t.length===Ee&&r.length===we&&ia(t,0,11)&&(t=t.slice(12)),t.length===we&&r.length===Ee&&aa(r,Ef,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 fa(r,t){if(typeof t=="string"&&(t=be(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 Go(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=we,o=Zr(t);if(o==null&&(n=Ee,o=Wr(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=$o(s,8*n);return{network:hr(o,i),mask:i}}function $o(r,t){if(t!==8*we&&t!==8*Ee)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 Fe=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Go(t));else{let n=be(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=be(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=$o(o,8*n.length);this.network=hr(n,this.mask)}}contains(t){return fa({network:this.network,mask:this.mask},t)}toString(){let t=ca(this.mask),e=t!==-1?String(t):ua(this.mask);return jo(this.network)+"/"+e}};function la(r,t){return new Fe(r).contains(t)}var Sf=41;function ha(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===Sf)return la("2000::/3",e)}catch{}return!1}function Yr(r){return!!Zr(r)}function Xr(r){return!!Wr(r)}function Qr(r){return!!be(r)}var pa=Va(da(),1),vf=["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"],Af=vf.map(r=>new pa.Netmask(r));function Zo(r){for(let t of Af)if(t.contains(r))return!0;return!1}function _f(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function If(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 Zo(o)}function Bf(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Lf(r){let t=r.split(":"),e=t[t.length-1];return Zo(e)}function Tf(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 ma(r){return Yr(r)?Zo(r):_f(r)?If(r):Bf(r)?Lf(r):Xr(r)?Tf(r):void 0}function ga(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function Wo(r){try{if(!ga(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:ma(t)??!1}catch{}return!0}function Rt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Jr=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}},Ke=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Jr(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 Jr(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 Yo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ya(r={}){return Rf(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 Rf(r,t){t=t??{};let e=t.onEnd,n=new Ke,o,s,i,c=Rt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((v,R)=>{s=F=>{s=null,n.push(F);try{v(r(n))}catch(E){R(E)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Rt()})}},u=v=>s!=null?s(v):(n.push(v),o),l=v=>(n=new Ke,s!=null?s({error:v}):(n.push({error:v}),o)),f=v=>{if(i)return o;if(t?.objectMode!==!0&&v?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:v})},h=v=>i?o:(i=!0,v!=null?l(v):u({done:!0})),x=()=>(n=new Ke,h(),{done:!0}),g=v=>(h(v),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:x,throw:g,push:f,end:h,get readableLength(){return n.size},onEmpty:async v=>{let R=v?.signal;if(R?.throwIfAborted(),n.isEmpty())return;let F,E;R!=null&&(F=new Promise((d,b)=>{E=()=>{b(new Yo)},R.addEventListener("abort",E)}));try{await Promise.race([c.promise,F])}finally{E!=null&&R!=null&&R?.removeEventListener("abort",E)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(v){return m.throw(v),e!=null&&(e(v),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(v){return m.end(v),e!=null&&(e(v),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:v=>m.onEmpty(v)},o}var Xo=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 tn(r,t,e,n){let o=new Xo(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function c(){e?.removeEventListener("abort",l),r.removeEventListener(t,a),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let a=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){c(),i(h);return}c(),s(f)},u=f=>{c(),i(f.detail)},l=()=>{c(),i(o)};e?.addEventListener("abort",l),r.addEventListener(t,a),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}function Qo(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 en=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var rn=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 Se(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new rn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new rn(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 nn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Rt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new kt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Df(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var on=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=Df(),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 kt),this.cleanup())}async join(t={}){let e=new nn(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 Se(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 sn=class extends xr{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=Qo(this.emitEmpty.bind(this),1),this.emitIdle=Qo(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 en;let n=new on(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 kt)}),this.clear()}async onEmpty(t){this.size!==0&&await tn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await tn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await tn(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=ya({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),e.end(a)},o=a=>{a.detail!=null&&e.push(a.detail)},s=a=>{n(a.detail)},i=()=>{n()},c=()=>{n(new kt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",c);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",c),n()}}};var an=class extends sn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function cn(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 xa(r,t,e){let n,o;function s(){let c={signal:o.signal};if(e?.timeout!=null){let a=cn([o.signal,AbortSignal.timeout(e.timeout)]);c.signal=a}Promise.resolve().then(async()=>{await r(c)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{setInterval:c=>{t=c,n!=null&&(clearTimeout(n),n=setTimeout(s,t))},setTimeout:c=>{e??={},e.timeout=c},start:()=>{i||(i=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),i=!1}}}var ba=Yr,Cf=Xr,Jo=function(r){let t=0;if(r=r.toString().trim(),ba(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Cf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ba(e[n]),i;s&&(i=Jo(e[n]),e[n]=G(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,G(i.slice(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++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},wa=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ze={},ts={},Uf=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Uf.forEach(r=>{let t=Nf(...r);ts[t.code]=t,ze[t.name]=t});function Nf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function V(r){if(typeof r=="number"){if(ts[r]!=null)return ts[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ze[r]!=null)return ze[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Vg=V("ip4"),jg=V("ip6"),Gg=V("ipcidr");function os(r,t){switch(V(r).code){case 4:case 41:return Mf(t);case 42:return ns(t);case 43:return G(t,"base10");case 6:case 273:case 33:case 132:return va(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ns(t);case 421:return qf(t);case 444:return Sa(t);case 445:return Sa(t);case 466:return zf(t);case 481:return globalThis.encodeURIComponent(ns(t));default:return G(t,"base16")}}function ss(r,t){switch(V(r).code){case 4:return Ea(t);case 41:return Ea(t);case 42:return rs(t);case 43:return Q(t,"base10");case 6:case 273:case 33:case 132:return is(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return rs(t);case 421:return Ff(t);case 444:return Hf(t);case 445:return Vf(t);case 466:return Kf(t);case 481:return rs(globalThis.decodeURIComponent(t));default:return Q(t,"base16")}}var es=Object.values(We).map(r=>r.decoder),Of=function(){let r=es[0].or(es[1]);return es.slice(2).forEach(t=>r=r.or(t)),r}();function Ea(r){if(!Qr(r))throw new Error("invalid ip address");return Jo(r)}function Mf(r){let t=wa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Qr(t))throw new Error("invalid ip address");return t}function is(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function va(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function rs(r){let t=Q(r),e=Uint8Array.from(oe(t.length));return wt([e,t],e.length+t.length)}function ns(r){let t=Gt(r);if(r=r.slice(lt(t)),r.length!==t)throw new Error("inconsistent lengths");return G(r)}function Ff(r){let t;r[0]==="Q"||r[0]==="1"?t=Mt($.decode(`z${r}`)).bytes:t=ot.parse(r).multihash.bytes;let e=Uint8Array.from(oe(t.length));return wt([e,t],e.length+t.length)}function Kf(r){let t=Of.decode(r),e=Uint8Array.from(oe(t.length));return wt([e,t],e.length+t.length)}function zf(r){let t=Gt(r),e=r.slice(lt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+G(e,"base64url")}function qf(r){let t=Gt(r),e=r.slice(lt(t));if(e.length!==t)throw new Error("inconsistent lengths");return G(e,"base58btc")}function Hf(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=Ot.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=is(n);return wt([e,o],e.length+o.length)}function Vf(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=Ot.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=is(n);return wt([e,o],e.length+o.length)}function Sa(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=G(t,"base32"),o=va(e);return`${n}:${o}`}function Aa(r){r=as(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],c=V(i);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(s++,s>=o.length)throw new un("invalid address: "+r);if(c.path===!0){n=as(o.slice(s).join("/")),t.push([c.code,ss(c.code,n)]),e.push([c.code,n]);break}let a=ss(c.code,o[s]);t.push([c.code,a]),e.push([c.code,os(c.code,a)])}return{string:_a(e),bytes:fn(t),tuples:t,stringTuples:e,path:n}}function cs(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Gt(r,o),i=lt(s),c=V(s),a=jf(c,r.slice(o+i));if(a===0){t.push([s]),e.push([s]),o+=i;continue}let u=r.slice(o+i,o+i+a);if(o+=a+i,o>r.length)throw new un("Invalid address Uint8Array: "+G(r,"base16"));t.push([s,u]);let l=os(s,u);if(e.push([s,l]),c.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:_a(e),tuples:t,stringTuples:e,path:n}}function _a(r){let t=[];return r.map(e=>{let n=V(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),as(t.join("/"))}function fn(r){return wt(r.map(t=>{let e=V(t[0]),n=Uint8Array.from(oe(e.code));return t.length>1&&t[1]!=null&&(n=wt([n,t[1]])),n}))}function jf(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Gt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+lt(e)}}function as(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var un=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Gf=Symbol.for("nodejs.util.inspect.custom"),fs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),$f=[V("dns").code,V("dns4").code,V("dns6").code,V("dnsaddr").code],us=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},ln=class r{bytes;#t;#e;#r;#n;[fs]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=cs(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Aa(t)}else if(Ba(t))e=cs(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=V("tcp"),c=V("udp"),a=V("ip4"),u=V("ip6"),l=V("dns6"),f=V("ip6zone");for(let[x,g]of this.stringTuples())x===f.code&&(s=`%${g??""}`),$f.includes(x)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${g??""}${s}`,t=x===l.code?6:4),(x===i.code||x===c.code)&&(e=V(x).name==="tcp"?"tcp":"udp",o=parseInt(g??"")),(x===a.code||x===u.code)&&(e=V(x).name==="tcp"?"tcp":"udp",n=`${g??""}${s}`,t=x===u.code?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}}protos(){return this.#e.map(([t])=>Object.assign({},V(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>V(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(fn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===ze.p2p.code&&t.push([n,o]),n===ze["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?G($.decode(`z${n}`),"base58btc"):G(ot.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return dt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Ia.get(e.name);if(n==null)throw new us(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>pr(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(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Gf](){return`Multiaddr(${this.#t})`}};var Ia=new Map;function Ba(r){return!!r?.[fs]}function pr(r){return new ln(r)}var ls=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Rt(),this.haveNext=Rt()}[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=Rt(),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=Rt(),await Se(this.readNext.promise,e?.signal,e)}};function La(){return new ls}var hn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ta(r,t){let e=La();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let c of i)await e.push(c);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 rt;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:a,value:u}=await Se(n.next(),i?.signal);return a===!0?null:u}for(;o.byteLength<i.bytes;){let{value:a,done:u}=await Se(n.next(),i?.signal);if(u===!0)throw new hn("unexpected end of input");o.append(a)}let c=o.sublist(0,i.bytes);return o.consume(i.bytes),c},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,c):await e.push(i.subarray(),c)},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 dn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},pn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},mn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ra(r,t={}){let e=Ta(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=lt(t.maxDataLength));let n=t?.lengthDecoder??Gt,o=t?.lengthEncoder??oe;return{read:async i=>{let c=-1,a=new rt;for(;;){a.append(await e.read({...i,bytes:1}));try{c=n(a)}catch(u){if(u instanceof RangeError)continue;throw u}if(c<0)throw new dn("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new mn("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new pn("message length too long");return e.read({...i,bytes:c})},write:async(i,c)=>{await e.write(new rt(o(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new rt(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(a,c)},unwrap:()=>e.unwrap()}}function hs(r,t){let e=Ra(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Pa="libp2p",Da="autonat",Ca="1.0.0";var Z;(function(r){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(u){u.codec=()=>Ne(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(u){u.codec=()=>Ne(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let l;u.codec=()=>(l==null&&(l=Wt((f,h,x={})=>{if(x.lengthDelimited!==!1&&h.fork(),f.id!=null&&(h.uint32(10),h.bytes(f.id)),f.addrs!=null)for(let g of f.addrs)h.uint32(18),h.bytes(g);x.lengthDelimited!==!1&&h.ldelim()},(f,h,x={})=>{let g={addrs:[]},m=h==null?f.len:f.pos+h;for(;f.pos<m;){let v=f.uint32();switch(v>>>3){case 1:{g.id=f.bytes();break}case 2:{if(x.limits?.addrs!=null&&g.addrs.length===x.limits.addrs)throw new Nr('Decode error - map field "addrs" had too many elements');g.addrs.push(f.bytes());break}default:{f.skipType(v&7);break}}}return g})),l),u.encode=f=>Zt(f,u.codec()),u.decode=(f,h)=>$t(f,u.codec(),h)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let l;u.codec=()=>(l==null&&(l=Wt((f,h,x={})=>{x.lengthDelimited!==!1&&h.fork(),f.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(f.peer,h)),x.lengthDelimited!==!1&&h.ldelim()},(f,h,x={})=>{let g={},m=h==null?f.len:f.pos+h;for(;f.pos<m;){let v=f.uint32();switch(v>>>3){case 1:{g.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:x.limits?.peer});break}default:{f.skipType(v&7);break}}}return g})),l),u.encode=f=>Zt(f,u.codec()),u.decode=(f,h)=>$t(f,u.codec(),h)})(i=r.Dial||(r.Dial={}));let c;(function(u){let l;u.codec=()=>(l==null&&(l=Wt((f,h,x={})=>{x.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)),x.lengthDelimited!==!1&&h.ldelim()},(f,h,x={})=>{let g={},m=h==null?f.len:f.pos+h;for(;f.pos<m;){let v=f.uint32();switch(v>>>3){case 1:{g.status=r.ResponseStatus.codec().decode(f);break}case 2:{g.statusText=f.string();break}case 3:{g.addr=f.bytes();break}default:{f.skipType(v&7);break}}}return g})),l),u.encode=f=>Zt(f,u.codec()),u.decode=(f,h)=>$t(f,u.codec(),h)})(c=r.DialResponse||(r.DialResponse={}));let a;r.codec=()=>(a==null&&(a=Wt((u,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),u.type!=null&&(l.uint32(8),r.MessageType.codec().encode(u.type,l)),u.dial!=null&&(l.uint32(18),r.Dial.codec().encode(u.dial,l)),u.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(u.dialResponse,l)),f.lengthDelimited!==!1&&l.ldelim()},(u,l,f={})=>{let h={},x=l==null?u.len:u.pos+l;for(;u.pos<x;){let g=u.uint32();switch(g>>>3){case 1:{h.type=r.MessageType.codec().decode(u);break}case 2:{h.dial=r.Dial.codec().decode(u,u.uint32(),{limits:f.limits?.dial});break}case 3:{h.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:f.limits?.dialResponse});break}default:{u.skipType(g&7);break}}}return h})),a),r.encode=u=>Zt(u,r.codec()),r.decode=(u,l)=>$t(u,r.codec(),l)})(Z||(Z={}));var Jf=4,tl=8,gn=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??Pa}/${Da}/${Ca}`,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=new Map,this.findPeers=xa(this.findRandomPeers.bind(this),6e4),this.addressFilter=Vo(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ms]=["@libp2p/autonat"];get[gs](){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=cn([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=hs(t.stream,{maxDataLength:this.maxMessageSize}).pb(Z);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:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,c=s.peer;if(c?.id==null)return this.log.error("PeerId missing from message"),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Mt(c.id);i=Hr(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let a=c.addrs.map(f=>pr(f)).filter(f=>{let h=f.toOptions();return Wo(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(a.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",a.map(f=>f.toString()).join(", "),i);let u="",l=a[0];for(let f of a){let 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:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(V("p2p").code).bytes}}}catch(x){this.log.error("could not dial %p - %e",i,x),u=x.message}finally{h!=null&&await h.close()}}return{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:l.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||o.multiaddr.toOptions().family===6&&(!e||!ha(o.multiaddr))||Wo(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:Ko(),queue:new an({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>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 c=hs(i).pb(Z),[,a]=await Promise.all([c.write({type:Z.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),c.read({signal:s})]);if(a.type!==Z.MessageType.DIAL_RESPONSE||a.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,a);return}let u=a.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==Z.ResponseStatus.OK&&u!==Z.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,a.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),u===Z.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===Z.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Jf&&this.confirmAddress(o),o.failure===tl&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(c){i.abort(c)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};function el(r={}){return t=>new gn(t,r)}return ja(rl);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: