@libp2p/autonat 2.0.30-6f96de86c → 2.0.30-772b4011e

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,32 +1,19 @@
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 ya=Object.create;var ar=Object.defineProperty;var ba=Object.getOwnPropertyDescriptor;var xa=Object.getOwnPropertyNames;var wa=Object.getPrototypeOf,Ea=Object.prototype.hasOwnProperty;var Sa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)ar(r,e,{get:t[e],enumerable:!0})},os=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of xa(t))!Ea.call(r,o)&&o!==e&&ar(r,o,{get:()=>t[o],enumerable:!(n=ba(t,o))||n.enumerable});return r};var va=(r,t,e)=>(e=r!=null?ya(wa(r)):{},os(t||!r||!r.__esModule?ar(e,"default",{value:r,enumerable:!0}):e,r)),Aa=r=>os(ar({},"__esModule",{value:!0}),r);var Gi=Sa(sr=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,l,f,h;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[u,l,f,h].join(".")},i=function(c){var u,l,f,h,g,y;for(u=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}y=t(c),g=y[0],l=y[1],c=c.substring(l),u.push(g)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var u,l,f,h,g;for(h=0,u=10,l="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,u=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,u=8,l="7")),g=f;f<c.length;){if("0"<=c[f]&&c[f]<=l)h=h*u+(e(c[f])-n)>>>0;else if(u===16)if("a"<=c[f]&&c[f]<="f")h=h*u+(10+e(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*u+(10+e(c[f])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===g)throw new Error("empty octet");return[h,f]},r=function(){function c(u,l){var f,h,g,y;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(y=u.split("/",2),u=y[0],l=y[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(b){throw f=b,new Error("Invalid mask: "+l)}for(h=g=32;g>=0;h=--g)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(b){throw f=b,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,f,h;for(h=i(this.first),f=i(this.last),l=0;h<=f;)u(a(h),h,l),l++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),sr.ip2long=i,sr.long2ip=a,sr.Netmask=r}).call(sr)});var el={};bt(el,{autoNAT:()=>tl});var un=Symbol.for("@libp2p/peer-id");var Dt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Ct=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},cr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var ur=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Me=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var fr=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 ss=Symbol.for("@libp2p/service-capabilities"),is=Symbol.for("@libp2p/service-dependencies");var pn={};bt(pn,{base58btc:()=>$,base58flickr:()=>Ra});var Ll=new Uint8Array(0);function as(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function kt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function cs(r){return new TextEncoder().encode(r)}function us(r){return new TextDecoder().decode(r)}function _a(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var b=0,d=0,x=0,v=y.length;x!==v&&y[x]===0;)x++,b++;for(var p=(v-x)*l+1>>>0,_=new Uint8Array(p);x!==v;){for(var P=y[x],D=0,B=p-1;(P!==0||D<d)&&B!==-1;B--,D++)P+=256*_[B]>>>0,_[B]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");d=D,x++}for(var L=p-d;L!==p&&_[L]===0;)L++;for(var T=c.repeat(b);L<p;++L)T+=r.charAt(_[L]);return T}function h(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var b=0;if(y[b]!==" "){for(var d=0,x=0;y[b]===c;)d++,b++;for(var v=(y.length-b)*u+1>>>0,p=new Uint8Array(v);y[b];){var _=e[y.charCodeAt(b)];if(_===255)return;for(var P=0,D=v-1;(_!==0||P<x)&&D!==-1;D--,P++)_+=a*p[D]>>>0,p[D]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");x=P,b++}if(y[b]!==" "){for(var B=v-x;B!==v&&p[B]===0;)B++;for(var L=new Uint8Array(d+(v-B)),T=d;B!==v;)L[T++]=p[B++];return L}}}function g(y){var b=h(y);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:g}}var Ia=_a,Ba=Ia,ls=Ba;var fn=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")}},ln=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 hs(this,t)}},hn=class{decoders;constructor(t){this.decoders=t}or(t){return hs(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 hs(r,t){return new hn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var dn=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 fn(t,e,n),this.decoder=new ln(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function xe({name:r,prefix:t,encode:e,decode:n}){return new dn(r,t,e,n)}function $t({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ls(e,r);return xe({prefix:t,name:r,encode:n,decode:s=>kt(o(s))})}function La(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),a=0,c=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`);c=c<<e|f,a+=e,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ta(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Q({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return xe({prefix:t,name:r,encode(o){return Ta(o,n,e)},decode(o){return La(o,n,e,r)}})}var $=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ra=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var mn={};bt(mn,{base32:()=>Nt,base32hex:()=>ka,base32hexpad:()=>Ua,base32hexpadupper:()=>Oa,base32hexupper:()=>Na,base32pad:()=>Da,base32padupper:()=>Ca,base32upper:()=>Pa,base32z:()=>Ma});var Nt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Pa=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Da=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ca=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ka=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Na=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ua=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Oa=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ma=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var gn={};bt(gn,{base36:()=>Fe,base36upper:()=>Fa});var Fe=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fa=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ka=ms,ds=128,za=127,qa=~za,Ha=Math.pow(2,31);function ms(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ha;)t[e++]=r&255|ds,r/=128;for(;r&qa;)t[e++]=r&255|ds,r>>>=7;return t[e]=r|0,ms.bytes=e-n+1,t}var Va=yn,ja=128,ps=127;function yn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw yn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ps)<<o:(i&ps)*Math.pow(2,o),o+=7}while(i>=ja);return yn.bytes=s-n,e}var Ga=Math.pow(2,7),$a=Math.pow(2,14),Za=Math.pow(2,21),Wa=Math.pow(2,28),Ya=Math.pow(2,35),Xa=Math.pow(2,42),Qa=Math.pow(2,49),Ja=Math.pow(2,56),tc=Math.pow(2,63),ec=function(r){return r<Ga?1:r<$a?2:r<Za?3:r<Wa?4:r<Ya?5:r<Xa?6:r<Qa?7:r<Ja?8:r<tc?9:10},rc={encode:Ka,decode:Va,encodingLength:ec},nc=rc,Ke=nc;function ze(r,t=0){return[Ke.decode(r,t),Ke.decode.bytes]}function we(r,t,e=0){return Ke.encode(r,t,e),t}function Ee(r){return Ke.encodingLength(r)}function ne(r,t){let e=t.byteLength,n=Ee(r),o=n+Ee(e),s=new Uint8Array(o+e);return we(r,s,0),we(e,s,n),s.set(t,o),new Se(r,e,t,s)}function Ut(r){let t=kt(r),[e,n]=ze(t),[o,s]=ze(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Se(e,o,i,t)}function gs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&as(r.bytes,e.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ys(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return sc(e,bn(r),t??$.encoder);default:return ic(e,bn(r),t??Nt.encoder)}}var bs=new WeakMap;function bn(r){let t=bs.get(r);if(t==null){let e=new Map;return bs.set(r,e),e}return t}var it=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==qe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ac)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=ne(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&&gs(t.multihash,n.multihash)}toString(t){return ys(this,t)}toJSON(){return{"/":ys(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??xs(n,o,s.bytes))}else if(e[cc]===!0){let{version:n,multihash:o,code:s}=e,i=Ut(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!==qe)throw new Error(`Version 0 CID must use dag-pb (code: ${qe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=xs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,qe,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=kt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Se(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,h]=ze(t.subarray(e));return e+=h,f},o=n(),s=qe;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=oc(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 bn(s).set(n,t),s}};function oc(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 Nt.prefix:{let e=t??Nt;return[Nt.prefix,e.decode(r)]}case Fe.prefix:{let e=t??Fe;return[Fe.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 sc(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 ic(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 qe=112,ac=18;function xs(r,t,e){let n=Ee(r),o=n+Ee(t),s=new Uint8Array(o+e.byteLength);return we(r,s,0),we(t,s,n),s.set(e,o),s}var cc=Symbol.for("@ipld/js-cid/CID");var xn={};bt(xn,{identity:()=>At});var ws=0,uc="identity",Es=kt;function fc(r){return ne(ws,Es(r))}var At={code:ws,name:uc,encode:Es,digest:fc};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 _t(r=0){return new Uint8Array(r)}function gt(r=0){return new Uint8Array(r)}function xt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=gt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var vs=Symbol.for("@achingbrain/uint8arraylist");function Ss(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 hr(r){return!!r?.[vs]}var nt=class r{bufs;length;[vs]=!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(hr(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(hr(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=Ss(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ss(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(hr(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 xt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:xt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!hr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let h=u;h>=0;h--){let g=this.get(f+h);if(n[h]!==g){l=Math.max(1,h-a[g]);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=gt(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=_t(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=_t(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=_t(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=gt(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=_t(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=_t(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=_t(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=_t(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=_t(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 wn={};bt(wn,{base10:()=>lc});var lc=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var En={};bt(En,{base16:()=>hc,base16upper:()=>dc});var hc=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),dc=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Sn={};bt(Sn,{base2:()=>pc});var pc=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vn={};bt(vn,{base256emoji:()=>xc});var As=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}"),mc=As.reduce((r,t,e)=>(r[e]=t,r),[]),gc=As.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function yc(r){return r.reduce((t,e)=>(t+=mc[e],t),"")}function bc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=gc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var xc=xe({prefix:"\u{1F680}",name:"base256emoji",encode:yc,decode:bc});var An={};bt(An,{base64:()=>wc,base64pad:()=>Ec,base64url:()=>Sc,base64urlpad:()=>vc});var wc=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ec=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Sc=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vc=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var _n={};bt(_n,{base8:()=>Ac});var Ac=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var In={};bt(In,{identity:()=>_c});var _c=xe({prefix:"\0",name:"identity",encode:r=>us(r),decode:r=>cs(r)});var lh=new TextEncoder,hh=new TextDecoder;var Tn={};bt(Tn,{sha256:()=>He,sha512:()=>Lc});function Ln({name:r,code:t,encode:e}){return new Bn(r,t,e)}var Bn=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?ne(this.code,e):e.then(n=>ne(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Is(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var He=Ln({name:"sha2-256",code:18,encode:Is("SHA-256")}),Lc=Ln({name:"sha2-512",code:19,encode:Is("SHA-512")});var Ve={...In,...Sn,..._n,...wn,...En,...mn,...gn,...pn,...An,...vn},Ah={...Tn,...xn};function Ls(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Bs=Ls("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Rn=Ls("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=gt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Tc={utf8:Bs,"utf-8":Bs,hex:Ve.base16,latin1:Rn,ascii:Rn,binary:Rn,...Ve},dr=Tc;function J(r,t="utf8"){let e=dr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function G(r,t="utf8"){let e=dr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Rc=parseInt("11111",2),Pn=parseInt("10000000",2),Pc=parseInt("01111111",2),Ts={0:je,1:je,2:Dc,3:Nc,4:Uc,5:kc,6:Cc,16:je,22:je,48:je};function Dn(r,t={offset:0}){let e=r[t.offset]&Rc;if(t.offset++,Ts[e]!=null)return Ts[e](r,t);throw new Error("No decoder for tag "+e)}function Ge(r,t){let e=0;if((r[t.offset]&Pn)===Pn){let n=r[t.offset]&Pc,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 je(r,t){Ge(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Dn(r,t);if(n===null)break;e.push(n)}return e}function Dc(r,t){let e=Ge(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 Cc(r,t){let e=Ge(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function kc(r,t){return t.offset++,null}function Nc(r,t){let e=Ge(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 Uc(r,t){let e=Ge(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Oc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new nt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Cn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Oc(r.byteLength);return new nt(Uint8Array.from([t.byteLength|Pn]),t)}function Rs(r){let t=new nt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new nt(Uint8Array.from([2]),Cn(t),t)}function Ps(r){let t=Uint8Array.from([0]),e=new nt(t,r);return new nt(Uint8Array.from([3]),Cn(e),e)}function pr(r,t=48){let e=new nt;for(let n of r)e.append(n);return new nt(Uint8Array.from([t]),Cn(e),e)}async function Ds(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 Mc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Fc=Uint8Array.from([6,5,43,129,4,0,34]),Kc=Uint8Array.from([6,5,43,129,4,0,35]),zc={ext:!0,kty:"EC",crv:"P-256"},qc={ext:!0,kty:"EC",crv:"P-384"},Hc={ext:!0,kty:"EC",crv:"P-521"},kn=32,Nn=48,Un=66;function Cs(r){let t=Dn(r);return ks(t)}function ks(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===kn*2+1)return n=G(t.subarray(e,e+kn),"base64url"),o=G(t.subarray(e+kn),"base64url"),new ve({...zc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Nn*2+1)return n=G(t.subarray(e,e+Nn),"base64url"),o=G(t.subarray(e+Nn),"base64url"),new ve({...qc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Un*2+1)return n=G(t.subarray(e,e+Un),"base64url"),o=G(t.subarray(e+Un),"base64url"),new ve({...Hc,key_ops:["verify"],x:n,y:o});throw new Ct(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ns(r){return pr([Rs(Uint8Array.from([1])),pr([Vc(r.crv)],160),pr([Ps(new nt(Uint8Array.from([4]),J(r.x??"","base64url"),J(r.y??"","base64url")))],161)]).subarray()}function Vc(r){if(r==="P-256")return Mc;if(r==="P-384")return Fc;if(r==="P-521")return Kc;throw new Ct(`Invalid curve ${r}`)}var ve=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ns(this.jwk)),this._raw}toMultihash(){return At.digest(Ae(this))}toCID(){return it.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 Ds(this.jwk,e,t)}};function Us(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function jc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function _e(r,...t){if(!jc(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 Os(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Us(r.outputLen),Us(r.blockLen)}function Ie(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ms(r,t){_e(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var oe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function mr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var sd=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";function Fs(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function $e(r){return typeof r=="string"&&(r=Fs(r)),_e(r),r}function On(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];_e(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 Be=class{clone(){return this._cloneInto()}};function gr(r){let t=n=>r().update($e(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function yr(r=32){if(oe&&typeof oe.getRandomValues=="function")return oe.getRandomValues(new Uint8Array(r));if(oe&&typeof oe.randomBytes=="function")return Uint8Array.from(oe.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Gc(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function Ks(r,t,e){return r&t^~r&e}function zs(r,t,e){return r&t^r&e^t&e}var Le=class extends Be{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=mr(this.buffer)}update(t){Ie(this);let{view:e,buffer:n,blockLen:o}=this;t=$e(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=mr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ie(this),Ms(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;Gc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=mr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var $c=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Zt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Wt=new Uint32Array(64),Mn=class extends Le{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:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)Wt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Wt[f-15],g=Wt[f-2],y=It(h,7)^It(h,18)^h>>>3,b=It(g,17)^It(g,19)^g>>>10;Wt[f]=b+Wt[f-7]+y+Wt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let h=It(a,6)^It(a,11)^It(a,25),g=l+h+Ks(a,c,u)+$c[f]+Wt[f]|0,b=(It(n,2)^It(n,13)^It(n,22))+zs(n,o,s)|0;l=u,u=c,c=a,a=i+g|0,i=s,s=o,o=n,n=g+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){Wt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Fn=gr(()=>new Mn);var br=BigInt(4294967295),Kn=BigInt(32);function qs(r,t=!1){return t?{h:Number(r&br),l:Number(r>>Kn&br)}:{h:Number(r>>Kn&br)|0,l:Number(r&br)|0}}function Zc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=qs(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var Wc=(r,t)=>BigInt(r>>>0)<<Kn|BigInt(t>>>0),Yc=(r,t,e)=>r>>>e,Xc=(r,t,e)=>r<<32-e|t>>>e,Qc=(r,t,e)=>r>>>e|t<<32-e,Jc=(r,t,e)=>r<<32-e|t>>>e,tu=(r,t,e)=>r<<64-e|t>>>e-32,eu=(r,t,e)=>r>>>e-32|t<<64-e,ru=(r,t)=>t,nu=(r,t)=>r,ou=(r,t,e)=>r<<e|t>>>32-e,su=(r,t,e)=>t<<e|r>>>32-e,iu=(r,t,e)=>t<<e-32|r>>>64-e,au=(r,t,e)=>r<<e-32|t>>>64-e;function cu(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var uu=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),fu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,lu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),hu=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,du=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),pu=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var mu={fromBig:qs,split:Zc,toBig:Wc,shrSH:Yc,shrSL:Xc,rotrSH:Qc,rotrSL:Jc,rotrBH:tu,rotrBL:eu,rotr32H:ru,rotr32L:nu,rotlSH:ou,rotlSL:su,rotlBH:iu,rotlBL:au,add:cu,add3L:uu,add3H:fu,add4L:lu,add4H:hu,add5H:pu,add5L:du},k=mu;var[gu,yu]=k.split(["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))),Yt=new Uint32Array(80),Xt=new Uint32Array(80),zn=class extends Le{constructor(t=64){super(128,t,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:h,Gh:g,Gl:y,Hh:b,Hl:d}=this;return[t,e,n,o,s,i,a,c,u,l,f,h,g,y,b,d]}set(t,e,n,o,s,i,a,c,u,l,f,h,g,y,b,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=g|0,this.Gl=y|0,this.Hh=b|0,this.Hl=d|0}process(t,e){for(let p=0;p<16;p++,e+=4)Yt[p]=t.getUint32(e),Xt[p]=t.getUint32(e+=4);for(let p=16;p<80;p++){let _=Yt[p-15]|0,P=Xt[p-15]|0,D=k.rotrSH(_,P,1)^k.rotrSH(_,P,8)^k.shrSH(_,P,7),B=k.rotrSL(_,P,1)^k.rotrSL(_,P,8)^k.shrSL(_,P,7),L=Yt[p-2]|0,T=Xt[p-2]|0,j=k.rotrSH(L,T,19)^k.rotrBH(L,T,61)^k.shrSH(L,T,6),K=k.rotrSL(L,T,19)^k.rotrBL(L,T,61)^k.shrSL(L,T,6),U=k.add4L(B,K,Xt[p-7],Xt[p-16]),rt=k.add4H(U,D,j,Yt[p-7],Yt[p-16]);Yt[p]=rt|0,Xt[p]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:h,Fh:g,Fl:y,Gh:b,Gl:d,Hh:x,Hl:v}=this;for(let p=0;p<80;p++){let _=k.rotrSH(f,h,14)^k.rotrSH(f,h,18)^k.rotrBH(f,h,41),P=k.rotrSL(f,h,14)^k.rotrSL(f,h,18)^k.rotrBL(f,h,41),D=f&g^~f&b,B=h&y^~h&d,L=k.add5L(v,P,B,yu[p],Xt[p]),T=k.add5H(L,x,_,D,gu[p],Yt[p]),j=L|0,K=k.rotrSH(n,o,28)^k.rotrBH(n,o,34)^k.rotrBH(n,o,39),U=k.rotrSL(n,o,28)^k.rotrBL(n,o,34)^k.rotrBL(n,o,39),rt=n&s^n&a^s&a,S=o&i^o&c^i&c;x=b|0,v=d|0,b=g|0,d=y|0,g=f|0,y=h|0,{h:f,l:h}=k.add(u|0,l|0,T|0,j|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=k.add3L(j,U,S);n=k.add3H(I,T,K,rt),o=I|0}({h:n,l:o}=k.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=k.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=k.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=k.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=k.add(this.Eh|0,this.El|0,f|0,h|0),{h:g,l:y}=k.add(this.Fh|0,this.Fl|0,g|0,y|0),{h:b,l:d}=k.add(this.Gh|0,this.Gl|0,b|0,d|0),{h:x,l:v}=k.add(this.Hh|0,this.Hl|0,x|0,v|0),this.set(n,o,s,i,a,c,u,l,f,h,g,y,b,d,x,v)}roundClean(){Yt.fill(0),Xt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var qn=gr(()=>new zn);var Gn=BigInt(0),jn=BigInt(1);function se(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function $n(r){if(!se(r))throw new Error("Uint8Array expected")}function Rt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Ze(r){let t=r.toString(16);return t.length&1?"0"+t:t}function js(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Gn:BigInt("0x"+r)}var Gs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",bu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Qt(r){if($n(r),Gs)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=bu[r[e]];return t}var Mt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Hs(r){if(r>=Mt._0&&r<=Mt._9)return r-Mt._0;if(r>=Mt.A&&r<=Mt.F)return r-(Mt.A-10);if(r>=Mt.a&&r<=Mt.f)return r-(Mt.a-10)}function We(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Gs)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=Hs(r.charCodeAt(s)),a=Hs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ft(r){return js(Qt(r))}function ie(r){return $n(r),js(Qt(Uint8Array.from(r).reverse()))}function ae(r,t){return We(r.toString(16).padStart(t*2,"0"))}function Te(r,t){return ae(r,t).reverse()}function X(r,t,e){let n;if(typeof t=="string")try{n=We(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(se(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function Jt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];$n(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Hn=r=>typeof r=="bigint"&&Gn<=r;function xr(r,t,e){return Hn(r)&&Hn(t)&&Hn(e)&&t<=r&&r<e}function wt(r,t,e,n){if(!xr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function $s(r){let t;for(t=0;r>Gn;r>>=jn,t+=1);return t}var ce=r=>(jn<<BigInt(r))-jn,Vn=r=>new Uint8Array(r),Vs=r=>Uint8Array.from(r);function Zs(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=Vn(r),o=Vn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=Vn(0))=>{o=a(Vs([0]),f),n=a(),f.length!==0&&(o=a(Vs([1]),f),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=a();let g=n.slice();h.push(g),f+=n.length}return Jt(...h)};return(f,h)=>{i(),c(f);let g;for(;!(g=h(u()));)c();return i(),g}}var xu={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"||se(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 Kt(r,t,e={}){let n=(o,s,i)=>{let a=xu[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};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 Re(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 ot=BigInt(0),W=BigInt(1),ue=BigInt(2),wu=BigInt(3),Zn=BigInt(4),Ws=BigInt(5),Ys=BigInt(8),Eu=BigInt(9),Su=BigInt(16);function V(r,t){let e=r%t;return e>=ot?e:t+e}function vu(r,t,e){if(t<ot)throw new Error("invalid exponent, negatives unsupported");if(e<=ot)throw new Error("invalid modulus");if(e===W)return ot;let n=W;for(;t>ot;)t&W&&(n=n*r%e),r=r*r%e,t>>=W;return n}function Y(r,t,e){let n=r;for(;t-- >ot;)n*=n,n%=e;return n}function wr(r,t){if(r===ot)throw new Error("invert: expected non-zero number");if(t<=ot)throw new Error("invert: expected positive modulus, got "+t);let e=V(r,t),n=t,o=ot,s=W,i=W,a=ot;for(;e!==ot;){let u=n/e,l=n%e,f=o-i*u,h=s-a*u;n=e,e=l,o=i,s=a,i=f,a=h}if(n!==W)throw new Error("invert: does not exist");return V(o,t)}function Au(r){let t=(r-W)/ue,e,n,o;for(e=r-W,n=0;e%ue===ot;e/=ue,n++);for(o=ue;o<r&&vu(o,t,r)!==r-W;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+W)/Zn;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let s=(e+W)/ue;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,o),e),f=a.pow(c,s),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let g=1;for(let b=a.sqr(h);g<u&&!a.eql(b,a.ONE);g++)b=a.sqr(b);let y=a.pow(l,W<<BigInt(u-g-1));l=a.sqr(y),f=a.mul(f,y),h=a.mul(h,l),u=g}return f}}function _u(r){if(r%Zn===wu){let t=(r+W)/Zn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%Ys===Ws){let t=(r-Ws)/Ys;return function(n,o){let s=n.mul(o,ue),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,ue),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%Su,Au(r)}var Xs=(r,t)=>(V(r,t)&W)===W,Iu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Iu.reduce((n,o)=>(n[o]="function",n),t);return Kt(r,e)}function Bu(r,t,e){if(e<ot)throw new Error("invalid exponent, negatives unsupported");if(e===ot)return r.ONE;if(e===W)return t;let n=r.ONE,o=t;for(;e>ot;)e&W&&(n=r.mul(n,o)),o=r.sqr(o),e>>=W;return n}function Lu(r,t){let e=new Array(t.length),n=t.reduce((s,i,a)=>r.is0(i)?s:(e[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,a)=>r.is0(i)?s:(e[a]=r.mul(s,e[a]),r.mul(s,i)),o),e}function Yn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function te(r,t,e=!1,n={}){if(r<=ot)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Yn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:ce(o),ZERO:ot,ONE:W,create:c=>V(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return ot<=c&&c<r},is0:c=>c===ot,isOdd:c=>(c&W)===W,neg:c=>V(-c,r),eql:(c,u)=>c===u,sqr:c=>V(c*c,r),add:(c,u)=>V(c+u,r),sub:(c,u)=>V(c-u,r),mul:(c,u)=>V(c*u,r),pow:(c,u)=>Bu(a,c,u),div:(c,u)=>V(c*wr(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>wr(c,r),sqrt:n.sqrt||(c=>(i||(i=_u(r)),i(a,c))),invertBatch:c=>Lu(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>e?Te(c,s):ae(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?ie(c):Ft(c)}});return Object.freeze(a)}function Qs(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 Xn(r){let t=Qs(r);return t+Math.ceil(t/2)}function Js(r,t,e=!1){let n=r.length,o=Qs(t),s=Xn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ie(r):Ft(r),a=V(i,t-W)+W;return e?Te(a,o):ae(a,o)}var ti=BigInt(0),ro=BigInt(1);function Qn(r,t){let e=t.negate();return r?e:t}function ri(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Jn(r,t){ri(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ce(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ei(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ro);let u=t*n,l=u+Math.abs(a)-1,f=a===0,h=a<0,g=t%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:h,isNegF:g,offsetF:u}}function Tu(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 Ru(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 to=new WeakMap,ni=new WeakMap;function eo(r){return ni.get(r)||1}function Er(r,t){return{constTimeNegate:Qn,hasPrecomputes(e){return eo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>ti;)n&ro&&(o=o.add(s)),s=s.double(),n>>=ro;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Jn(n,t),i=[],a=e,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let l=1;l<s;l++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=Jn(e,t);for(let c=0;c<a.windows;c++){let{nextN:u,offset:l,isZero:f,isNeg:h,isNegF:g,offsetF:y}=ei(o,c,a);o=u,f?i=i.add(Qn(g,n[y])):s=s.add(Qn(h,n[l]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Jn(e,t);for(let a=0;a<i.windows&&o!==ti;a++){let{nextN:c,offset:u,isZero:l,isNeg:f}=ei(o,a,i);if(o=c,!l){let h=n[u];s=s.add(f?h.negate():h)}}return s},getPrecomputes(e,n,o){let s=to.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&to.set(n,o(s))),s},wNAFCached(e,n,o){let s=eo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=eo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ri(n,t),ni.set(e,n),to.delete(e)}}}function Sr(r,t,e,n){if(Tu(e,r),Ru(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=$s(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=ce(i),c=new Array(Number(a)+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,l=o;for(let f=u;f>=0;f-=i){c.fill(o);for(let g=0;g<n.length;g++){let y=n[g],b=Number(y>>BigInt(f)&a);c[b]=c[b].add(e[g])}let h=o;for(let g=c.length-1,y=o;g>0;g--)y=y.add(c[g]),h=h.add(y);if(l=l.add(h),f!==0)for(let g=0;g<i;g++)l=l.double()}return l}function Ye(r){return Wn(r.Fp),Kt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Yn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Pt=BigInt(0),pt=BigInt(1),oi=BigInt(2),Pu=BigInt(8),Du={zip215:!0};function Cu(r){let t=Ye(r);return Kt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function si(r){let t=Cu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,u=oi<<BigInt(a*8)-pt,l=e.create,f=te(t.n,t.nBitLength),h=t.uvRatio||((w,m)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(m))}}catch{return{isValid:!1,value:Pt}}}),g=t.adjustScalarBytes||(w=>w),y=t.domain||((w,m,E)=>{if(Rt("phflag",E),m.length||E)throw new Error("Contexts/pre-hash are not supported");return w});function b(w,m,E=!1){let A=E?pt:Pt;wt("coordinate "+w,m,A,u)}function d(w){if(!(w instanceof p))throw new Error("ExtendedPoint expected")}let x=Re((w,m)=>{let{ex:E,ey:A,ez:C}=w,N=w.is0();m==null&&(m=N?Pu:e.inv(C));let O=l(E*m),M=l(A*m),F=l(C*m);if(N)return{x:Pt,y:pt};if(F!==pt)throw new Error("invZ was invalid");return{x:O,y:M}}),v=Re(w=>{let{a:m,d:E}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:A,ey:C,ez:N,et:O}=w,M=l(A*A),F=l(C*C),q=l(N*N),et=l(q*q),tt=l(M*m),ct=l(q*l(tt+F)),mt=l(et+l(E*l(M*F)));if(ct!==mt)throw new Error("bad point: equation left != right (1)");let st=l(A*C),ut=l(N*O);if(st!==ut)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(m,E,A,C){b("x",m),b("y",E),b("z",A,!0),b("t",C),this.ex=m,this.ey=E,this.ez=A,this.et=C,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:E,y:A}=m||{};return b("x",E),b("y",A),new p(E,A,pt,l(E*A))}static normalizeZ(m){let E=e.invertBatch(m.map(A=>A.ez));return m.map((A,C)=>A.toAffine(E[C])).map(p.fromAffine)}static msm(m,E){return Sr(p,f,m,E)}_setWindowSize(m){D.setWindowSize(this,m)}assertValidity(){v(this)}equals(m){d(m);let{ex:E,ey:A,ez:C}=this,{ex:N,ey:O,ez:M}=m,F=l(E*M),q=l(N*C),et=l(A*M),tt=l(O*C);return F===q&&et===tt}is0(){return this.equals(p.ZERO)}negate(){return new p(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:m}=t,{ex:E,ey:A,ez:C}=this,N=l(E*E),O=l(A*A),M=l(oi*l(C*C)),F=l(m*N),q=E+A,et=l(l(q*q)-N-O),tt=F+O,ct=tt-M,mt=F-O,st=l(et*ct),ut=l(tt*mt),yt=l(et*mt),vt=l(ct*tt);return new p(st,ut,vt,yt)}add(m){d(m);let{a:E,d:A}=t,{ex:C,ey:N,ez:O,et:M}=this,{ex:F,ey:q,ez:et,et:tt}=m,ct=l(C*F),mt=l(N*q),st=l(M*A*tt),ut=l(O*et),yt=l((C+N)*(F+q)-ct-mt),vt=ut-st,Oe=ut+st,ns=l(mt-E*ct),da=l(yt*vt),pa=l(Oe*ns),ma=l(yt*ns),ga=l(vt*Oe);return new p(da,pa,ga,ma)}subtract(m){return this.add(m.negate())}wNAF(m){return D.wNAFCached(this,m,p.normalizeZ)}multiply(m){let E=m;wt("scalar",E,pt,n);let{p:A,f:C}=this.wNAF(E);return p.normalizeZ([A,C])[0]}multiplyUnsafe(m,E=p.ZERO){let A=m;return wt("scalar",A,Pt,n),A===Pt?P:this.is0()||A===pt?this:D.wNAFCachedUnsafe(this,A,p.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(m){return x(this,m)}clearCofactor(){let{h:m}=t;return m===pt?this:this.multiplyUnsafe(m)}static fromHex(m,E=!1){let{d:A,a:C}=t,N=e.BYTES;m=X("pointHex",m,N),Rt("zip215",E);let O=m.slice(),M=m[N-1];O[N-1]=M&-129;let F=ie(O),q=E?u:e.ORDER;wt("pointHex.y",F,Pt,q);let et=l(F*F),tt=l(et-pt),ct=l(A*et-C),{isValid:mt,value:st}=h(tt,ct);if(!mt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(st&pt)===pt,yt=(M&128)!==0;if(!E&&st===Pt&&yt)throw new Error("Point.fromHex: x=0 and x_0=1");return yt!==ut&&(st=l(-st)),p.fromAffine({x:st,y:F})}static fromPrivateKey(m){let{scalar:E}=T(m);return _.multiply(E)}toRawBytes(){let{x:m,y:E}=this.toAffine(),A=Te(E,e.BYTES);return A[A.length-1]|=m&pt?128:0,A}toHex(){return Qt(this.toRawBytes())}}p.BASE=new p(t.Gx,t.Gy,pt,l(t.Gx*t.Gy)),p.ZERO=new p(Pt,pt,pt,Pt);let{BASE:_,ZERO:P}=p,D=Er(p,a*8);function B(w){return V(w,n)}function L(w){return B(ie(w))}function T(w){let m=e.BYTES;w=X("private key",w,m);let E=X("hashed private key",s(w),2*m),A=g(E.slice(0,m)),C=E.slice(m,2*m),N=L(A);return{head:A,prefix:C,scalar:N}}function j(w){let{head:m,prefix:E,scalar:A}=T(w),C=_.multiply(A),N=C.toRawBytes();return{head:m,prefix:E,scalar:A,point:C,pointBytes:N}}function K(w){return j(w).pointBytes}function U(w=new Uint8Array,...m){let E=Jt(...m);return L(s(y(E,X("context",w),!!o)))}function rt(w,m,E={}){w=X("message",w),o&&(w=o(w));let{prefix:A,scalar:C,pointBytes:N}=j(m),O=U(E.context,A,w),M=_.multiply(O).toRawBytes(),F=U(E.context,M,N,w),q=B(O+F*C);wt("signature.s",q,Pt,n);let et=Jt(M,Te(q,e.BYTES));return X("result",et,e.BYTES*2)}let S=Du;function I(w,m,E,A=S){let{context:C,zip215:N}=A,O=e.BYTES;w=X("signature",w,2*O),m=X("message",m),E=X("publicKey",E,O),N!==void 0&&Rt("zip215",N),o&&(m=o(m));let M=ie(w.slice(O,2*O)),F,q,et;try{F=p.fromHex(E,N),q=p.fromHex(w.slice(0,O),N),et=_.multiplyUnsafe(M)}catch{return!1}if(!N&&F.isSmallOrder())return!1;let tt=U(C,q.toRawBytes(),F.toRawBytes(),m);return q.add(F.multiplyUnsafe(tt)).subtract(et).clearCofactor().equals(p.ZERO)}return _._setWindowSize(8),{CURVE:t,getPublicKey:K,sign:rt,verify:I,ExtendedPoint:p,utils:{getExtendedPublicKey:j,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,m=p.BASE){return m._setWindowSize(w),m.multiply(BigInt(3)),m}}}}var no=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ii=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Kd=BigInt(0),ku=BigInt(1),ai=BigInt(2),zd=BigInt(3),Nu=BigInt(5),Uu=BigInt(8);function Ou(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=no,a=r*r%s*r%s,c=Y(a,ai,s)*a%s,u=Y(c,ku,s)*r%s,l=Y(u,Nu,s)*u%s,f=Y(l,t,s)*l%s,h=Y(f,e,s)*f%s,g=Y(h,n,s)*h%s,y=Y(g,o,s)*g%s,b=Y(y,o,s)*g%s,d=Y(b,t,s)*l%s;return{pow_p_5_8:Y(d,ai,s)*r%s,b2:a}}function Mu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Fu(r,t){let e=no,n=V(t*t*t,e),o=V(n*n*t,e),s=Ou(r*o).pow_p_5_8,i=V(r*n*s,e),a=V(t*i*i,e),c=i,u=V(i*ii,e),l=a===r,f=a===V(-r,e),h=a===V(-r*ii,e);return l&&(i=c),(f||h)&&(i=u),Xs(i,e)&&(i=V(-i,e)),{isValid:l||f,value:i}}var ci=te(no,void 0,!0),Ku={a:ci.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ci,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Uu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:qn,randomBytes:yr,adjustScalarBytes:Mu,uvRatio:Fu},ui=si(Ku);var vr=32;function fi(r,t,e){return ui.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Ar=class{type="Ed25519";raw;constructor(t){this.raw=oo(t,vr)}toMultihash(){return At.digest(Ae(this))}toCID(){return it.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 fi(this.raw,e,t)}};function hi(r){return r=oo(r,vr),new Ar(r)}function oo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Ct(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var qu=Math.pow(2,7),Hu=Math.pow(2,14),Vu=Math.pow(2,21),so=Math.pow(2,28),io=Math.pow(2,35),ao=Math.pow(2,42),co=Math.pow(2,49),z=128,ft=127;function lt(r){if(r<qu)return 1;if(r<Hu)return 2;if(r<Vu)return 3;if(r<so)return 4;if(r<io)return 5;if(r<ao)return 6;if(r<co)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function uo(r,t,e=0){switch(lt(r)){case 8:t[e++]=r&255|z,r/=128;case 7:t[e++]=r&255|z,r/=128;case 6:t[e++]=r&255|z,r/=128;case 5:t[e++]=r&255|z,r/=128;case 4:t[e++]=r&255|z,r>>>=7;case 3:t[e++]=r&255|z,r>>>=7;case 2:t[e++]=r&255|z,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ju(r,t,e=0){switch(lt(r)){case 8:t.set(e++,r&255|z),r/=128;case 7:t.set(e++,r&255|z),r/=128;case 6:t.set(e++,r&255|z),r/=128;case 5:t.set(e++,r&255|z),r/=128;case 4:t.set(e++,r&255|z),r>>>=7;case 3:t.set(e++,r&255|z),r>>>=7;case 2:t.set(e++,r&255|z),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function fo(r,t){let e=r[t],n=0;if(n+=e&ft,e<z||(e=r[t+1],n+=(e&ft)<<7,e<z)||(e=r[t+2],n+=(e&ft)<<14,e<z)||(e=r[t+3],n+=(e&ft)<<21,e<z)||(e=r[t+4],n+=(e&ft)*so,e<z)||(e=r[t+5],n+=(e&ft)*io,e<z)||(e=r[t+6],n+=(e&ft)*ao,e<z)||(e=r[t+7],n+=(e&ft)*co,e<z))return n;throw new RangeError("Could not decode varint")}function Gu(r,t){let e=r.get(t),n=0;if(n+=e&ft,e<z||(e=r.get(t+1),n+=(e&ft)<<7,e<z)||(e=r.get(t+2),n+=(e&ft)<<14,e<z)||(e=r.get(t+3),n+=(e&ft)<<21,e<z)||(e=r.get(t+4),n+=(e&ft)*so,e<z)||(e=r.get(t+5),n+=(e&ft)*io,e<z)||(e=r.get(t+6),n+=(e&ft)*ao,e<z)||(e=r.get(t+7),n+=(e&ft)*co,e<z))return n;throw new RangeError("Could not decode varint")}function ee(r,t,e=0){return t==null&&(t=gt(lt(r))),t instanceof Uint8Array?uo(r,t,e):ju(r,t,e)}function zt(r,t=0){return r instanceof Uint8Array?fo(r,t):Gu(r,t)}var ho=new Float32Array([-0]),re=new Uint8Array(ho.buffer);function di(r,t,e){ho[0]=r,t[e]=re[0],t[e+1]=re[1],t[e+2]=re[2],t[e+3]=re[3]}function pi(r,t){return re[0]=r[t],re[1]=r[t+1],re[2]=r[t+2],re[3]=r[t+3],ho[0]}var po=new Float64Array([-0]),ht=new Uint8Array(po.buffer);function mi(r,t,e){po[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 gi(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],po[0]}var $u=BigInt(Number.MAX_SAFE_INTEGER),Zu=BigInt(Number.MIN_SAFE_INTEGER),Et=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return fe;if(t<$u&&t>Zu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>yi&&(o=0n,++n>yi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return fe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):fe}},fe=new Et(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var yi=4294967296n;function bi(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 xi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function mo(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 Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function _r(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var go=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Bt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Bt(this,4);return _r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return _r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=pi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=gi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return xi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=_r(this.buf,this.pos+=4),e=_r(this.buf,this.pos+=4);return new Et(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=fo(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 yo(r){return new go(r instanceof Uint8Array?r:r.subarray())}function qt(r,t,e){let n=yo(r);return t.decode(n,void 0,e)}function bo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var le=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function xo(){}var Eo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Wu=bo();function Yu(r){return globalThis.Buffer!=null?gt(r):Wu(r)}var Qe=class{len;head;tail;states;constructor(){this.len=0,this.head=new le(xo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new le(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new So((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(Ir,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Ir,e.length(),e)}uint64Number(t){return this._push(uo,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=Et.fromBigInt(t).zzEncode();return this._push(Ir,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Ir,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(wo,1,t?1:0)}fixed32(t){return this._push(Xe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(Xe,4,e.lo)._push(Xe,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(Xe,4,e.lo)._push(Xe,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(di,4,t)}double(t){return this._push(mi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(wo,1,0):this.uint32(e)._push(Qu,e,t)}string(t){let e=bi(t);return e!==0?this.uint32(e)._push(mo,e,t):this._push(wo,1,0)}fork(){return this.states=new Eo(this),this.head=this.tail=new le(xo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new le(xo,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=Yu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function wo(r,t,e){t[e]=r&255}function Xu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var So=class extends le{next;constructor(t,e){super(Xu,t,e),this.next=void 0}};function Ir(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 Xe(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 Qu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Qe.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ju,t,r),this},Qe.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(tf,t,r),this});function Ju(r,t,e){t.set(r,e)}function tf(r,t,e){r.length<40?mo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(J(r),e)}function vo(){return new Qe}function Ht(r,t){let e=vo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Pe;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Pe||(Pe={}));function Br(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function De(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Br("enum",Pe.VARINT,e,n)}function Vt(r,t){return Br("message",Pe.LENGTH_DELIMITED,r,t)}var Lr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var St;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(St||(St={}));var Ao;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Ao||(Ao={}));(function(r){r.codec=()=>De(Ao)})(St||(St={}));var Je;(function(r){let t;r.codec=()=>(t==null&&(t=Vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),St.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=St.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Ht(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(Je||(Je={}));var _o;(function(r){let t;r.codec=()=>(t==null&&(t=Vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),St.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=St.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Ht(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(_o||(_o={}));var tr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Tr=class extends Be{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Os(t);let n=$e(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),s.fill(0)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(this),_e(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Io=(r,t,e)=>new Tr(r,t).update(e).digest();Io.create=(r,t)=>new Tr(r,t);function Ei(r){r.lowS!==void 0&&Rt("lowS",r.lowS),r.prehash!==void 0&&Rt("prehash",r.prehash)}function rf(r){let t=Ye(r);Kt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var Bo=class extends Error{constructor(t=""){super(t)}},jt={Err:Bo,_tlv:{encode:(r,t)=>{let{Err:e}=jt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Ze(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Ze(o.length/2|128):"";return Ze(r)+s+o+t},decode(r,t){let{Err:e}=jt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=jt;if(r<Gt)throw new t("integer: negative integers are not allowed");let e=Ze(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=jt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ft(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=jt,o=X("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=jt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Gt=BigInt(0),at=BigInt(1),j0=BigInt(2),Si=BigInt(3),G0=BigInt(4);function nf(r){let t=rf(r),{Fp:e}=t,n=te(t.n,t.nBitLength),o=t.toBytes||((b,d,x)=>{let v=d.toAffine();return Jt(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(b=>{let d=b.subarray(1),x=e.fromBytes(d.subarray(0,e.BYTES)),v=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x,y:v}});function i(b){let{a:d,b:x}=t,v=e.sqr(b),p=e.mul(v,b);return e.add(e.add(p,e.mul(b,d)),x)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return xr(b,at,t.n)}function c(b){let{allowedPrivateKeyLengths:d,nByteLength:x,wrapPrivateKey:v,n:p}=t;if(d&&typeof b!="bigint"){if(se(b)&&(b=Qt(b)),typeof b!="string"||!d.includes(b.length))throw new Error("invalid private key");b=b.padStart(x*2,"0")}let _;try{_=typeof b=="bigint"?b:Ft(X("private key",b,x))}catch{throw new Error("invalid private key, expected hex or "+x+" bytes, got "+typeof b)}return v&&(_=V(_,p)),wt("private key",_,at,p),_}function u(b){if(!(b instanceof h))throw new Error("ProjectivePoint expected")}let l=Re((b,d)=>{let{px:x,py:v,pz:p}=b;if(e.eql(p,e.ONE))return{x,y:v};let _=b.is0();d==null&&(d=_?e.ONE:e.inv(p));let P=e.mul(x,d),D=e.mul(v,d),B=e.mul(p,d);if(_)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:P,y:D}}),f=Re(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:d,y:x}=b.toAffine();if(!e.isValid(d)||!e.isValid(x))throw new Error("bad point: x or y not FE");let v=e.sqr(x),p=i(d);if(!e.eql(v,p))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,x,v){if(d==null||!e.isValid(d))throw new Error("x required");if(x==null||!e.isValid(x))throw new Error("y required");if(v==null||!e.isValid(v))throw new Error("z required");this.px=d,this.py=x,this.pz=v,Object.freeze(this)}static fromAffine(d){let{x,y:v}=d||{};if(!d||!e.isValid(x)||!e.isValid(v))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let p=_=>e.eql(_,e.ZERO);return p(x)&&p(v)?h.ZERO:new h(x,v,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let x=e.invertBatch(d.map(v=>v.pz));return d.map((v,p)=>v.toAffine(x[p])).map(h.fromAffine)}static fromHex(d){let x=h.fromAffine(s(X("pointHex",d)));return x.assertValidity(),x}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,x){return Sr(h,n,d,x)}_setWindowSize(d){y.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){u(d);let{px:x,py:v,pz:p}=this,{px:_,py:P,pz:D}=d,B=e.eql(e.mul(x,D),e.mul(_,p)),L=e.eql(e.mul(v,D),e.mul(P,p));return B&&L}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:x}=t,v=e.mul(x,Si),{px:p,py:_,pz:P}=this,D=e.ZERO,B=e.ZERO,L=e.ZERO,T=e.mul(p,p),j=e.mul(_,_),K=e.mul(P,P),U=e.mul(p,_);return U=e.add(U,U),L=e.mul(p,P),L=e.add(L,L),D=e.mul(d,L),B=e.mul(v,K),B=e.add(D,B),D=e.sub(j,B),B=e.add(j,B),B=e.mul(D,B),D=e.mul(U,D),L=e.mul(v,L),K=e.mul(d,K),U=e.sub(T,K),U=e.mul(d,U),U=e.add(U,L),L=e.add(T,T),T=e.add(L,T),T=e.add(T,K),T=e.mul(T,U),B=e.add(B,T),K=e.mul(_,P),K=e.add(K,K),T=e.mul(K,U),D=e.sub(D,T),L=e.mul(K,j),L=e.add(L,L),L=e.add(L,L),new h(D,B,L)}add(d){u(d);let{px:x,py:v,pz:p}=this,{px:_,py:P,pz:D}=d,B=e.ZERO,L=e.ZERO,T=e.ZERO,j=t.a,K=e.mul(t.b,Si),U=e.mul(x,_),rt=e.mul(v,P),S=e.mul(p,D),I=e.add(x,v),R=e.add(_,P);I=e.mul(I,R),R=e.add(U,rt),I=e.sub(I,R),R=e.add(x,p);let w=e.add(_,D);return R=e.mul(R,w),w=e.add(U,S),R=e.sub(R,w),w=e.add(v,p),B=e.add(P,D),w=e.mul(w,B),B=e.add(rt,S),w=e.sub(w,B),T=e.mul(j,R),B=e.mul(K,S),T=e.add(B,T),B=e.sub(rt,T),T=e.add(rt,T),L=e.mul(B,T),rt=e.add(U,U),rt=e.add(rt,U),S=e.mul(j,S),R=e.mul(K,R),rt=e.add(rt,S),S=e.sub(U,S),S=e.mul(j,S),R=e.add(R,S),U=e.mul(rt,R),L=e.add(L,U),U=e.mul(w,R),B=e.mul(I,B),B=e.sub(B,U),U=e.mul(I,rt),T=e.mul(w,T),T=e.add(T,U),new h(B,L,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return y.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:x,n:v}=t;wt("scalar",d,Gt,v);let p=h.ZERO;if(d===Gt)return p;if(this.is0()||d===at)return this;if(!x||y.hasPrecomputes(this))return y.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:_,k1:P,k2neg:D,k2:B}=x.splitScalar(d),L=p,T=p,j=this;for(;P>Gt||B>Gt;)P&at&&(L=L.add(j)),B&at&&(T=T.add(j)),j=j.double(),P>>=at,B>>=at;return _&&(L=L.negate()),D&&(T=T.negate()),T=new h(e.mul(T.px,x.beta),T.py,T.pz),L.add(T)}multiply(d){let{endo:x,n:v}=t;wt("scalar",d,at,v);let p,_;if(x){let{k1neg:P,k1:D,k2neg:B,k2:L}=x.splitScalar(d),{p:T,f:j}=this.wNAF(D),{p:K,f:U}=this.wNAF(L);T=y.constTimeNegate(P,T),K=y.constTimeNegate(B,K),K=new h(e.mul(K.px,x.beta),K.py,K.pz),p=T.add(K),_=j.add(U)}else{let{p:P,f:D}=this.wNAF(d);p=P,_=D}return h.normalizeZ([p,_])[0]}multiplyAndAddUnsafe(d,x,v){let p=h.BASE,_=(D,B)=>B===Gt||B===at||!D.equals(p)?D.multiplyUnsafe(B):D.multiply(B),P=_(this,x).add(_(d,v));return P.is0()?void 0:P}toAffine(d){return l(this,d)}isTorsionFree(){let{h:d,isTorsionFree:x}=t;if(d===at)return!0;if(x)return x(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:x}=t;return d===at?this:x?x(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Rt("isCompressed",d),this.assertValidity(),o(h,this,d)}toHex(d=!0){return Rt("isCompressed",d),Qt(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,y=Er(h,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function of(r){let t=Ye(r);return Kt(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}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(S){return V(S,n)}function a(S){return wr(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=nf({...t,toBytes(S,I,R){let w=I.toAffine(),m=e.toBytes(w.x),E=Jt;return Rt("isCompressed",R),R?E(Uint8Array.from([I.hasEvenY()?2:3]),m):E(Uint8Array.from([4]),m,e.toBytes(w.y))},fromBytes(S){let I=S.length,R=S[0],w=S.subarray(1);if(I===o&&(R===2||R===3)){let m=Ft(w);if(!xr(m,at,e.ORDER))throw new Error("Point is not on curve");let E=l(m),A;try{A=e.sqrt(E)}catch(O){let M=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+M)}let C=(A&at)===at;return(R&1)===1!==C&&(A=e.neg(A)),{x:m,y:A}}else if(I===s&&R===4){let m=e.fromBytes(w.subarray(0,e.BYTES)),E=e.fromBytes(w.subarray(e.BYTES,2*e.BYTES));return{x:m,y:E}}else{let m=o,E=s;throw new Error("invalid Point, expected length of "+m+", or uncompressed "+E+", got "+I)}}}),h=S=>Qt(ae(S,t.nByteLength));function g(S){let I=n>>at;return S>I}function y(S){return g(S)?i(-S):S}let b=(S,I,R)=>Ft(S.slice(I,R));class d{constructor(I,R,w){wt("r",I,at,n),wt("s",R,at,n),this.r=I,this.s=R,w!=null&&(this.recovery=w),Object.freeze(this)}static fromCompact(I){let R=t.nByteLength;return I=X("compactSignature",I,R*2),new d(b(I,0,R),b(I,R,2*R))}static fromDER(I){let{r:R,s:w}=jt.toSig(X("DER",I));return new d(R,w)}assertValidity(){}addRecoveryBit(I){return new d(this.r,this.s,I)}recoverPublicKey(I){let{r:R,s:w,recovery:m}=this,E=D(X("msgHash",I));if(m==null||![0,1,2,3].includes(m))throw new Error("recovery id invalid");let A=m===2||m===3?R+t.n:R;if(A>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let C=(m&1)===0?"02":"03",N=c.fromHex(C+h(A)),O=a(A),M=i(-E*O),F=i(w*O),q=c.BASE.multiplyAndAddUnsafe(N,M,F);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return We(this.toDERHex())}toDERHex(){return jt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return We(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let x={isValidPrivateKey(S){try{return u(S),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let S=Xn(t.n);return Js(t.randomBytes(S),t.n)},precompute(S=8,I=c.BASE){return I._setWindowSize(S),I.multiply(BigInt(3)),I}};function v(S,I=!0){return c.fromPrivateKey(S).toRawBytes(I)}function p(S){let I=se(S),R=typeof S=="string",w=(I||R)&&S.length;return I?w===o||w===s:R?w===2*o||w===2*s:S instanceof c}function _(S,I,R=!0){if(p(S))throw new Error("first arg must be private key");if(!p(I))throw new Error("second arg must be public key");return c.fromHex(I).multiply(u(S)).toRawBytes(R)}let P=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let I=Ft(S),R=S.length*8-t.nBitLength;return R>0?I>>BigInt(R):I},D=t.bits2int_modN||function(S){return i(P(S))},B=ce(t.nBitLength);function L(S){return wt("num < 2^"+t.nBitLength,S,Gt,B),ae(S,t.nByteLength)}function T(S,I,R=j){if(["recovered","canonical"].some(tt=>tt in R))throw new Error("sign() legacy options not supported");let{hash:w,randomBytes:m}=t,{lowS:E,prehash:A,extraEntropy:C}=R;E==null&&(E=!0),S=X("msgHash",S),Ei(R),A&&(S=X("prehashed msgHash",w(S)));let N=D(S),O=u(I),M=[L(O),L(N)];if(C!=null&&C!==!1){let tt=C===!0?m(e.BYTES):C;M.push(X("extraEntropy",tt))}let F=Jt(...M),q=N;function et(tt){let ct=P(tt);if(!f(ct))return;let mt=a(ct),st=c.BASE.multiply(ct).toAffine(),ut=i(st.x);if(ut===Gt)return;let yt=i(mt*i(q+ut*O));if(yt===Gt)return;let vt=(st.x===ut?0:2)|Number(st.y&at),Oe=yt;return E&&g(yt)&&(Oe=y(yt),vt^=1),new d(ut,Oe,vt)}return{seed:F,k2sig:et}}let j={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function U(S,I,R=j){let{seed:w,k2sig:m}=T(S,I,R),E=t;return Zs(E.hash.outputLen,E.nByteLength,E.hmac)(w,m)}c.BASE._setWindowSize(8);function rt(S,I,R,w=K){let m=S;I=X("msgHash",I),R=X("publicKey",R);let{lowS:E,prehash:A,format:C}=w;if(Ei(w),"strict"in w)throw new Error("options.strict was renamed to lowS");if(C!==void 0&&C!=="compact"&&C!=="der")throw new Error("format must be compact or der");let N=typeof m=="string"||se(m),O=!N&&!C&&typeof m=="object"&&m!==null&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!N&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let M,F;try{if(O&&(M=new d(m.r,m.s)),N){try{C!=="compact"&&(M=d.fromDER(m))}catch(vt){if(!(vt instanceof jt.Err))throw vt}!M&&C!=="der"&&(M=d.fromCompact(m))}F=c.fromHex(R)}catch{return!1}if(!M||E&&M.hasHighS())return!1;A&&(I=t.hash(I));let{r:q,s:et}=M,tt=D(I),ct=a(et),mt=i(tt*ct),st=i(q*ct),ut=c.BASE.multiplyAndAddUnsafe(F,mt,st)?.toAffine();return ut?i(ut.x)===q:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:_,sign:U,verify:rt,ProjectivePoint:c,Signature:d,utils:x}}function sf(r){return{hash:r,hmac:(t,...e)=>Io(r,t,On(...e)),randomBytes:yr}}function Ai(r,t){let e=n=>vi({...r,...sf(n)});return{...e(t),create:e}}var Bi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),_i=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),af=BigInt(1),Lo=BigInt(2),Ii=(r,t)=>(r+t/Lo)/t;function cf(r){let t=Bi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=Y(l,e,t)*l%t,h=Y(f,e,t)*l%t,g=Y(h,Lo,t)*u%t,y=Y(g,o,t)*g%t,b=Y(y,s,t)*y%t,d=Y(b,a,t)*b%t,x=Y(d,c,t)*d%t,v=Y(x,a,t)*b%t,p=Y(v,e,t)*l%t,_=Y(p,i,t)*y%t,P=Y(_,n,t)*u%t,D=Y(P,Lo,t);if(!To.eql(To.sqr(D),r))throw new Error("Cannot find square root");return D}var To=te(Bi,void 0,void 0,{sqrt:cf}),he=Ai({a:BigInt(0),b:BigInt(7),Fp:To,n:_i,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=_i,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-af*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Ii(s*r,t),c=Ii(-n*r,t),u=V(r-a*e-c*o,t),l=V(-a*n-c*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}}}},Fn),ep=BigInt(0);var rp=he.ProjectivePoint;function Li(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Ti(r,t,e){let n=He.digest(e instanceof Uint8Array?e:e.subarray());if(Li(n))return n.then(({digest:o})=>he.verify(t,o,r)).catch(o=>{throw new tr(String(o))});try{return he.verify(t,n.digest,r)}catch(o){throw new tr(String(o))}}var Rr=class{type="secp256k1";raw;_key;constructor(t){this._key=Pi(t),this.raw=Ri(this._key)}toMultihash(){return At.digest(Ae(this))}toCID(){return it.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 Ti(this._key,e,t)}};function Di(r){return new Rr(r)}function Ri(r){return he.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Pi(r){try{return he.ProjectivePoint.fromHex(r),r}catch(t){throw new cr(String(t))}}function Ci(r){let{Type:t,Data:e}=Je.decode(r.digest),n=e??new Uint8Array;switch(t){case St.Ed25519:return hi(n);case St.secp256k1:return Di(n);case St.ECDSA:return Cs(n);default:throw new Me}}function Ae(r){return Je.encode({Type:St[r.type],Data:r.raw})}var ki=Symbol.for("nodejs.util.inspect.custom"),uf=114,er=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()})`}[un]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return it.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")}[ki](){return`PeerId(${this.toString()})`}},Pr=class extends er{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dr=class extends er{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Cr=class extends er{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ff=2336,kr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(J(this.url))}[ki](){return`PeerId(${this.url})`}[un]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return it.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 Nr(r){if(hf(r))return new Pr({multihash:r});if(lf(r))try{let t=Ci(r);if(t.type==="Ed25519")return new Dr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Cr({multihash:r,publicKey:t})}catch{let e=G(r.digest);return new kr(new URL(e))}throw new ur("Supplied PeerID Multihash is invalid")}function lf(r){return r.code===At.code}function hf(r){return r.code===He.code}function Ro(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 Ur(r){let t=Ut($.decode(`z${r}`));return Nr(t)}var Or=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 Ro(this.set.entries(),t=>{let e=Ur(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Ur(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ro(this.set.values(),t=>Ur(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 Po(){return new Or}var Do={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ni={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ui=new globalThis.TextEncoder;function df(r,t){let e=Do[t],n=Ni[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=Do[t],o=Ni[t],s=r;for(;s.length>0;){let i=Ui.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function Co(r,{size:t=32,utf8Buffer:e}={}){if(!Do[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=Ui.encode(r)}return df(r,t)}var rr={hash:r=>Number(Co(r,{size:32})),hashV:(r,t)=>mf(rr.hash(r,t))};function mf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),J(t,"base16")}var ko=64,Lt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>ko)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=_t(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?dt(this.fp,t.fp):!1}};function de(r,t){return Math.floor(Math.random()*(t-r))+r}var pe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Lt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Lt))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 Lt))throw new TypeError("Invalid Fingerprint");let e=de(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Lt))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,nr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??rr,this.seed=t.seed??de(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=J(t));let e=new Lt(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 pe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new pe(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[de(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new pe(this.bucketSize));for(let a=0;a<gf;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new pe(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=J(t));let e=new Lt(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=J(t));let e=new Lt(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 bf(r=.001){return r>.002?2:r>1e-5?4:8}function Oi(r,t=.001){let e=bf(t),n=yf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),ko);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Mr=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??rr,this.seed=t.seed??de(0,Math.pow(2,10)),this.filterSeries=[new nr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=J(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new nr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=J(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=J(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 No(r,t=.001,e){return new Mr({...Oi(r,t),...e??{}})}var Fr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let 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&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Mi=45,xf=15,Ce=new Fr;function Kr(r){if(!(r.length>xf))return Ce.new(r).parseWith(()=>Ce.readIPv4Addr())}function zr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Mi))return Ce.new(r).parseWith(()=>Ce.readIPv6Addr())}function me(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Mi)return;let e=Ce.new(r).parseWith(()=>Ce.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 Fi(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 Ki(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 Uo(r){switch(r.length){case ge:return r.join(".");case ye:{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 zi(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 qi(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var ge=4,ye=16,jm=parseInt("0xFFFF",16),wf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function or(r,t){t.length===ye&&r.length===ge&&Fi(t,0,11)&&(t=t.slice(12)),t.length===ge&&r.length===ye&&Ki(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 Hi(r,t){if(typeof t=="string"&&(t=me(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Oo(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=ge,o=Kr(t);if(o==null&&(n=ye,o=zr(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=Mo(s,8*n);return{network:or(o,i),mask:i}}function Mo(r,t){if(t!==8*ge&&t!==8*ye)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 ke=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Oo(t));else{let n=me(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=me(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Mo(o,8*n.length);this.network=or(n,this.mask)}}contains(t){return Hi({network:this.network,mask:this.mask},t)}toString(){let t=zi(this.mask),e=t!==-1?String(t):qi(this.mask);return Uo(this.network)+"/"+e}};function Vi(r,t){return new ke(r).contains(t)}var Ef=41;function ji(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===Ef)return Vi("2000::/3",e)}catch{}return!1}function qr(r){return!!Kr(r)}function Hr(r){return!!zr(r)}function Vr(r){return!!me(r)}var $i=va(Gi(),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 $i.Netmask(r));function Fo(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 Fo(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 Fo(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 Zi(r){return qr(r)?Fo(r):Af(r)?_f(r):If(r)?Bf(r):Hr(r)?Lf(r):void 0}function Wi(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function Ko(r){try{if(!Wi(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:Zi(t)??!1}catch{}return!0}function Tt(){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}},Ne=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 zo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Yi(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 Ne,o,s,i,a=Tt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,x)=>{s=v=>{s=null,n.push(v);try{d(r(n))}catch(p){x(p)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Tt()})}},u=d=>s!=null?s(d):(n.push(d),o),l=d=>(n=new Ne,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:d})},h=d=>i?o:(i=!0,d!=null?l(d):u({done:!0})),g=()=>(n=new Ne,h(),{done:!0}),y=d=>(h(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:y,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let x=d?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let v,p;x!=null&&(v=new Promise((_,P)=>{p=()=>{P(new zo)},x.addEventListener("abort",p)}));try{await Promise.race([a.promise,v])}finally{p!=null&&x!=null&&x?.removeEventListener("abort",p)}}},e==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(d){return b.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return b.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return b.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return b.readableLength},onEmpty:d=>b.onEmpty(d)},o}var qo=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 Gr(r,t,e,n){let o=new qo(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",l),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),i(h);return}a(),s(f)},u=f=>{a(),i(f.detail)},l=()=>{a(),i(o)};e?.addEventListener("abort",l),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}var $r=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Zr=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 be(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Zr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Zr(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 Wr=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Tt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Dt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Pf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Yr=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 Dt),this.cleanup())}async join(t={}){let e=new Wr(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 be(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 Xr=class extends fr{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=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!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 $r;let n=new Yr(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 Dt)}),this.clear()}async onEmpty(t){this.size!==0&&await Gr(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await Gr(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Gr(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=Yi({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail)},i=()=>{n()},a=()=>{n(new Dt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var Qr=class extends Xr{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Jr(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 Xi(r,t,e){let n,o;function s(){let a={signal:o.signal};if(e?.timeout!=null){let c=Jr([o.signal,AbortSignal.timeout(e.timeout)]);a.signal=c}Promise.resolve().then(async()=>{await r(a)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{setInterval:a=>{t=a,n!=null&&(clearTimeout(n),n=setTimeout(s,t))},setTimeout:a=>{e==null&&(e={}),e.timeout=a},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 Qi=qr,Df=Hr,Ho=function(r){let t=0;if(r=r.toString().trim(),Qi(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=Qi(e[n]),i;s&&(i=Ho(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")},Ji=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 Ue={},Vo={},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=Nf(...r);Vo[t.code]=t,Ue[t.name]=t});function Nf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function H(r){if(typeof r=="number"){if(Vo[r]!=null)return Vo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ue[r]!=null)return Ue[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var sy=H("ip4"),iy=H("ip6"),ay=H("ipcidr");function Zo(r,t){switch(H(r).code){case 4:case 41:return Of(t);case 42:return $o(t);case 43:return G(t,"base10");case 6:case 273:case 33:case 132:return ra(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return $o(t);case 421:return zf(t);case 444:return ea(t);case 445:return ea(t);case 466:return Kf(t);case 481:return globalThis.encodeURIComponent($o(t));default:return G(t,"base16")}}function Wo(r,t){switch(H(r).code){case 4:return ta(t);case 41:return ta(t);case 42:return Go(t);case 43:return J(t,"base10");case 6:case 273:case 33:case 132:return Yo(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Go(t);case 421:return Mf(t);case 444:return qf(t);case 445:return Hf(t);case 466:return Ff(t);case 481:return Go(globalThis.decodeURIComponent(t));default:return J(t,"base16")}}var jo=Object.values(Ve).map(r=>r.decoder),Uf=function(){let r=jo[0].or(jo[1]);return jo.slice(2).forEach(t=>r=r.or(t)),r}();function ta(r){if(!Vr(r))throw new Error("invalid ip address");return Ho(r)}function Of(r){let t=Ji(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Vr(t))throw new Error("invalid ip address");return t}function Yo(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ra(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Go(r){let t=J(r),e=Uint8Array.from(ee(t.length));return xt([e,t],e.length+t.length)}function $o(r){let t=zt(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=Ut($.decode(`z${r}`)).bytes:t=it.parse(r).multihash.bytes;let e=Uint8Array.from(ee(t.length));return xt([e,t],e.length+t.length)}function Ff(r){let t=Uf.decode(r),e=Uint8Array.from(ee(t.length));return xt([e,t],e.length+t.length)}function Kf(r){let t=zt(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=zt(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=Nt.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=Yo(n);return xt([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=Nt.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=Yo(n);return xt([e,o],e.length+o.length)}function ea(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=G(t,"base32"),o=ra(e);return`${n}:${o}`}function na(r){r=Xo(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],a=H(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new tn("invalid address: "+r);if(a.path===!0){n=Xo(o.slice(s).join("/")),t.push([a.code,Wo(a.code,n)]),e.push([a.code,n]);break}let c=Wo(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Zo(a.code,c)])}return{string:oa(e),bytes:en(t),tuples:t,stringTuples:e,path:n}}function Qo(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=zt(r,o),i=lt(s),a=H(s),c=Vf(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let u=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw new tn("Invalid address Uint8Array: "+G(r,"base16"));t.push([s,u]);let l=Zo(s,u);if(e.push([s,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:oa(e),tuples:t,stringTuples:e,path:n}}function oa(r){let t=[];return r.map(e=>{let n=H(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Xo(t.join("/"))}function en(r){return xt(r.map(t=>{let e=H(t[0]),n=Uint8Array.from(ee(e.code));return t.length>1&&t[1]!=null&&(n=xt([n,t[1]])),n}))}function Vf(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=zt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+lt(e)}}function Xo(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var tn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var jf=Symbol.for("nodejs.util.inspect.custom"),ts=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Gf=[H("dns").code,H("dns4").code,H("dns6").code,H("dnsaddr").code],Jo=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},rn=class r{bytes;#t;#e;#r;#n;[ts]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Qo(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=na(t)}else if(ia(t))e=Qo(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=H("tcp"),a=H("udp"),c=H("ip4"),u=H("ip6"),l=H("dns6"),f=H("ip6zone");for(let[g,y]of this.stringTuples())g===f.code&&(s=`%${y??""}`),Gf.includes(g)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${y??""}${s}`,t=g===l.code?6:4),(g===i.code||g===a.code)&&(e=H(g).name==="tcp"?"tcp":"udp",o=parseInt(y??"")),(g===c.code||g===u.code)&&(e=H(g).name==="tcp"?"tcp":"udp",n=`${y??""}${s}`,t=g===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({},H(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>H(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(en(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ue.p2p.code&&t.push([n,o]),n===Ue["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(it.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=sa.get(e.name);if(n==null)throw new Jo(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>ir(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 sa=new Map;function ia(r){return!!r?.[ts]}function ir(r){return new rn(r)}var es=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Tt(),this.haveNext=Tt()}[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=Tt(),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=Tt(),await be(this.readNext.promise,e?.signal,e)}};function aa(){return new es}var nn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function ca(r,t){let e=aa();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new nt;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:c,value:u}=await be(n.next(),i?.signal);return c===!0?null:u}for(;o.byteLength<i.bytes;){let{value:c,done:u}=await be(n.next(),i?.signal);if(u===!0)throw new nn("unexpected end of input");o.append(c)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var on=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},sn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},an=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ua(r,t={}){let e=ca(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=lt(t.maxDataLength));let n=t?.lengthDecoder??zt,o=t?.lengthEncoder??ee;return{read:async i=>{let a=-1,c=new nt;for(;;){c.append(await e.read({...i,bytes:1}));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new on("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new an("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new sn("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new nt(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new nt(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function rs(r,t){let e=ua(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var fa="libp2p",la="autonat",ha="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=()=>De(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=()=>De(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let l;u.codec=()=>(l==null&&(l=Vt((f,h,g={})=>{if(g.lengthDelimited!==!1&&h.fork(),f.id!=null&&(h.uint32(10),h.bytes(f.id)),f.addrs!=null)for(let y of f.addrs)h.uint32(18),h.bytes(y);g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let y={addrs:[]},b=h==null?f.len:f.pos+h;for(;f.pos<b;){let d=f.uint32();switch(d>>>3){case 1:{y.id=f.bytes();break}case 2:{if(g.limits?.addrs!=null&&y.addrs.length===g.limits.addrs)throw new Lr('Decode error - map field "addrs" had too many elements');y.addrs.push(f.bytes());break}default:{f.skipType(d&7);break}}}return y})),l),u.encode=f=>Ht(f,u.codec()),u.decode=(f,h)=>qt(f,u.codec(),h)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let l;u.codec=()=>(l==null&&(l=Vt((f,h,g={})=>{g.lengthDelimited!==!1&&h.fork(),f.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(f.peer,h)),g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let y={},b=h==null?f.len:f.pos+h;for(;f.pos<b;){let d=f.uint32();switch(d>>>3){case 1:{y.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:g.limits?.peer});break}default:{f.skipType(d&7);break}}}return y})),l),u.encode=f=>Ht(f,u.codec()),u.decode=(f,h)=>qt(f,u.codec(),h)})(i=r.Dial||(r.Dial={}));let a;(function(u){let l;u.codec=()=>(l==null&&(l=Vt((f,h,g={})=>{g.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)),g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let y={},b=h==null?f.len:f.pos+h;for(;f.pos<b;){let d=f.uint32();switch(d>>>3){case 1:{y.status=r.ResponseStatus.codec().decode(f);break}case 2:{y.statusText=f.string();break}case 3:{y.addr=f.bytes();break}default:{f.skipType(d&7);break}}}return y})),l),u.encode=f=>Ht(f,u.codec()),u.decode=(f,h)=>qt(f,u.codec(),h)})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=Vt((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={},g=l==null?u.len:u.pos+l;for(;u.pos<g;){let y=u.uint32();switch(y>>>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(y&7);break}}}return h})),c),r.encode=u=>Ht(u,r.codec()),r.decode=(u,l)=>qt(u,r.codec(),l)})(Z||(Z={}));var Qf=4,Jf=8,cn=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??fa}/${la}/${ha}`,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=Xi(this.findRandomPeers.bind(this),6e4),this.addressFilter=No(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ss]=["@libp2p/autonat"];get[is](){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=Jr([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=rs(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,a=s.peer;if(a?.id==null)return this.log.error("PeerId missing from message"),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Ut(a.id);i=Nr(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 c=a.addrs.map(f=>ir(f)).filter(f=>{let h=f.toOptions();return Ko(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(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(f=>f.toString()).join(", "),i);let u="",l=c[0];for await(let f of c){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(H("p2p").code).bytes}}}catch(g){this.log.error("could not dial %p - %e",i,g),u=g.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||!ji(o.multiaddr))||Ko(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:Po(),queue:new Qr({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>i.toOptions().family===6),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %p to verify multiaddr %s",t.remotePeer,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=rs(i).pb(Z),[,c]=await Promise.all([a.write({type:Z.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==Z.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let u=c.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,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),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(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};function tl(r={}){return t=>new cn(t,r)}return Aa(el);})();
2
+ "use strict";var Libp2PAutonat=(()=>{var ka=Object.create;var pr=Object.defineProperty;var Ua=Object.getOwnPropertyDescriptor;var Na=Object.getOwnPropertyNames;var Oa=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var Fa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),xt=(r,t)=>{for(var e in t)pr(r,e,{get:t[e],enumerable:!0})},ls=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Na(t))!Ma.call(r,o)&&o!==e&&pr(r,o,{get:()=>t[o],enumerable:!(n=Ua(t,o))||n.enumerable});return r};var Ka=(r,t,e)=>(e=r!=null?ka(Oa(r)):{},ls(t||!r||!r.__esModule?pr(e,"default",{value:r,enumerable:!0}):e,r)),za=r=>ls(pr({},"__esModule",{value:!0}),r);var ua=Fa(hr=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,l,f,h;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[u,l,f,h].join(".")},i=function(c){var u,l,f,h,g,y;for(u=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}y=t(c),g=y[0],l=y[1],c=c.substring(l),u.push(g)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var u,l,f,h,g;for(h=0,u=10,l="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,u=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,u=8,l="7")),g=f;f<c.length;){if("0"<=c[f]&&c[f]<=l)h=h*u+(e(c[f])-n)>>>0;else if(u===16)if("a"<=c[f]&&c[f]<="f")h=h*u+(10+e(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*u+(10+e(c[f])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===g)throw new Error("empty octet");return[h,f]},r=function(){function c(u,l){var f,h,g,y;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(y=u.split("/",2),u=y[0],l=y[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(x){throw f=x,new Error("Invalid mask: "+l)}for(h=g=32;g>=0;h=--g)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(x){throw f=x,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,f,h;for(h=i(this.first),f=i(this.last),l=0;h<=f;)u(a(h),h,l),l++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),hr.ip2long=i,hr.long2ip=a,hr.Netmask=r}).call(hr)});var Xf={};xt(Xf,{autoNAT:()=>Yf});var gn=Symbol.for("@libp2p/peer-id");var Ct=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var kt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},mr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var gr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var qe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var yr=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 hs=Symbol.for("@libp2p/service-capabilities"),ds=Symbol.for("@libp2p/service-dependencies");var En={};xt(En,{base58btc:()=>G,base58flickr:()=>$a});var Al=new Uint8Array(0);function ps(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 Ut(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 ms(r){return new TextEncoder().encode(r)}function gs(r){return new TextDecoder().decode(r)}function qa(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var x=0,d=0,b=0,v=y.length;b!==v&&y[b]===0;)b++,x++;for(var p=(v-b)*l+1>>>0,_=new Uint8Array(p);b!==v;){for(var P=y[b],D=0,B=p-1;(P!==0||D<d)&&B!==-1;B--,D++)P+=256*_[B]>>>0,_[B]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");d=D,b++}for(var L=p-d;L!==p&&_[L]===0;)L++;for(var T=c.repeat(x);L<p;++L)T+=r.charAt(_[L]);return T}function h(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var x=0;if(y[x]!==" "){for(var d=0,b=0;y[x]===c;)d++,x++;for(var v=(y.length-x)*u+1>>>0,p=new Uint8Array(v);y[x];){var _=e[y.charCodeAt(x)];if(_===255)return;for(var P=0,D=v-1;(_!==0||P<b)&&D!==-1;D--,P++)_+=a*p[D]>>>0,p[D]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");b=P,x++}if(y[x]!==" "){for(var B=v-b;B!==v&&p[B]===0;)B++;for(var L=new Uint8Array(d+(v-B)),T=d;B!==v;)L[T++]=p[B++];return L}}}function g(y){var x=h(y);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:g}}var Ha=qa,Va=Ha,xs=Va;var yn=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")}},xn=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 bs(this,t)}},bn=class{decoders;constructor(t){this.decoders=t}or(t){return bs(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 bs(r,t){return new bn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var wn=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 yn(t,e,n),this.decoder=new xn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:r,prefix:t,encode:e,decode:n}){return new wn(r,t,e,n)}function Xt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=xs(e,r);return Ae({prefix:t,name:r,encode:n,decode:s=>Ut(o(s))})}function ja(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),a=0,c=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`);c=c<<e|f,a+=e,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ga(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ae({prefix:t,name:r,encode(o){return Ga(o,n,e)},decode(o){return ja(o,n,e,r)}})}var G=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$a=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Sn={};xt(Sn,{base32:()=>Nt,base32hex:()=>Xa,base32hexpad:()=>Ja,base32hexpadupper:()=>tc,base32hexupper:()=>Qa,base32pad:()=>Wa,base32padupper:()=>Ya,base32upper:()=>Za,base32z:()=>ec});var Nt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Za=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wa=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ya=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xa=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qa=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ja=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tc=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ec=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var vn={};xt(vn,{base36:()=>He,base36upper:()=>rc});var He=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rc=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nc=Ss,ws=128,oc=127,sc=~oc,ic=Math.pow(2,31);function Ss(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ic;)t[e++]=r&255|ws,r/=128;for(;r&sc;)t[e++]=r&255|ws,r>>>=7;return t[e]=r|0,Ss.bytes=e-n+1,t}var ac=An,cc=128,Es=127;function An(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw An.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Es)<<o:(i&Es)*Math.pow(2,o),o+=7}while(i>=cc);return An.bytes=s-n,e}var uc=Math.pow(2,7),fc=Math.pow(2,14),lc=Math.pow(2,21),hc=Math.pow(2,28),dc=Math.pow(2,35),pc=Math.pow(2,42),mc=Math.pow(2,49),gc=Math.pow(2,56),yc=Math.pow(2,63),xc=function(r){return r<uc?1:r<fc?2:r<lc?3:r<hc?4:r<dc?5:r<pc?6:r<mc?7:r<gc?8:r<yc?9:10},bc={encode:nc,decode:ac,encodingLength:xc},wc=bc,Ve=wc;function je(r,t=0){return[Ve.decode(r,t),Ve.decode.bytes]}function _e(r,t,e=0){return Ve.encode(r,t,e),t}function Ie(r){return Ve.encodingLength(r)}function se(r,t){let e=t.byteLength,n=Ie(r),o=n+Ie(e),s=new Uint8Array(o+e);return _e(r,s,0),_e(e,s,n),s.set(t,o),new Be(r,e,t,s)}function Ot(r){let t=Ut(r),[e,n]=je(t),[o,s]=je(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Be(e,o,i,t)}function vs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ps(r.bytes,e.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function As(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Sc(e,_n(r),t??G.encoder);default:return vc(e,_n(r),t??Nt.encoder)}}var _s=new WeakMap;function _n(r){let t=_s.get(r);if(t==null){let e=new Map;return _s.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!==Ge)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ac)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=se(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&vs(t.multihash,n.multihash)}toString(t){return As(this,t)}toJSON(){return{"/":As(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??Is(n,o,s.bytes))}else if(e[_c]===!0){let{version:n,multihash:o,code:s}=e,i=Ot(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!==Ge)throw new Error(`Version 0 CID must use dag-pb (code: ${Ge}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Is(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ge,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=Ut(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 Be(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]=je(t.subarray(e));return e+=h,f},o=n(),s=Ge;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=Ec(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 _n(s).set(n,t),s}};function Ec(r,t){switch(r[0]){case"Q":{let e=t??G;return[G.prefix,e.decode(`${G.prefix}${r}`)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case Nt.prefix:{let e=t??Nt;return[Nt.prefix,e.decode(r)]}case He.prefix:{let e=t??He;return[He.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 Sc(r,t,e){let{prefix:n}=e;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function vc(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 Ge=112,Ac=18;function Is(r,t,e){let n=Ie(r),o=n+Ie(t),s=new Uint8Array(o+e.byteLength);return _e(r,s,0),_e(t,s,n),s.set(e,o),s}var _c=Symbol.for("@ipld/js-cid/CID");var In={};xt(In,{identity:()=>At});var Bs=0,Ic="identity",Ls=Ut;function Bc(r){return se(Bs,Ls(r))}var At={code:Bs,name:Ic,encode:Ls,digest:Bc};function ht(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 _t(r=0){return new Uint8Array(r)}function gt(r=0){return new Uint8Array(r)}function bt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=gt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Rs=Symbol.for("@achingbrain/uint8arraylist");function Ts(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 br(r){return!!r?.[Rs]}var et=class r{bufs;length;[Rs]=!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(br(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(br(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=Ts(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ts(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(br(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 bt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:bt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!br(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let h=u;h>=0;h--){let g=this.get(f+h);if(n[h]!==g){l=Math.max(1,h-a[g]);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=gt(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=_t(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=_t(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=_t(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=gt(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=_t(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=_t(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=_t(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=_t(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=_t(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(!ht(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 Bn={};xt(Bn,{base10:()=>Lc});var Lc=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Ln={};xt(Ln,{base16:()=>Tc,base16upper:()=>Rc});var Tc=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Rc=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Tn={};xt(Tn,{base2:()=>Pc});var Pc=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Rn={};xt(Rn,{base256emoji:()=>Nc});var Ps=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}"),Dc=Ps.reduce((r,t,e)=>(r[e]=t,r),[]),Cc=Ps.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function kc(r){return r.reduce((t,e)=>(t+=Dc[e],t),"")}function Uc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Cc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Nc=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:kc,decode:Uc});var Pn={};xt(Pn,{base64:()=>Oc,base64pad:()=>Mc,base64url:()=>Fc,base64urlpad:()=>Kc});var Oc=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mc=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fc=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kc=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Dn={};xt(Dn,{base8:()=>zc});var zc=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Cn={};xt(Cn,{identity:()=>qc});var qc=Ae({prefix:"\0",name:"identity",encode:r=>gs(r),decode:r=>ms(r)});var ah=new TextEncoder,ch=new TextDecoder;var Nn={};xt(Nn,{sha256:()=>$e,sha512:()=>jc});function Un({name:r,code:t,encode:e}){return new kn(r,t,e)}var kn=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?se(this.code,e):e.then(n=>se(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Cs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var $e=Un({name:"sha2-256",code:18,encode:Cs("SHA-256")}),jc=Un({name:"sha2-512",code:19,encode:Cs("SHA-512")});var Ze={...Cn,...Tn,...Dn,...Bn,...Ln,...Sn,...vn,...En,...Pn,...Rn},wh={...Nn,...In};function Us(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ks=Us("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),On=Us("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=gt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Gc={utf8:ks,"utf-8":ks,hex:Ze.base16,latin1:On,ascii:On,binary:On,...Ze},wr=Gc;function X(r,t="utf8"){let e=wr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function j(r,t="utf8"){let e=wr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var $c=parseInt("11111",2),Mn=parseInt("10000000",2),Zc=parseInt("01111111",2),Ns={0:We,1:We,2:Wc,3:Qc,4:Jc,5:Xc,6:Yc,16:We,22:We,48:We};function Fn(r,t={offset:0}){let e=r[t.offset]&$c;if(t.offset++,Ns[e]!=null)return Ns[e](r,t);throw new Error("No decoder for tag "+e)}function Ye(r,t){let e=0;if((r[t.offset]&Mn)===Mn){let n=r[t.offset]&Zc,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 We(r,t){Ye(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Fn(r,t);if(n===null)break;e.push(n)}return e}function Wc(r,t){let e=Ye(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Yc(r,t){let e=Ye(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Xc(r,t){return t.offset++,null}function Qc(r,t){let e=Ye(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Jc(r,t){let e=Ye(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function tu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new et;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Kn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=tu(r.byteLength);return new et(Uint8Array.from([t.byteLength|Mn]),t)}function Os(r){let t=new et,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new et(Uint8Array.from([2]),Kn(t),t)}function Ms(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),Kn(e),e)}function Er(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),Kn(e),e)}async function Fs(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 eu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ru=Uint8Array.from([6,5,43,129,4,0,34]),nu=Uint8Array.from([6,5,43,129,4,0,35]),ou={ext:!0,kty:"EC",crv:"P-256"},su={ext:!0,kty:"EC",crv:"P-384"},iu={ext:!0,kty:"EC",crv:"P-521"},zn=32,qn=48,Hn=66;function Ks(r){let t=Fn(r);return zs(t)}function zs(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===zn*2+1)return n=j(t.subarray(e,e+zn),"base64url"),o=j(t.subarray(e+zn),"base64url"),new Le({...ou,key_ops:["verify"],x:n,y:o});if(t.byteLength===qn*2+1)return n=j(t.subarray(e,e+qn),"base64url"),o=j(t.subarray(e+qn),"base64url"),new Le({...su,key_ops:["verify"],x:n,y:o});if(t.byteLength===Hn*2+1)return n=j(t.subarray(e,e+Hn),"base64url"),o=j(t.subarray(e+Hn),"base64url"),new Le({...iu,key_ops:["verify"],x:n,y:o});throw new kt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function qs(r){return Er([Os(Uint8Array.from([1])),Er([au(r.crv)],160),Er([Ms(new et(Uint8Array.from([4]),X(r.x??"","base64url"),X(r.y??"","base64url")))],161)]).subarray()}function au(r){if(r==="P-256")return eu;if(r==="P-384")return ru;if(r==="P-521")return nu;throw new kt(`Invalid curve ${r}`)}var Le=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=qs(this.jwk)),this._raw}toMultihash(){return At.digest(Te(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}async verify(t,e){return Fs(this.jwk,e,t)}};var ie=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function cu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Sr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ae(r,...t){if(!cu(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 Hs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Sr(r.outputLen),Sr(r.blockLen)}function Pe(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 Vs(r,t){ae(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Ft(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function vr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}function js(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Xe(r){return typeof r=="string"&&(r=js(r)),ae(r),r}function Vn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ae(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 Re=class{};function jn(r){let t=n=>r().update(Xe(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ar(r=32){if(ie&&typeof ie.getRandomValues=="function")return ie.getRandomValues(new Uint8Array(r));if(ie&&typeof ie.randomBytes=="function")return Uint8Array.from(ie.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function uu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function Gs(r,t,e){return r&t^~r&e}function $s(r,t,e){return r&t^r&e^t&e}var Qe=class extends Re{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=vr(this.buffer)}update(t){Pe(this),t=Xe(t),ae(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=vr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Pe(this),Vs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Ft(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;uu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=vr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Kt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var _r=BigInt(4294967295),Zs=BigInt(32);function fu(r,t=!1){return t?{h:Number(r&_r),l:Number(r>>Zs&_r)}:{h:Number(r>>Zs&_r)|0,l:Number(r&_r)|0}}function Ws(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=fu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Gn=(r,t,e)=>r>>>e,$n=(r,t,e)=>r<<32-e|t>>>e,ce=(r,t,e)=>r>>>e|t<<32-e,ue=(r,t,e)=>r<<32-e|t>>>e,Je=(r,t,e)=>r<<64-e|t>>>e-32,tr=(r,t,e)=>r>>>e-32|t<<64-e;function Rt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ys=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Xs=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Qs=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Js=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ti=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ei=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var hu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Qt=new Uint32Array(64),Zn=class extends Qe{constructor(t=32){super(64,t,8,!1),this.A=Kt[0]|0,this.B=Kt[1]|0,this.C=Kt[2]|0,this.D=Kt[3]|0,this.E=Kt[4]|0,this.F=Kt[5]|0,this.G=Kt[6]|0,this.H=Kt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)Qt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Qt[f-15],g=Qt[f-2],y=It(h,7)^It(h,18)^h>>>3,x=It(g,17)^It(g,19)^g>>>10;Qt[f]=x+Qt[f-7]+y+Qt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let h=It(a,6)^It(a,11)^It(a,25),g=l+h+Gs(a,c,u)+hu[f]+Qt[f]|0,x=(It(n,2)^It(n,13)^It(n,22))+$s(n,o,s)|0;l=u,u=c,c=a,a=i+g|0,i=s,s=o,o=n,n=g+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){Ft(Qt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ft(this.buffer)}};var ri=Ws(["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))),du=ri[0],pu=ri[1],Jt=new Uint32Array(80),te=new Uint32Array(80),Wn=class extends Qe{constructor(t=64){super(128,t,16,!1),this.Ah=at[0]|0,this.Al=at[1]|0,this.Bh=at[2]|0,this.Bl=at[3]|0,this.Ch=at[4]|0,this.Cl=at[5]|0,this.Dh=at[6]|0,this.Dl=at[7]|0,this.Eh=at[8]|0,this.El=at[9]|0,this.Fh=at[10]|0,this.Fl=at[11]|0,this.Gh=at[12]|0,this.Gl=at[13]|0,this.Hh=at[14]|0,this.Hl=at[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:h,Gh:g,Gl:y,Hh:x,Hl:d}=this;return[t,e,n,o,s,i,a,c,u,l,f,h,g,y,x,d]}set(t,e,n,o,s,i,a,c,u,l,f,h,g,y,x,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=g|0,this.Gl=y|0,this.Hh=x|0,this.Hl=d|0}process(t,e){for(let p=0;p<16;p++,e+=4)Jt[p]=t.getUint32(e),te[p]=t.getUint32(e+=4);for(let p=16;p<80;p++){let _=Jt[p-15]|0,P=te[p-15]|0,D=ce(_,P,1)^ce(_,P,8)^Gn(_,P,7),B=ue(_,P,1)^ue(_,P,8)^$n(_,P,7),L=Jt[p-2]|0,T=te[p-2]|0,V=ce(L,T,19)^Je(L,T,61)^Gn(L,T,6),F=ue(L,T,19)^tr(L,T,61)^$n(L,T,6),U=Qs(B,F,te[p-7],te[p-16]),tt=Js(U,D,V,Jt[p-7],Jt[p-16]);Jt[p]=tt|0,te[p]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:h,Fh:g,Fl:y,Gh:x,Gl:d,Hh:b,Hl:v}=this;for(let p=0;p<80;p++){let _=ce(f,h,14)^ce(f,h,18)^Je(f,h,41),P=ue(f,h,14)^ue(f,h,18)^tr(f,h,41),D=f&g^~f&x,B=h&y^~h&d,L=ti(v,P,B,pu[p],te[p]),T=ei(L,b,_,D,du[p],Jt[p]),V=L|0,F=ce(n,o,28)^Je(n,o,34)^Je(n,o,39),U=ue(n,o,28)^tr(n,o,34)^tr(n,o,39),tt=n&s^n&a^s&a,S=o&i^o&c^i&c;b=x|0,v=d|0,x=g|0,d=y|0,g=f|0,y=h|0,{h:f,l:h}=Rt(u|0,l|0,T|0,V|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=Ys(V,U,S);n=Xs(I,T,F,tt),o=I|0}({h:n,l:o}=Rt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Rt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Rt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Rt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=Rt(this.Eh|0,this.El|0,f|0,h|0),{h:g,l:y}=Rt(this.Fh|0,this.Fl|0,g|0,y|0),{h:x,l:d}=Rt(this.Gh|0,this.Gl|0,x|0,d|0),{h:b,l:v}=Rt(this.Hh|0,this.Hl|0,b|0,v|0),this.set(n,o,s,i,a,c,u,l,f,h,g,y,x,d,b,v)}roundClean(){Ft(Jt,te)}destroy(){Ft(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ni=jn(()=>new Zn);var oi=jn(()=>new Wn);var Jn=BigInt(0),Qn=BigInt(1);function fe(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function to(r){if(!fe(r))throw new Error("Uint8Array expected")}function Pt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function er(r){let t=r.toString(16);return t.length&1?"0"+t:t}function ai(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Jn:BigInt("0x"+r)}var ci=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",mu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ee(r){if(to(r),ci)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=mu[r[e]];return t}var zt={_0:48,_9:57,A:65,F:70,a:97,f:102};function si(r){if(r>=zt._0&&r<=zt._9)return r-zt._0;if(r>=zt.A&&r<=zt.F)return r-(zt.A-10);if(r>=zt.a&&r<=zt.f)return r-(zt.a-10)}function rr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ci)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=si(r.charCodeAt(s)),a=si(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function qt(r){return ai(ee(r))}function le(r){return to(r),ai(ee(Uint8Array.from(r).reverse()))}function he(r,t){return rr(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=rr(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(fe(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 re(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];to(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 Yn=r=>typeof r=="bigint"&&Jn<=r;function Ir(r,t,e){return Yn(r)&&Yn(t)&&Yn(e)&&t<=r&&r<e}function wt(r,t,e,n){if(!Ir(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ui(r){let t;for(t=0;r>Jn;r>>=Qn,t+=1);return t}var de=r=>(Qn<<BigInt(r))-Qn,Xn=r=>new Uint8Array(r),ii=r=>Uint8Array.from(r);function fi(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=Xn(r),o=Xn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=Xn(0))=>{o=a(ii([0]),f),n=a(),f.length!==0&&(o=a(ii([1]),f),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=a();let g=n.slice();h.push(g),f+=n.length}return re(...h)};return(f,h)=>{i(),c(f);let g;for(;!(g=h(u()));)c();return i(),g}}var gu={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"||fe(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 Ht(r,t,e={}){let n=(o,s,i)=>{let a=gu[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};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 dt=BigInt(0),rt=BigInt(1),pe=BigInt(2),yu=BigInt(3),eo=BigInt(4),li=BigInt(5),hi=BigInt(8),xu=BigInt(9),bu=BigInt(16);function H(r,t){let e=r%t;return e>=dt?e:t+e}function Z(r,t,e){let n=r;for(;t-- >dt;)n*=n,n%=e;return n}function Br(r,t){if(r===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let e=H(r,t),n=t,o=dt,s=rt,i=rt,a=dt;for(;e!==dt;){let u=n/e,l=n%e,f=o-i*u,h=s-a*u;n=e,e=l,o=i,s=a,i=f,a=h}if(n!==rt)throw new Error("invert: does not exist");return H(o,t)}function wu(r){let t=r-rt,e=0;for(;t%pe===dt;)t/=pe,e++;let n=pe,o=Vt(r);for(;n<r&&di(o,n);)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1){let i=(r+rt)/eo;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let s=(t+rt)/pe;return function(a,c){if(!di(a,c))throw new Error("Cannot find square root");let u=e,l=a.pow(a.mul(a.ONE,n),t),f=a.pow(c,s),h=a.pow(c,t);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let g=1;for(let x=a.sqr(h);g<u&&!a.eql(x,a.ONE);g++)x=a.sqr(x);let y=a.pow(l,rt<<BigInt(u-g-1));l=a.sqr(y),f=a.mul(f,y),h=a.mul(h,l),u=g}return f}}function Eu(r){return r%eo===yu?function(e,n){let o=(r+rt)/eo,s=e.pow(n,o);if(!e.eql(e.sqr(s),n))throw new Error("Cannot find square root");return s}:r%hi===li?function(e,n){let o=e.mul(n,pe),s=(r-li)/hi,i=e.pow(o,s),a=e.mul(n,i),c=e.mul(e.mul(a,pe),i),u=e.mul(a,e.sub(c,e.ONE));if(!e.eql(e.sqr(u),n))throw new Error("Cannot find square root");return u}:(r%bu,wu(r))}var pi=(r,t)=>(H(r,t)&rt)===rt,Su=["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=Su.reduce((n,o)=>(n[o]="function",n),t);return Ht(r,e)}function vu(r,t,e){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(e===dt)return r.ONE;if(e===rt)return t;let n=r.ONE,o=t;for(;e>dt;)e&rt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=rt;return n}function ke(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Au(r,t){let e=(r.ORDER-rt)/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("Cannot find square root: probably non-prime P");return o?1:s?0:-1}function di(r,t){let e=Au(r,t);return e===0||e===1}function no(r,t){t!==void 0&&Sr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Vt(r,t,e=!1,n={}){if(r<=dt)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,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:de(o),ZERO:dt,ONE:rt,create:c=>H(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return dt<=c&&c<r},is0:c=>c===dt,isOdd:c=>(c&rt)===rt,neg:c=>H(-c,r),eql:(c,u)=>c===u,sqr:c=>H(c*c,r),add:(c,u)=>H(c+u,r),sub:(c,u)=>H(c-u,r),mul:(c,u)=>H(c*u,r),pow:(c,u)=>vu(a,c,u),div:(c,u)=>H(c*Br(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Br(c,r),sqrt:n.sqrt||(c=>(i||(i=Eu(r)),i(a,c))),toBytes:c=>e?De(c,s):he(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?le(c):qt(c)},invertBatch:c=>ke(a,c),cmov:(c,u,l)=>l?u:c});return Object.freeze(a)}function mi(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=mi(r);return t+Math.ceil(t/2)}function gi(r,t,e=!1){let n=r.length,o=mi(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):qt(r),a=H(i,t-rt)+rt;return e?De(a,o):he(a,o)}var yi=BigInt(0),uo=BigInt(1);function so(r,t){let e=t.negate();return r?e:t}function bi(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){bi(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 xi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=uo);let u=t*n,l=u+Math.abs(a)-1,f=a===0,h=a<0,g=t%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:h,isNegF:g,offsetF:u}}function _u(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 Iu(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,wi=new WeakMap;function co(r){return wi.get(r)||1}function Lr(r,t){return{constTimeNegate:so,hasPrecomputes(e){return co(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>yi;)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=[],a=e,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let l=1;l<s;l++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=io(e,t);for(let c=0;c<a.windows;c++){let{nextN:u,offset:l,isZero:f,isNeg:h,isNegF:g,offsetF:y}=xi(o,c,a);o=u,f?i=i.add(so(g,n[y])):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 a=0;a<i.windows&&o!==yi;a++){let{nextN:c,offset:u,isZero:l,isNeg:f}=xi(o,a,i);if(o=c,!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){bi(n,t),wi.set(e,n),ao.delete(e)}}}function Tr(r,t,e,n){if(_u(e,r),Iu(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=ui(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=de(i),c=new Array(Number(a)+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,l=o;for(let f=u;f>=0;f-=i){c.fill(o);for(let g=0;g<n.length;g++){let y=n[g],x=Number(y>>BigInt(f)&a);c[x]=c[x].add(e[g])}let h=o;for(let g=c.length-1,y=o;g>0;g--)y=y.add(c[g]),h=h.add(y);if(l=l.add(h),f!==0)for(let g=0;g<i;g++)l=l.double()}return l}function nr(r){return ro(r.Fp),Ht(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 Dt=BigInt(0),pt=BigInt(1),Ei=BigInt(2),Bu=BigInt(8),Lu={zip215:!0};function Tu(r){let t=nr(r);return Ht(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Si(r){let t=Tu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,u=Ei<<BigInt(a*8)-pt,l=e.create,f=Vt(t.n,t.nBitLength),h=t.uvRatio||((w,m)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(m))}}catch{return{isValid:!1,value:Dt}}}),g=t.adjustScalarBytes||(w=>w),y=t.domain||((w,m,E)=>{if(Pt("phflag",E),m.length||E)throw new Error("Contexts/pre-hash are not supported");return w});function x(w,m,E=!1){let A=E?pt:Dt;wt("coordinate "+w,m,A,u)}function d(w){if(!(w instanceof p))throw new Error("ExtendedPoint expected")}let b=Ce((w,m)=>{let{ex:E,ey:A,ez:C}=w,k=w.is0();m==null&&(m=k?Bu:e.inv(C));let N=l(E*m),O=l(A*m),M=l(C*m);if(k)return{x:Dt,y:pt};if(M!==pt)throw new Error("invZ was invalid");return{x:N,y:O}}),v=Ce(w=>{let{a:m,d:E}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:A,ey:C,ez:k,et:N}=w,O=l(A*A),M=l(C*C),z=l(k*k),J=l(z*z),Q=l(O*m),it=l(z*l(Q+M)),mt=l(J+l(E*l(O*M)));if(it!==mt)throw new Error("bad point: equation left != right (1)");let nt=l(A*C),ct=l(k*N);if(nt!==ct)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(m,E,A,C){x("x",m),x("y",E),x("z",A,!0),x("t",C),this.ex=m,this.ey=E,this.ez=A,this.et=C,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:E,y:A}=m||{};return x("x",E),x("y",A),new p(E,A,pt,l(E*A))}static normalizeZ(m){let E=ke(e,m.map(A=>A.ez));return m.map((A,C)=>A.toAffine(E[C])).map(p.fromAffine)}static msm(m,E){return Tr(p,f,m,E)}_setWindowSize(m){D.setWindowSize(this,m)}assertValidity(){v(this)}equals(m){d(m);let{ex:E,ey:A,ez:C}=this,{ex:k,ey:N,ez:O}=m,M=l(E*O),z=l(k*C),J=l(A*O),Q=l(N*C);return M===z&&J===Q}is0(){return this.equals(p.ZERO)}negate(){return new p(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:m}=t,{ex:E,ey:A,ez:C}=this,k=l(E*E),N=l(A*A),O=l(Ei*l(C*C)),M=l(m*k),z=E+A,J=l(l(z*z)-k-N),Q=M+N,it=Q-O,mt=M-N,nt=l(J*it),ct=l(Q*mt),yt=l(J*mt),vt=l(it*Q);return new p(nt,ct,vt,yt)}add(m){d(m);let{a:E,d:A}=t,{ex:C,ey:k,ez:N,et:O}=this,{ex:M,ey:z,ez:J,et:Q}=m,it=l(C*M),mt=l(k*z),nt=l(O*A*Q),ct=l(N*J),yt=l((C+k)*(M+z)-it-mt),vt=ct-nt,ze=ct+nt,fs=l(mt-E*it),Ra=l(yt*vt),Pa=l(ze*fs),Da=l(yt*fs),Ca=l(vt*ze);return new p(Ra,Pa,Ca,Da)}subtract(m){return this.add(m.negate())}wNAF(m){return D.wNAFCached(this,m,p.normalizeZ)}multiply(m){let E=m;wt("scalar",E,pt,n);let{p:A,f:C}=this.wNAF(E);return p.normalizeZ([A,C])[0]}multiplyUnsafe(m,E=p.ZERO){let A=m;return wt("scalar",A,Dt,n),A===Dt?P:this.is0()||A===pt?this:D.wNAFCachedUnsafe(this,A,p.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(m){return b(this,m)}clearCofactor(){let{h:m}=t;return m===pt?this:this.multiplyUnsafe(m)}static fromHex(m,E=!1){let{d:A,a:C}=t,k=e.BYTES;m=W("pointHex",m,k),Pt("zip215",E);let N=m.slice(),O=m[k-1];N[k-1]=O&-129;let M=le(N),z=E?u:e.ORDER;wt("pointHex.y",M,Dt,z);let J=l(M*M),Q=l(J-pt),it=l(A*J-C),{isValid:mt,value:nt}=h(Q,it);if(!mt)throw new Error("Point.fromHex: invalid y coordinate");let ct=(nt&pt)===pt,yt=(O&128)!==0;if(!E&&nt===Dt&&yt)throw new Error("Point.fromHex: x=0 and x_0=1");return yt!==ct&&(nt=l(-nt)),p.fromAffine({x:nt,y:M})}static fromPrivateKey(m){let{scalar:E}=T(m);return _.multiply(E)}toRawBytes(){let{x:m,y:E}=this.toAffine(),A=De(E,e.BYTES);return A[A.length-1]|=m&pt?128:0,A}toHex(){return ee(this.toRawBytes())}}p.BASE=new p(t.Gx,t.Gy,pt,l(t.Gx*t.Gy)),p.ZERO=new p(Dt,pt,pt,Dt);let{BASE:_,ZERO:P}=p,D=Lr(p,a*8);function B(w){return H(w,n)}function L(w){return B(le(w))}function T(w){let m=e.BYTES;w=W("private key",w,m);let E=W("hashed private key",s(w),2*m),A=g(E.slice(0,m)),C=E.slice(m,2*m),k=L(A);return{head:A,prefix:C,scalar:k}}function V(w){let{head:m,prefix:E,scalar:A}=T(w),C=_.multiply(A),k=C.toRawBytes();return{head:m,prefix:E,scalar:A,point:C,pointBytes:k}}function F(w){return V(w).pointBytes}function U(w=Uint8Array.of(),...m){let E=re(...m);return L(s(y(E,W("context",w),!!o)))}function tt(w,m,E={}){w=W("message",w),o&&(w=o(w));let{prefix:A,scalar:C,pointBytes:k}=V(m),N=U(E.context,A,w),O=_.multiply(N).toRawBytes(),M=U(E.context,O,k,w),z=B(N+M*C);wt("signature.s",z,Dt,n);let J=re(O,De(z,e.BYTES));return W("result",J,e.BYTES*2)}let S=Lu;function I(w,m,E,A=S){let{context:C,zip215:k}=A,N=e.BYTES;w=W("signature",w,2*N),m=W("message",m),E=W("publicKey",E,N),k!==void 0&&Pt("zip215",k),o&&(m=o(m));let O=le(w.slice(N,2*N)),M,z,J;try{M=p.fromHex(E,k),z=p.fromHex(w.slice(0,N),k),J=_.multiplyUnsafe(O)}catch{return!1}if(!k&&M.isSmallOrder())return!1;let Q=U(C,z.toRawBytes(),M.toRawBytes(),m);return z.add(M.multiplyUnsafe(Q)).subtract(J).clearCofactor().equals(p.ZERO)}return _._setWindowSize(8),{CURVE:t,getPublicKey:F,sign:tt,verify:I,ExtendedPoint:p,utils:{getExtendedPublicKey:V,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,m=p.BASE){return m._setWindowSize(w),m.multiply(BigInt(3)),m}}}}var fo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),vi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),vd=BigInt(0),Ru=BigInt(1),Ai=BigInt(2),Ad=BigInt(3),Pu=BigInt(5),Du=BigInt(8);function Cu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=fo,a=r*r%s*r%s,c=Z(a,Ai,s)*a%s,u=Z(c,Ru,s)*r%s,l=Z(u,Pu,s)*u%s,f=Z(l,t,s)*l%s,h=Z(f,e,s)*f%s,g=Z(h,n,s)*h%s,y=Z(g,o,s)*g%s,x=Z(y,o,s)*g%s,d=Z(x,t,s)*l%s;return{pow_p_5_8:Z(d,Ai,s)*r%s,b2:a}}function ku(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Uu(r,t){let e=fo,n=H(t*t*t,e),o=H(n*n*t,e),s=Cu(r*o).pow_p_5_8,i=H(r*n*s,e),a=H(t*i*i,e),c=i,u=H(i*vi,e),l=a===r,f=a===H(-r,e),h=a===H(-r*vi,e);return l&&(i=c),(f||h)&&(i=u),pi(i,e)&&(i=H(-i,e)),{isValid:l||f,value:i}}var _i=Vt(fo,void 0,!0),Nu={a:_i.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:_i,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Du,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:oi,randomBytes:Ar,adjustScalarBytes:ku,uvRatio:Uu},Ii=Si(Nu);var Rr=32;function Bi(r,t,e){return Ii.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Pr=class{type="Ed25519";raw;constructor(t){this.raw=lo(t,Rr)}toMultihash(){return At.digest(Te(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,e){return Bi(this.raw,e,t)}};function Ti(r){return r=lo(r,Rr),new Pr(r)}function lo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new kt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Mu=Math.pow(2,7),Fu=Math.pow(2,14),Ku=Math.pow(2,21),ho=Math.pow(2,28),po=Math.pow(2,35),mo=Math.pow(2,42),go=Math.pow(2,49),K=128,ut=127;function ft(r){if(r<Mu)return 1;if(r<Fu)return 2;if(r<Ku)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(ft(r)){case 8:t[e++]=r&255|K,r/=128;case 7:t[e++]=r&255|K,r/=128;case 6:t[e++]=r&255|K,r/=128;case 5:t[e++]=r&255|K,r/=128;case 4:t[e++]=r&255|K,r>>>=7;case 3:t[e++]=r&255|K,r>>>=7;case 2:t[e++]=r&255|K,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function zu(r,t,e=0){switch(ft(r)){case 8:t.set(e++,r&255|K),r/=128;case 7:t.set(e++,r&255|K),r/=128;case 6:t.set(e++,r&255|K),r/=128;case 5:t.set(e++,r&255|K),r/=128;case 4:t.set(e++,r&255|K),r>>>=7;case 3:t.set(e++,r&255|K),r>>>=7;case 2:t.set(e++,r&255|K),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function xo(r,t){let e=r[t],n=0;if(n+=e&ut,e<K||(e=r[t+1],n+=(e&ut)<<7,e<K)||(e=r[t+2],n+=(e&ut)<<14,e<K)||(e=r[t+3],n+=(e&ut)<<21,e<K)||(e=r[t+4],n+=(e&ut)*ho,e<K)||(e=r[t+5],n+=(e&ut)*po,e<K)||(e=r[t+6],n+=(e&ut)*mo,e<K)||(e=r[t+7],n+=(e&ut)*go,e<K))return n;throw new RangeError("Could not decode varint")}function qu(r,t){let e=r.get(t),n=0;if(n+=e&ut,e<K||(e=r.get(t+1),n+=(e&ut)<<7,e<K)||(e=r.get(t+2),n+=(e&ut)<<14,e<K)||(e=r.get(t+3),n+=(e&ut)<<21,e<K)||(e=r.get(t+4),n+=(e&ut)*ho,e<K)||(e=r.get(t+5),n+=(e&ut)*po,e<K)||(e=r.get(t+6),n+=(e&ut)*mo,e<K)||(e=r.get(t+7),n+=(e&ut)*go,e<K))return n;throw new RangeError("Could not decode varint")}function ne(r,t,e=0){return t==null&&(t=gt(ft(r))),t instanceof Uint8Array?yo(r,t,e):zu(r,t,e)}function jt(r,t=0){return r instanceof Uint8Array?xo(r,t):qu(r,t)}var wo=new Float32Array([-0]),oe=new Uint8Array(wo.buffer);function Ri(r,t,e){wo[0]=r,t[e]=oe[0],t[e+1]=oe[1],t[e+2]=oe[2],t[e+3]=oe[3]}function Pi(r,t){return oe[0]=r[t],oe[1]=r[t+1],oe[2]=r[t+2],oe[3]=r[t+3],wo[0]}var Eo=new Float64Array([-0]),lt=new Uint8Array(Eo.buffer);function Di(r,t,e){Eo[0]=r,t[e]=lt[0],t[e+1]=lt[1],t[e+2]=lt[2],t[e+3]=lt[3],t[e+4]=lt[4],t[e+5]=lt[5],t[e+6]=lt[6],t[e+7]=lt[7]}function Ci(r,t){return lt[0]=r[t],lt[1]=r[t+1],lt[2]=r[t+2],lt[3]=r[t+3],lt[4]=r[t+4],lt[5]=r[t+5],lt[6]=r[t+6],lt[7]=r[t+7],Eo[0]}var Hu=BigInt(Number.MAX_SAFE_INTEGER),Vu=BigInt(Number.MIN_SAFE_INTEGER),Et=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<Hu&&t>Vu)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>ki&&(o=0n,++n>ki&&(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 Et(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var ki=4294967296n;function Ui(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 Ni(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function 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 Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Dr(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,Bt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Dr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Dr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=Pi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=Ci(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ni(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=Dr(this.buf,this.pos+=4),e=Dr(this.buf,this.pos+=4);return new Et(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+=ft(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 Gt(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 gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}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}},ju=_o();function Gu(r){return globalThis.Buffer!=null?gt(r):ju(r)}var sr=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(Cr,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Cr,e.length(),e)}uint64Number(t){return this._push(yo,ft(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=Et.fromBigInt(t).zzEncode();return this._push(Cr,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Cr,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(or,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(or,4,e.lo)._push(or,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(or,4,e.lo)._push(or,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(Ri,4,t)}double(t){return this._push(Di,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Bo,1,0):this.uint32(e)._push(Zu,e,t)}string(t){let e=Ui(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=Gu(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 $u(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($u,t,e),this.next=void 0}};function Cr(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 or(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 Zu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(sr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Wu,t,r),this},sr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Yu,t,r),this});function Wu(r,t,e){t.set(r,e)}function Yu(r,t,e){r.length<40?So(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(X(r),e)}function Ro(){return new sr}function $t(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 kr(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 a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return kr("enum",Ue.VARINT,e,n)}function Zt(r,t){return kr("message",Ue.LENGTH_DELIMITED,r,t)}var Ur=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var St;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(St||(St={}));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)})(St||(St={}));var ir;(function(r){let t;r.codec=()=>(t==null&&(t=Zt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),St.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=St.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>$t(e,r.codec()),r.decode=(e,n)=>Gt(e,r.codec(),n)})(ir||(ir={}));var Do;(function(r){let t;r.codec=()=>(t==null&&(t=Zt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),St.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=St.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>$t(e,r.codec()),r.decode=(e,n)=>Gt(e,r.codec(),n)})(Do||(Do={}));var ar=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Nr=class extends Re{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Hs(t);let n=Xe(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),Ft(s)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),ae(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Co=(r,t,e)=>new Nr(r,t).update(e).digest();Co.create=(r,t)=>new Nr(r,t);function Mi(r){r.lowS!==void 0&&Pt("lowS",r.lowS),r.prehash!==void 0&&Pt("prehash",r.prehash)}function Qu(r){let t=nr(r);Ht(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var ko=class extends Error{constructor(t=""){super(t)}},Wt={Err:ko,_tlv:{encode:(r,t)=>{let{Err:e}=Wt;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=er(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?er(o.length/2|128):"";return er(r)+s+o+t},decode(r,t){let{Err:e}=Wt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Wt;if(r<Yt)throw new t("integer: negative integers are not allowed");let e=er(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}=Wt;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 qt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Wt,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:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=Wt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Yt=BigInt(0),st=BigInt(1),B0=BigInt(2),Fi=BigInt(3),L0=BigInt(4);function Ju(r){let t=Qu(r),{Fp:e}=t,n=Vt(t.n,t.nBitLength),o=t.toBytes||((x,d,b)=>{let v=d.toAffine();return re(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(x=>{let d=x.subarray(1),b=e.fromBytes(d.subarray(0,e.BYTES)),v=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:b,y:v}});function i(x){let{a:d,b}=t,v=e.sqr(x),p=e.mul(v,x);return e.add(e.add(p,e.mul(x,d)),b)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(x){return Ir(x,st,t.n)}function c(x){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:v,n:p}=t;if(d&&typeof x!="bigint"){if(fe(x)&&(x=ee(x)),typeof x!="string"||!d.includes(x.length))throw new Error("invalid private key");x=x.padStart(b*2,"0")}let _;try{_=typeof x=="bigint"?x:qt(W("private key",x,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof x)}return v&&(_=H(_,p)),wt("private key",_,st,p),_}function u(x){if(!(x instanceof h))throw new Error("ProjectivePoint expected")}let l=Ce((x,d)=>{let{px:b,py:v,pz:p}=x;if(e.eql(p,e.ONE))return{x:b,y:v};let _=x.is0();d==null&&(d=_?e.ONE:e.inv(p));let P=e.mul(b,d),D=e.mul(v,d),B=e.mul(p,d);if(_)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:P,y:D}}),f=Ce(x=>{if(x.is0()){if(t.allowInfinityPoint&&!e.is0(x.py))return;throw new Error("bad point: ZERO")}let{x:d,y:b}=x.toAffine();if(!e.isValid(d)||!e.isValid(b))throw new Error("bad point: x or y not FE");let v=e.sqr(b),p=i(d);if(!e.eql(v,p))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,b,v){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(v==null||!e.isValid(v))throw new Error("z required");this.px=d,this.py=b,this.pz=v,Object.freeze(this)}static fromAffine(d){let{x:b,y:v}=d||{};if(!d||!e.isValid(b)||!e.isValid(v))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let p=_=>e.eql(_,e.ZERO);return p(b)&&p(v)?h.ZERO:new h(b,v,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let b=ke(e,d.map(v=>v.pz));return d.map((v,p)=>v.toAffine(b[p])).map(h.fromAffine)}static fromHex(d){let b=h.fromAffine(s(W("pointHex",d)));return b.assertValidity(),b}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,b){return Tr(h,n,d,b)}_setWindowSize(d){y.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){u(d);let{px:b,py:v,pz:p}=this,{px:_,py:P,pz:D}=d,B=e.eql(e.mul(b,D),e.mul(_,p)),L=e.eql(e.mul(v,D),e.mul(P,p));return B&&L}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b}=t,v=e.mul(b,Fi),{px:p,py:_,pz:P}=this,D=e.ZERO,B=e.ZERO,L=e.ZERO,T=e.mul(p,p),V=e.mul(_,_),F=e.mul(P,P),U=e.mul(p,_);return U=e.add(U,U),L=e.mul(p,P),L=e.add(L,L),D=e.mul(d,L),B=e.mul(v,F),B=e.add(D,B),D=e.sub(V,B),B=e.add(V,B),B=e.mul(D,B),D=e.mul(U,D),L=e.mul(v,L),F=e.mul(d,F),U=e.sub(T,F),U=e.mul(d,U),U=e.add(U,L),L=e.add(T,T),T=e.add(L,T),T=e.add(T,F),T=e.mul(T,U),B=e.add(B,T),F=e.mul(_,P),F=e.add(F,F),T=e.mul(F,U),D=e.sub(D,T),L=e.mul(F,V),L=e.add(L,L),L=e.add(L,L),new h(D,B,L)}add(d){u(d);let{px:b,py:v,pz:p}=this,{px:_,py:P,pz:D}=d,B=e.ZERO,L=e.ZERO,T=e.ZERO,V=t.a,F=e.mul(t.b,Fi),U=e.mul(b,_),tt=e.mul(v,P),S=e.mul(p,D),I=e.add(b,v),R=e.add(_,P);I=e.mul(I,R),R=e.add(U,tt),I=e.sub(I,R),R=e.add(b,p);let w=e.add(_,D);return R=e.mul(R,w),w=e.add(U,S),R=e.sub(R,w),w=e.add(v,p),B=e.add(P,D),w=e.mul(w,B),B=e.add(tt,S),w=e.sub(w,B),T=e.mul(V,R),B=e.mul(F,S),T=e.add(B,T),B=e.sub(tt,T),T=e.add(tt,T),L=e.mul(B,T),tt=e.add(U,U),tt=e.add(tt,U),S=e.mul(V,S),R=e.mul(F,R),tt=e.add(tt,S),S=e.sub(U,S),S=e.mul(V,S),R=e.add(R,S),U=e.mul(tt,R),L=e.add(L,U),U=e.mul(w,R),B=e.mul(I,B),B=e.sub(B,U),U=e.mul(I,tt),T=e.mul(w,T),T=e.add(T,U),new h(B,L,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return y.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:b,n:v}=t;wt("scalar",d,Yt,v);let p=h.ZERO;if(d===Yt)return p;if(this.is0()||d===st)return this;if(!b||y.hasPrecomputes(this))return y.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:_,k1:P,k2neg:D,k2:B}=b.splitScalar(d),L=p,T=p,V=this;for(;P>Yt||B>Yt;)P&st&&(L=L.add(V)),B&st&&(T=T.add(V)),V=V.double(),P>>=st,B>>=st;return _&&(L=L.negate()),D&&(T=T.negate()),T=new h(e.mul(T.px,b.beta),T.py,T.pz),L.add(T)}multiply(d){let{endo:b,n:v}=t;wt("scalar",d,st,v);let p,_;if(b){let{k1neg:P,k1:D,k2neg:B,k2:L}=b.splitScalar(d),{p:T,f:V}=this.wNAF(D),{p:F,f:U}=this.wNAF(L);T=y.constTimeNegate(P,T),F=y.constTimeNegate(B,F),F=new h(e.mul(F.px,b.beta),F.py,F.pz),p=T.add(F),_=V.add(U)}else{let{p:P,f:D}=this.wNAF(d);p=P,_=D}return h.normalizeZ([p,_])[0]}multiplyAndAddUnsafe(d,b,v){let p=h.BASE,_=(D,B)=>B===Yt||B===st||!D.equals(p)?D.multiplyUnsafe(B):D.multiply(B),P=_(this,b).add(_(d,v));return P.is0()?void 0:P}toAffine(d){return l(this,d)}isTorsionFree(){let{h:d,isTorsionFree:b}=t;if(d===st)return!0;if(b)return b(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:b}=t;return d===st?this:b?b(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Pt("isCompressed",d),this.assertValidity(),o(h,this,d)}toHex(d=!0){return Pt("isCompressed",d),ee(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,y=Lr(h,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function tf(r){let t=nr(r);return Ht(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ki(r){let t=tf(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(S){return H(S,n)}function a(S){return Br(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=Ju({...t,toBytes(S,I,R){let w=I.toAffine(),m=e.toBytes(w.x),E=re;return Pt("isCompressed",R),R?E(Uint8Array.from([I.hasEvenY()?2:3]),m):E(Uint8Array.from([4]),m,e.toBytes(w.y))},fromBytes(S){let I=S.length,R=S[0],w=S.subarray(1);if(I===o&&(R===2||R===3)){let m=qt(w);if(!Ir(m,st,e.ORDER))throw new Error("Point is not on curve");let E=l(m),A;try{A=e.sqrt(E)}catch(N){let O=N instanceof Error?": "+N.message:"";throw new Error("Point is not on curve"+O)}let C=(A&st)===st;return(R&1)===1!==C&&(A=e.neg(A)),{x:m,y:A}}else if(I===s&&R===4){let m=e.fromBytes(w.subarray(0,e.BYTES)),E=e.fromBytes(w.subarray(e.BYTES,2*e.BYTES));return{x:m,y:E}}else{let m=o,E=s;throw new Error("invalid Point, expected length of "+m+", or uncompressed "+E+", got "+I)}}}),h=S=>ee(he(S,t.nByteLength));function g(S){let I=n>>st;return S>I}function y(S){return g(S)?i(-S):S}let x=(S,I,R)=>qt(S.slice(I,R));class d{constructor(I,R,w){wt("r",I,st,n),wt("s",R,st,n),this.r=I,this.s=R,w!=null&&(this.recovery=w),Object.freeze(this)}static fromCompact(I){let R=t.nByteLength;return I=W("compactSignature",I,R*2),new d(x(I,0,R),x(I,R,2*R))}static fromDER(I){let{r:R,s:w}=Wt.toSig(W("DER",I));return new d(R,w)}assertValidity(){}addRecoveryBit(I){return new d(this.r,this.s,I)}recoverPublicKey(I){let{r:R,s:w,recovery:m}=this,E=D(W("msgHash",I));if(m==null||![0,1,2,3].includes(m))throw new Error("recovery id invalid");let A=m===2||m===3?R+t.n:R;if(A>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let C=(m&1)===0?"02":"03",k=c.fromHex(C+h(A)),N=a(A),O=i(-E*N),M=i(w*N),z=c.BASE.multiplyAndAddUnsafe(k,O,M);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return rr(this.toDERHex())}toDERHex(){return Wt.hexFromSig(this)}toCompactRawBytes(){return rr(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let b={isValidPrivateKey(S){try{return u(S),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let S=oo(t.n);return gi(t.randomBytes(S),t.n)},precompute(S=8,I=c.BASE){return I._setWindowSize(S),I.multiply(BigInt(3)),I}};function v(S,I=!0){return c.fromPrivateKey(S).toRawBytes(I)}function p(S){let I=fe(S),R=typeof S=="string",w=(I||R)&&S.length;return I?w===o||w===s:R?w===2*o||w===2*s:S instanceof c}function _(S,I,R=!0){if(p(S))throw new Error("first arg must be private key");if(!p(I))throw new Error("second arg must be public key");return c.fromHex(I).multiply(u(S)).toRawBytes(R)}let P=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let I=qt(S),R=S.length*8-t.nBitLength;return R>0?I>>BigInt(R):I},D=t.bits2int_modN||function(S){return i(P(S))},B=de(t.nBitLength);function L(S){return wt("num < 2^"+t.nBitLength,S,Yt,B),he(S,t.nByteLength)}function T(S,I,R=V){if(["recovered","canonical"].some(Q=>Q in R))throw new Error("sign() legacy options not supported");let{hash:w,randomBytes:m}=t,{lowS:E,prehash:A,extraEntropy:C}=R;E==null&&(E=!0),S=W("msgHash",S),Mi(R),A&&(S=W("prehashed msgHash",w(S)));let k=D(S),N=u(I),O=[L(N),L(k)];if(C!=null&&C!==!1){let Q=C===!0?m(e.BYTES):C;O.push(W("extraEntropy",Q))}let M=re(...O),z=k;function J(Q){let it=P(Q);if(!f(it))return;let mt=a(it),nt=c.BASE.multiply(it).toAffine(),ct=i(nt.x);if(ct===Yt)return;let yt=i(mt*i(z+ct*N));if(yt===Yt)return;let vt=(nt.x===ct?0:2)|Number(nt.y&st),ze=yt;return E&&g(yt)&&(ze=y(yt),vt^=1),new d(ct,ze,vt)}return{seed:M,k2sig:J}}let V={lowS:t.lowS,prehash:!1},F={lowS:t.lowS,prehash:!1};function U(S,I,R=V){let{seed:w,k2sig:m}=T(S,I,R),E=t;return fi(E.hash.outputLen,E.nByteLength,E.hmac)(w,m)}c.BASE._setWindowSize(8);function tt(S,I,R,w=F){let m=S;I=W("msgHash",I),R=W("publicKey",R);let{lowS:E,prehash:A,format:C}=w;if(Mi(w),"strict"in w)throw new Error("options.strict was renamed to lowS");if(C!==void 0&&C!=="compact"&&C!=="der")throw new Error("format must be compact or der");let k=typeof m=="string"||fe(m),N=!k&&!C&&typeof m=="object"&&m!==null&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!k&&!N)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let O,M;try{if(N&&(O=new d(m.r,m.s)),k){try{C!=="compact"&&(O=d.fromDER(m))}catch(vt){if(!(vt instanceof Wt.Err))throw vt}!O&&C!=="der"&&(O=d.fromCompact(m))}M=c.fromHex(R)}catch{return!1}if(!O||E&&O.hasHighS())return!1;A&&(I=t.hash(I));let{r:z,s:J}=O,Q=D(I),it=a(J),mt=i(Q*it),nt=i(z*it),ct=c.BASE.multiplyAndAddUnsafe(M,mt,nt)?.toAffine();return ct?i(ct.x)===z:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:_,sign:U,verify:tt,ProjectivePoint:c,Signature:d,utils:b}}function ef(r){return{hash:r,hmac:(t,...e)=>Co(r,t,Vn(...e)),randomBytes:Ar}}function zi(r,t){let e=n=>Ki({...r,...ef(n)});return{...e(t),create:e}}var Vi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),qi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),rf=BigInt(1),Uo=BigInt(2),Hi=(r,t)=>(r+t/Uo)/t;function nf(r){let t=Vi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=Z(l,e,t)*l%t,h=Z(f,e,t)*l%t,g=Z(h,Uo,t)*u%t,y=Z(g,o,t)*g%t,x=Z(y,s,t)*y%t,d=Z(x,a,t)*x%t,b=Z(d,c,t)*d%t,v=Z(b,a,t)*x%t,p=Z(v,e,t)*l%t,_=Z(p,i,t)*y%t,P=Z(_,n,t)*u%t,D=Z(P,Uo,t);if(!No.eql(No.sqr(D),r))throw new Error("Cannot find square root");return D}var No=Vt(Vi,void 0,void 0,{sqrt:nf}),ye=zi({a:BigInt(0),b:BigInt(7),Fp:No,n:qi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=qi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-rf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Hi(s*r,t),c=Hi(-n*r,t),u=H(r-a*e-c*o,t),l=H(-a*n-c*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}}}},ni),O0=BigInt(0);var M0=ye.ProjectivePoint;function ji(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Gi(r,t,e){let n=$e.digest(e instanceof Uint8Array?e:e.subarray());if(ji(n))return n.then(({digest:o})=>ye.verify(t,o,r)).catch(o=>{throw new ar(String(o))});try{return ye.verify(t,n.digest,r)}catch(o){throw new ar(String(o))}}var Or=class{type="secp256k1";raw;_key;constructor(t){this._key=Zi(t),this.raw=$i(this._key)}toMultihash(){return At.digest(Te(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,e){return Gi(this._key,e,t)}};function Wi(r){return new Or(r)}function $i(r){return ye.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Zi(r){try{return ye.ProjectivePoint.fromHex(r),r}catch(t){throw new mr(String(t))}}function Yi(r){let{Type:t,Data:e}=ir.decode(r.digest),n=e??new Uint8Array;switch(t){case St.Ed25519:return Ti(n);case St.secp256k1:return Wi(n);case St.ECDSA:return Ks(n);default:throw new qe}}function Te(r){return ir.encode({Type:St[r.type],Data:r.raw})}var Xi=Symbol.for("nodejs.util.inspect.custom"),of=114,cr=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()})`}[gn]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ot.createV1(of,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ht(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ht(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Xi](){return`PeerId(${this.toString()})`}},Mr=class extends cr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Fr=class extends cr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Kr=class extends cr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},sf=2336,zr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(X(this.url))}[Xi](){return`PeerId(${this.url})`}[gn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ot.createV1(sf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function qr(r){if(cf(r))return new Mr({multihash:r});if(af(r))try{let t=Yi(r);if(t.type==="Ed25519")return new Fr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Kr({multihash:r,publicKey:t})}catch{let e=j(r.digest);return new zr(new URL(e))}throw new gr("Supplied PeerID Multihash is invalid")}function af(r){return r.code===At.code}function cf(r){return r.code===$e.code}function Oo(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 Hr(r){let t=Ot(G.decode(`z${r}`));return qr(t)}var Vr=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 Oo(this.set.entries(),t=>{let e=Hr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Hr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Oo(this.set.values(),t=>Hr(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 Mo(){return new Vr}var Fo={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Qi={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ji=new globalThis.TextEncoder;function uf(r,t){let e=Fo[t],n=Qi[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function ff(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Fo[t],o=Qi[t],s=r;for(;s.length>0;){let i=Ji.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function Ko(r,{size:t=32,utf8Buffer:e}={}){if(!Fo[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 ff(r,t,e);r=Ji.encode(r)}return uf(r,t)}var ur={hash:r=>Number(Ko(r,{size:32})),hashV:(r,t)=>lf(ur.hash(r,t))};function lf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),X(t,"base16")}var zo=64,Lt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>zo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=_t(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ht(this.fp,t.fp):!1}};function xe(r,t){return Math.floor(Math.random()*(t-r))+r}var be=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Lt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Lt))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 Lt))throw new TypeError("Invalid Fingerprint");let e=xe(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Lt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var hf=500,fr=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??ur,this.seed=t.seed??xe(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=X(t));let e=new Lt(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 be(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new be(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[xe(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new be(this.bucketSize));for(let a=0;a<hf;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new be(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=X(t));let e=new Lt(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=X(t));let e=new Lt(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}},df={1:.5,2:.84,4:.95,8:.98};function pf(r=.001){return r>.002?2:r>1e-5?4:8}function ta(r,t=.001){let e=pf(t),n=df[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),zo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var jr=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??ur,this.seed=t.seed??xe(0,Math.pow(2,10)),this.filterSeries=[new fr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=X(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 fr({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=X(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=X(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 qo(r,t=.001,e){return new jr({...ta(r,t),...e??{}})}var Gr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let 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&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ea=45,mf=15,Oe=new Gr;function $r(r){if(!(r.length>mf))return Oe.new(r).parseWith(()=>Oe.readIPv4Addr())}function Zr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ea))return Oe.new(r).parseWith(()=>Oe.readIPv6Addr())}function we(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>ea)return;let e=Oe.new(r).parseWith(()=>Oe.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function ra(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function na(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Ho(r){switch(r.length){case Ee:return r.join(".");case Se:{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 oa(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 sa(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Ee=4,Se=16,Bm=parseInt("0xFFFF",16),gf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function lr(r,t){t.length===Se&&r.length===Ee&&ra(t,0,11)&&(t=t.slice(12)),t.length===Ee&&r.length===Se&&na(r,gf,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 ia(r,t){if(typeof t=="string"&&(t=we(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 Vo(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Ee,o=$r(t);if(o==null&&(n=Se,o=Zr(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=jo(s,8*n);return{network:lr(o,i),mask:i}}function jo(r,t){if(t!==8*Ee&&t!==8*Se)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 Me=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Vo(t));else{let n=we(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=we(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=jo(o,8*n.length);this.network=lr(n,this.mask)}}contains(t){return ia({network:this.network,mask:this.mask},t)}toString(){let t=oa(this.mask),e=t!==-1?String(t):sa(this.mask);return Ho(this.network)+"/"+e}};function aa(r,t){return new Me(r).contains(t)}var yf=41;function ca(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===yf)return aa("2000::/3",e)}catch{}return!1}function Wr(r){return!!$r(r)}function Yr(r){return!!Zr(r)}function Xr(r){return!!we(r)}var fa=Ka(ua(),1),xf=["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"],bf=xf.map(r=>new fa.Netmask(r));function Go(r){for(let t of bf)if(t.contains(r))return!0;return!1}function wf(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Ef(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 Go(o)}function Sf(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function vf(r){let t=r.split(":"),e=t[t.length-1];return Go(e)}function Af(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 la(r){return Wr(r)?Go(r):wf(r)?Ef(r):Sf(r)?vf(r):Yr(r)?Af(r):void 0}function ha(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function $o(r){try{if(!ha(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:la(t)??!1}catch{}return!0}function Tt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Qr=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}},Fe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Qr(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 Qr(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 Zo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function da(r={}){return _f(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 _f(r,t){t=t??{};let e=t.onEnd,n=new Fe,o,s,i,a=Tt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,b)=>{s=v=>{s=null,n.push(v);try{d(r(n))}catch(p){b(p)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Tt()})}},u=d=>s!=null?s(d):(n.push(d),o),l=d=>(n=new Fe,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:d})},h=d=>i?o:(i=!0,d!=null?l(d):u({done:!0})),g=()=>(n=new Fe,h(),{done:!0}),y=d=>(h(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:y,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let b=d?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,p;b!=null&&(v=new Promise((_,P)=>{p=()=>{P(new Zo)},b.addEventListener("abort",p)}));try{await Promise.race([a.promise,v])}finally{p!=null&&b!=null&&b?.removeEventListener("abort",p)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(d){return x.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return x.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:d=>x.onEmpty(d)},o}var Wo=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 Jr(r,t,e,n){let o=new Wo(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",l),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),i(h);return}a(),s(f)},u=f=>{a(),i(f.detail)},l=()=>{a(),i(o)};e?.addEventListener("abort",l),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}var tn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var en=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 ve(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new en(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new en(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 rn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Tt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Ct)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Bf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var nn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=Bf(),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 Ct),this.cleanup())}async join(t={}){let e=new rn(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 ve(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 on=class extends yr{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=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!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 tn;let n=new nn(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 Ct)}),this.clear()}async onEmpty(t){this.size!==0&&await Jr(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await Jr(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Jr(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=da({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail)},i=()=>{n()},a=()=>{n(new Ct("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var sn=class extends on{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function an(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 pa(r,t,e){let n,o;function s(){let a={signal:o.signal};if(e?.timeout!=null){let c=an([o.signal,AbortSignal.timeout(e.timeout)]);a.signal=c}Promise.resolve().then(async()=>{await r(a)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{setInterval:a=>{t=a,n!=null&&(clearTimeout(n),n=setTimeout(s,t))},setTimeout:a=>{e==null&&(e={}),e.timeout=a},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 ma=Wr,Lf=Yr,Yo=function(r){let t=0;if(r=r.toString().trim(),ma(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Lf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ma(e[n]),i;s&&(i=Yo(e[n]),e[n]=j(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,j(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")},ga=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 Ke={},Xo={},Rf=[[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"]];Rf.forEach(r=>{let t=Pf(...r);Xo[t.code]=t,Ke[t.name]=t});function Pf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function q(r){if(typeof r=="number"){if(Xo[r]!=null)return Xo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ke[r]!=null)return Ke[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var zg=q("ip4"),qg=q("ip6"),Hg=q("ipcidr");function es(r,t){switch(q(r).code){case 4:case 41:return Cf(t);case 42:return ts(t);case 43:return j(t,"base10");case 6:case 273:case 33:case 132:return ba(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ts(t);case 421:return Of(t);case 444:return xa(t);case 445:return xa(t);case 466:return Nf(t);case 481:return globalThis.encodeURIComponent(ts(t));default:return j(t,"base16")}}function rs(r,t){switch(q(r).code){case 4:return ya(t);case 41:return ya(t);case 42:return Jo(t);case 43:return X(t,"base10");case 6:case 273:case 33:case 132:return ns(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Jo(t);case 421:return kf(t);case 444:return Mf(t);case 445:return Ff(t);case 466:return Uf(t);case 481:return Jo(globalThis.decodeURIComponent(t));default:return X(t,"base16")}}var Qo=Object.values(Ze).map(r=>r.decoder),Df=function(){let r=Qo[0].or(Qo[1]);return Qo.slice(2).forEach(t=>r=r.or(t)),r}();function ya(r){if(!Xr(r))throw new Error("invalid ip address");return Yo(r)}function Cf(r){let t=ga(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Xr(t))throw new Error("invalid ip address");return t}function ns(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ba(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Jo(r){let t=X(r),e=Uint8Array.from(ne(t.length));return bt([e,t],e.length+t.length)}function ts(r){let t=jt(r);if(r=r.slice(ft(t)),r.length!==t)throw new Error("inconsistent lengths");return j(r)}function kf(r){let t;r[0]==="Q"||r[0]==="1"?t=Ot(G.decode(`z${r}`)).bytes:t=ot.parse(r).multihash.bytes;let e=Uint8Array.from(ne(t.length));return bt([e,t],e.length+t.length)}function Uf(r){let t=Df.decode(r),e=Uint8Array.from(ne(t.length));return bt([e,t],e.length+t.length)}function Nf(r){let t=jt(r),e=r.slice(ft(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+j(e,"base64url")}function Of(r){let t=jt(r),e=r.slice(ft(t));if(e.length!==t)throw new Error("inconsistent lengths");return j(e,"base58btc")}function Mf(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=Nt.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=ns(n);return bt([e,o],e.length+o.length)}function Ff(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=Nt.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=ns(n);return bt([e,o],e.length+o.length)}function xa(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=j(t,"base32"),o=ba(e);return`${n}:${o}`}function wa(r){r=os(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],a=q(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new cn("invalid address: "+r);if(a.path===!0){n=os(o.slice(s).join("/")),t.push([a.code,rs(a.code,n)]),e.push([a.code,n]);break}let c=rs(a.code,o[s]);t.push([a.code,c]),e.push([a.code,es(a.code,c)])}return{string:Ea(e),bytes:un(t),tuples:t,stringTuples:e,path:n}}function ss(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=jt(r,o),i=ft(s),a=q(s),c=Kf(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let u=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw new cn("Invalid address Uint8Array: "+j(r,"base16"));t.push([s,u]);let l=es(s,u);if(e.push([s,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Ea(e),tuples:t,stringTuples:e,path:n}}function Ea(r){let t=[];return r.map(e=>{let n=q(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),os(t.join("/"))}function un(r){return bt(r.map(t=>{let e=q(t[0]),n=Uint8Array.from(ne(e.code));return t.length>1&&t[1]!=null&&(n=bt([n,t[1]])),n}))}function Kf(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=jt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ft(e)}}function os(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var cn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var zf=Symbol.for("nodejs.util.inspect.custom"),as=Symbol.for("@multiformats/js-multiaddr/multiaddr"),qf=[q("dns").code,q("dns4").code,q("dns6").code,q("dnsaddr").code],is=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},fn=class r{bytes;#t;#e;#r;#n;[as]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=ss(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=wa(t)}else if(va(t))e=ss(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=q("tcp"),a=q("udp"),c=q("ip4"),u=q("ip6"),l=q("dns6"),f=q("ip6zone");for(let[g,y]of this.stringTuples())g===f.code&&(s=`%${y??""}`),qf.includes(g)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${y??""}${s}`,t=g===l.code?6:4),(g===i.code||g===a.code)&&(e=q(g).name==="tcp"?"tcp":"udp",o=parseInt(y??"")),(g===c.code||g===u.code)&&(e=q(g).name==="tcp"?"tcp":"udp",n=`${y??""}${s}`,t=g===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({},q(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>q(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(un(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ke.p2p.code&&t.push([n,o]),n===Ke["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?j(G.decode(`z${n}`),"base58btc"):j(ot.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return ht(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Sa.get(e.name);if(n==null)throw new is(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>dr(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)}[zf](){return`Multiaddr(${this.#t})`}};var Sa=new Map;function va(r){return!!r?.[as]}function dr(r){return new fn(r)}var cs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Tt(),this.haveNext=Tt()}[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=Tt(),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=Tt(),await ve(this.readNext.promise,e?.signal,e)}};function Aa(){return new cs}var ln=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function _a(r,t){let e=Aa();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new et;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:c,value:u}=await ve(n.next(),i?.signal);return c===!0?null:u}for(;o.byteLength<i.bytes;){let{value:c,done:u}=await ve(n.next(),i?.signal);if(u===!0)throw new ln("unexpected end of input");o.append(c)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var hn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},dn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},pn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ia(r,t={}){let e=_a(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=ft(t.maxDataLength));let n=t?.lengthDecoder??jt,o=t?.lengthEncoder??ne;return{read:async i=>{let a=-1,c=new et;for(;;){c.append(await e.read({...i,bytes:1}));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new hn("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new pn("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new dn("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new et(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new et(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function us(r,t){let e=Ia(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Ba="libp2p",La="autonat",Ta="1.0.0";var $;(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=Zt((f,h,g={})=>{if(g.lengthDelimited!==!1&&h.fork(),f.id!=null&&(h.uint32(10),h.bytes(f.id)),f.addrs!=null)for(let y of f.addrs)h.uint32(18),h.bytes(y);g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let y={addrs:[]},x=h==null?f.len:f.pos+h;for(;f.pos<x;){let d=f.uint32();switch(d>>>3){case 1:{y.id=f.bytes();break}case 2:{if(g.limits?.addrs!=null&&y.addrs.length===g.limits.addrs)throw new Ur('Decode error - map field "addrs" had too many elements');y.addrs.push(f.bytes());break}default:{f.skipType(d&7);break}}}return y})),l),u.encode=f=>$t(f,u.codec()),u.decode=(f,h)=>Gt(f,u.codec(),h)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let l;u.codec=()=>(l==null&&(l=Zt((f,h,g={})=>{g.lengthDelimited!==!1&&h.fork(),f.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(f.peer,h)),g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let y={},x=h==null?f.len:f.pos+h;for(;f.pos<x;){let d=f.uint32();switch(d>>>3){case 1:{y.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:g.limits?.peer});break}default:{f.skipType(d&7);break}}}return y})),l),u.encode=f=>$t(f,u.codec()),u.decode=(f,h)=>Gt(f,u.codec(),h)})(i=r.Dial||(r.Dial={}));let a;(function(u){let l;u.codec=()=>(l==null&&(l=Zt((f,h,g={})=>{g.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)),g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let y={},x=h==null?f.len:f.pos+h;for(;f.pos<x;){let d=f.uint32();switch(d>>>3){case 1:{y.status=r.ResponseStatus.codec().decode(f);break}case 2:{y.statusText=f.string();break}case 3:{y.addr=f.bytes();break}default:{f.skipType(d&7);break}}}return y})),l),u.encode=f=>$t(f,u.codec()),u.decode=(f,h)=>Gt(f,u.codec(),h)})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=Zt((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={},g=l==null?u.len:u.pos+l;for(;u.pos<g;){let y=u.uint32();switch(y>>>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(y&7);break}}}return h})),c),r.encode=u=>$t(u,r.codec()),r.decode=(u,l)=>Gt(u,r.codec(),l)})($||($={}));var Zf=4,Wf=8,mn=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??Ba}/${La}/${Ta}`,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=pa(this.findRandomPeers.bind(this),6e4),this.addressFilter=qo(1024)}[Symbol.toStringTag]="@libp2p/autonat";[hs]=["@libp2p/autonat"];get[ds](){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=an([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=us(t.stream,{maxDataLength:this.maxMessageSize}).pb($);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:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("PeerId missing from message"),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Ot(a.id);i=qr(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.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:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(f=>dr(f)).filter(f=>{let h=f.toOptions();return $o(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(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(f=>f.toString()).join(", "),i);let u="",l=c[0];for await(let f of c){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:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(q("p2p").code).bytes}}}catch(g){this.log.error("could not dial %p - %e",i,g),u=g.message}finally{h!=null&&await h.close()}}return{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.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||!ca(o.multiaddr))||$o(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:Mo(),queue:new sn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>i.toOptions().family===6),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %p to verify multiaddr %s",t.remotePeer,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=us(i).pb($),[,c]=await Promise.all([a.write({type:$.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==$.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let u=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==$.ResponseStatus.OK&&u!==$.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),u===$.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===$.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Zf&&this.confirmAddress(o),o.failure===Wf&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};function Yf(r={}){return t=>new mn(t,r)}return za(Xf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js:
6
6
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7
7
 
8
8
  @noble/curves/esm/abstract/utils.js:
9
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
10
-
11
9
  @noble/curves/esm/abstract/modular.js:
12
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
13
-
14
10
  @noble/curves/esm/abstract/curve.js:
15
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
16
-
17
11
  @noble/curves/esm/abstract/edwards.js:
18
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
19
-
20
12
  @noble/curves/esm/ed25519.js:
21
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
22
-
23
13
  @noble/curves/esm/abstract/weierstrass.js:
24
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
25
-
26
14
  @noble/curves/esm/_shortw_utils.js:
27
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
28
-
29
15
  @noble/curves/esm/secp256k1.js:
30
16
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
31
17
  */
32
18
  return Libp2PAutonat}));
19
+ //# sourceMappingURL=index.min.js.map