@libp2p/autonat-v2 2.1.4 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonatV2 = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PAutonatV2=(()=>{var xu=Object.create;var jr=Object.defineProperty;var Eu=Object.getOwnPropertyDescriptor;var Su=Object.getOwnPropertyNames;var vu=Object.getPrototypeOf,_u=Object.prototype.hasOwnProperty;var po=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},vt=(e,t)=>{for(var r in t)jr(e,r,{get:t[r],enumerable:!0})},vi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Su(t))!_u.call(e,o)&&o!==r&&jr(e,o,{get:()=>t[o],enumerable:!(n=Eu(t,o))||n.enumerable});return e};var Au=(e,t,r)=>(r=e!=null?xu(vu(e)):{},vi(t||!e||!e.__esModule?jr(r,"default",{value:e,enumerable:!0}):r,e)),Iu=e=>vi(jr({},"__esModule",{value:!0}),e);var Xs=po(Xe=>{"use strict";Object.defineProperty(Xe,"__esModule",{value:!0});Xe.Netmask4Impl=void 0;Xe.ip2long=We;Xe.long2ip=Ht;function Ht(e){let t=(e&-16777216)>>>24,r=(e&255<<16)>>>16,n=(e&65280)>>>8,o=e&255;return[t,r,n,o].join(".")}var vd=48,_d=97,Ad=65;function Id(e){let t=0,r=10,n="9",o=0;e.length>1&&e[o]==="0"&&(e[o+1]==="x"||e[o+1]==="X"?(o+=2,r=16):"0"<=e[o+1]&&e[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<e.length;){if("0"<=e[o]&&e[o]<=n)t=t*r+(e.charCodeAt(o)-vd)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-_d)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-Ad)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function We(e){let t=[];for(let r=0;r<=3&&e.length!==0;r++){if(r>0){if(e[0]!==".")throw new Error("Invalid IP");e=e.substring(1)}let[n,o]=Id(e);e=e.substring(o),t.push(n)}if(e.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var Ws=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=We(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(We(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Ht(this.netLong),this.mask=Ht(this.maskLong),this.hostmask=Ht(~this.maskLong),this.first=this.bitmask<=30?Ht(this.netLong+1):this.base,this.last=this.bitmask<=30?Ht(this.netLong+this.size-2):Ht(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Ht(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):(We(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new e(Ht(this.netLong+this.size*t),this.mask)}forEach(t){let r=We(this.first),n=We(this.last),o=0;for(;r<=n;)t(Ht(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Xe.Netmask4Impl=Ws});var Mc=po(Qe=>{"use strict";Object.defineProperty(Qe,"__esModule",{value:!0});Qe.Netmask6Impl=void 0;Qe.ip6bigint=Js;Qe.bigint2ip6=Ie;var Bd=Xs(),Qs=(1n<<128n)-1n;function Js(e){let t=e.indexOf("%");t!==-1&&(e=e.substring(0,t));let r=e.lastIndexOf(":");if(r!==-1&&e.indexOf(".",r)!==-1){let n=e.substring(r+1),o=(0,Bd.ip2long)(n),s=e.substring(0,r+1)+"0:0";return Uc(s)&~0xffffffffn|BigInt(o)}return Uc(e)}function Uc(e){let t=e.indexOf("::"),r;if(t!==-1){let o=e.substring(0,t),s=e.substring(t+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=e.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Ie(e){if(e<0n||e>Qs)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(e&0xffffn)),e>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return t.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=t.slice(0,r).map(c=>c.toString(16)),a=t.slice(r+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var ti=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Qs>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Js(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Ie(this.netBigint),this.mask=Ie(this.maskBigint),this.hostmask=Ie(~this.maskBigint&Qs),this.first=this.base,this.last=Ie(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.last):(Js(t)&this.maskBigint)===this.netBigint}next(t=1){let r=1n<<BigInt(128-this.bitmask);return new e(Ie(this.netBigint+r*BigInt(t)),this.bitmask)}forEach(t){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)t(Ie(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};Qe.Netmask6Impl=ti});var Kc=po(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.long2ip=ce.ip2long=ce.Netmask=void 0;var Yn=Xs();Object.defineProperty(ce,"ip2long",{enumerable:!0,get:function(){return Yn.ip2long}});Object.defineProperty(ce,"long2ip",{enumerable:!0,get:function(){return Yn.long2ip}});var Td=Mc(),ei=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new Td.Netmask6Impl(t,r):this._impl=new Yn.Netmask4Impl(t,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Yn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new e(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new e(t))),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let r=this._impl.next(t);return new e(r.base,r.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ce.Netmask=ei});var Vh={};vt(Vh,{autoNATv2:()=>$h});var Mt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var yt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Zr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Yr=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Gr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var It=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var ar=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var mo=Symbol.for("@libp2p/peer-id");function _i(e){return e!=null&&typeof e.start=="function"&&typeof e.stop=="function"}async function Ai(...e){let t=[];for(let r of e)_i(r)&&t.push(r);await Promise.all(t.map(async r=>{r.beforeStart!=null&&await r.beforeStart()})),await Promise.all(t.map(async r=>{await r.start()})),await Promise.all(t.map(async r=>{r.afterStart!=null&&await r.afterStart()}))}async function Ii(...e){let t=[];for(let r of e)_i(r)&&t.push(r);await Promise.all(t.map(async r=>{r.beforeStop!=null&&await r.beforeStop()})),await Promise.all(t.map(async r=>{await r.stop()})),await Promise.all(t.map(async r=>{r.afterStop!=null&&await r.afterStop()}))}function Bu(e){return typeof e?.handleEvent=="function"}function Tu(e){return e===!0||e===!1}function Du(e){return Tu(e)?e:e?.capture??!1}function go(e){let t={capture:Du(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function Bi(e,t){return go(e).capture===go(t).capture}var De=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let o=go(n);if(o?.signal?.aborted===!0)return;let s=u=>{o.once&&this.removeEventListener(t,r,o),Bu(r)?r.handleEvent(u):r(u)},i=this.#t.get(t);if(i==null&&(i=[],this.#t.set(t,i)),i.some(u=>u.callback!==r?!1:Bi(u.options,o)))return;super.addEventListener(t,s,o);let c=()=>{this.removeEventListener(t,r,o)};o.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:s,options:o,onAbort:c})}removeEventListener(t,r,n){let o=this.#t.get(t);if(o==null){super.removeEventListener(t,r??null,n);return}this.#t.set(t,o.filter(s=>s.callback===r&&Bi(s.options,n)?(super.removeEventListener(t,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Wr=Symbol.for("@libp2p/service-capabilities"),Xr=Symbol.for("@libp2p/service-dependencies");var Eo={};vt(Eo,{base58btc:()=>ot,base58flickr:()=>Fu});var Sp=new Uint8Array(0);function Di(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Bt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return fe(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return fe(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Ri(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var Ti=4096;function Li(e){let t=e.length;if(t<=Ti)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=Ti));return r}function Ru(e){return e?.buffer instanceof ArrayBuffer}function fe(e){return Ru(e)?e:e.slice()}function Lu(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<e.length;s++){var i=e.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=e.length,l=e.charAt(0),d=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function S(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var v=0,m=0,_=0,A=x.length;_!==A&&x[_]===0;)_++,v++;for(var P=(A-_)*p+1>>>0,F=new Uint8Array(P);_!==A;){for(var k=x[_],R=0,C=P-1;(k!==0||R<m)&&C!==-1;C--,R++)k+=256*F[C]>>>0,F[C]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");m=R,_++}for(var z=P-m;z!==P&&F[z]===0;)z++;for(var K=l.repeat(v);z<P;++z)K+=e.charAt(F[z]);return K}function b(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var v=0;if(x[v]!==" "){for(var m=0,_=0;x[v]===l;)m++,v++;for(var A=(x.length-v)*d+1>>>0,P=new Uint8Array(A);x[v];){var F=n[x.charCodeAt(v)];if(F===255)return;for(var k=0,R=A-1;(F!==0||k<_)&&R!==-1;R--,k++)F+=f*P[R]>>>0,P[R]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");_=k,v++}if(x[v]!==" "){for(var C=A-_;C!==A&&P[C]===0;)C++;for(var z=new Uint8Array(m+(A-C)),K=m;C!==A;)z[K++]=P[C++];return z}}}function y(x){var v=b(x);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:S,decodeUnsafe:b,decode:y}}var Cu=Lu,Ou=Cu,Oi=Ou;var yo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},bo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Pi(this,t)}},wo=class{decoders;constructor(t){this.decoders=t}or(t){return Pi(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Pi(e,t){return new wo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var xo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new yo(t,r,n),this.decoder=new bo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Re({name:e,prefix:t,encode:r,decode:n}){return new xo(e,t,r,n)}function Xt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Oi(r,e,n);return Re({prefix:t,name:e,encode:o,decode:i=>Bt(s(i))})}function Pu(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ku(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Nu(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let o=e[n].toLowerCase(),s=e[n].toUpperCase();o!==e[n]&&(r[o]=n),s!==e[n]&&(r[s]=n)}return r}function et({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Nu(n,o);return Re({prefix:t,name:e,encode(i){return ku(i,n,r)},decode(i){return Pu(i,s,r,e)}})}var ot=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Fu=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var So={};vt(So,{base32:()=>Qt,base32hex:()=>zu,base32hexpad:()=>Hu,base32hexpadupper:()=>$u,base32hexupper:()=>qu,base32pad:()=>Mu,base32padupper:()=>Ku,base32upper:()=>Uu,base32z:()=>Vu});var Qt=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Uu=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Mu=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Ku=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),zu=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),qu=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Hu=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),$u=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Vu=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var vo={};vt(vo,{base36:()=>cr,base36upper:()=>ju});var cr=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),ju=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Zu=Fi,ki=128,Yu=127,Gu=~Yu,Wu=Math.pow(2,31);function Fi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Wu;)t[r++]=e&255|ki,e/=128;for(;e&Gu;)t[r++]=e&255|ki,e>>>=7;return t[r]=e|0,Fi.bytes=r-n+1,t}var Xu=_o,Qu=128,Ni=127;function _o(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw _o.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ni)<<o:(i&Ni)*Math.pow(2,o),o+=7}while(i>=Qu);return _o.bytes=s-n,r}var Ju=Math.pow(2,7),tf=Math.pow(2,14),ef=Math.pow(2,21),rf=Math.pow(2,28),nf=Math.pow(2,35),of=Math.pow(2,42),sf=Math.pow(2,49),af=Math.pow(2,56),cf=Math.pow(2,63),uf=function(e){return e<Ju?1:e<tf?2:e<ef?3:e<rf?4:e<nf?5:e<of?6:e<sf?7:e<af?8:e<cf?9:10},ff={encode:Zu,decode:Xu,encodingLength:uf},lf=ff,ur=lf;function fr(e,t=0){let r=ur.decode(e,t),n=ur.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Le(e,t,r=0){return ur.encode(e,t,r),t}function Ce(e){return ur.encodingLength(e)}function Pe(e,t){let r=t.byteLength,n=Ce(e),o=n+Ce(r),s=new Uint8Array(o+r);return Le(e,s,0),Le(r,s,n),s.set(t,o),new Oe(e,r,t,s)}function lr(e){let t=Bt(e),[r,n]=fr(t),[o,s]=fr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Oe(r,o,i,t)}function Ui(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Di(e.bytes,r.bytes)}}var Oe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=fe(n),this.bytes=fe(o)}};function Mi(e,t){let{bytes:r,version:n}=e;return n===0?hf(r,Ao(e),t??ot.encoder):pf(r,Ao(e),t??Qt.encoder)}var Ki=new WeakMap;function Ao(e){let t=Ki.get(e);if(t==null){let r=new Map;return Ki.set(e,r),r}return t}var dt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=fe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==mf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Pe(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ui(t.multihash,n.multihash)}toString(t){return Mi(this,t)}toJSON(){return{"/":Mi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??zi(n,o,s.bytes))}else if(r[gf]===!0){let{version:n,multihash:o,code:s}=r,i=lr(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==dr)throw new Error(`Version 0 CID must use dag-pb (code: ${dr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=zi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,dr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Bt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Oe(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,d]=fr(t.subarray(r));return r+=d,l},o=n(),s=dr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=df(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ao(s).set(n,t),s}};function df(e,t){switch(e[0]){case"Q":{let r=t??ot;return[ot.prefix,r.decode(`${ot.prefix}${e}`)]}case ot.prefix:{let r=t??ot;return[ot.prefix,r.decode(e)]}case Qt.prefix:{let r=t??Qt;return[Qt.prefix,r.decode(e)]}case cr.prefix:{let r=t??cr;return[cr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function hf(e,t,r){let{prefix:n}=r;if(n!==ot.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function pf(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var dr=112,mf=18;function zi(e,t,r){let n=Ce(e),o=n+Ce(t),s=new Uint8Array(o+r.byteLength);return Le(e,s,0),Le(t,s,n),s.set(r,o),s}var gf=Symbol.for("@ipld/js-cid/CID");var Io={};vt(Io,{identity:()=>Pt});var qi=0,yf="identity",Hi=Bt;function bf(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Pe(qi,Hi(e))}var Pt={code:qi,name:yf,encode:Hi,digest:bf};function ht(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function wf(e){return e.buffer instanceof ArrayBuffer}function kt(e){return wf(e)?e:e.slice()}async function $i(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,kt(t),kt(r.subarray()));return n?.signal?.throwIfAborted(),s}function wt(e=0){return new Uint8Array(e)}function pt(e=0){return new Uint8Array(e)}function xf(e){return e?.buffer instanceof ArrayBuffer}function Bo(e){if(xf(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Kt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=pt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return Bo(r)}var ji=Symbol.for("@achingbrain/uint8arraylist");function Vi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Jr(e){return!!e?.[ji]}var ct=class e{bufs;length;[ji]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Jr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Jr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Vi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Vi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Jr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Kt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Kt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Jr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){f=Math.max(1,d-a[p]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=wt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=wt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ht(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var To={};vt(To,{base10:()=>Ef});var Ef=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Do={};vt(Do,{base16:()=>Sf,base16upper:()=>vf});var Sf=et({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),vf=et({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ro={};vt(Ro,{base2:()=>_f});var _f=et({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Lo={};vt(Lo,{base256emoji:()=>Df});var Zi=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Af=Zi.reduce((e,t,r)=>(e[r]=t,e),[]),If=Zi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Bf(e){return e.reduce((t,r)=>(t+=Af[r],t),"")}function Tf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=If[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Df=Re({prefix:"\u{1F680}",name:"base256emoji",encode:Bf,decode:Tf});var Oo={};vt(Oo,{base64:()=>Rf,base64pad:()=>Lf,base64url:()=>Co,base64urlpad:()=>Cf});var Rf=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Lf=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Co=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Cf=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Po={};vt(Po,{base8:()=>Of});var Of=et({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ko={};vt(ko,{identity:()=>Pf});var Pf=Re({prefix:"\0",name:"identity",encode:e=>Li(Bt(e)),decode:e=>Bt(Ri(e))});var a0=new TextEncoder,c0=new TextDecoder;var Uo={};vt(Uo,{sha256:()=>hr,sha512:()=>Uf});var Ff=20;function Fo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new No(e,t,r,n,o)}var No=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Ff,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Yi(n,this.code,r?.truncate):n.then(o=>Yi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Yi(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Pe(t,e)}function Wi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var hr=Fo({name:"sha2-256",code:18,encode:Wi("SHA-256")}),Uf=Fo({name:"sha2-512",code:19,encode:Wi("SHA-512")});var pr={...ko,...Ro,...Po,...To,...Do,...So,...vo,...Eo,...Oo,...Lo},x0={...Uo,...Io};function Qi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Xi=Qi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Mo=Qi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=pt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Mf={utf8:Xi,"utf-8":Xi,hex:pr.base16,latin1:Mo,ascii:Mo,binary:Mo,...pr},tn=Mf;function X(e,t="utf8"){let r=tn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function st(e,t="utf8"){let r=tn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Kf=parseInt("11111",2),Ko=parseInt("10000000",2),zf=parseInt("01111111",2),Ji={0:mr,1:mr,2:qf,3:Vf,4:jf,5:$f,6:Hf,16:mr,22:mr,48:mr};function zo(e,t={offset:0}){let r=e[t.offset]&Kf;if(t.offset++,Ji[r]!=null)return Ji[r](e,t);throw new Error("No decoder for tag "+r)}function gr(e,t){let r=0;if((e[t.offset]&Ko)===Ko){let n=e[t.offset]&zf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");o+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function mr(e,t){gr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=zo(e,t);if(n===null)break;r.push(n)}return r}function qf(e,t){let r=gr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Hf(e,t){let r=gr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function $f(e,t){return t.offset++,null}function Vf(e,t){let r=gr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function jf(e,t){let r=gr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Zf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ct;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function qo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Zf(e.byteLength);return new ct(Uint8Array.from([t.byteLength|Ko]),t)}function ta(e){let t=new ct,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ct(Uint8Array.from([2]),qo(t),t)}function ea(e){let t=Uint8Array.from([0]),r=new ct(t,e);return new ct(Uint8Array.from([3]),qo(r),r)}function en(e,t=48){let r=new ct;for(let n of e)r.append(n);return new ct(Uint8Array.from([t]),qo(r),r)}var Yf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Gf=Uint8Array.from([6,5,43,129,4,0,34]),Wf=Uint8Array.from([6,5,43,129,4,0,35]),Xf={ext:!0,kty:"EC",crv:"P-256"},Qf={ext:!0,kty:"EC",crv:"P-384"},Jf={ext:!0,kty:"EC",crv:"P-521"},Ho=32,$o=48,Vo=66;function ra(e){let t=zo(e);return na(t)}function na(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ho*2+1)return n=st(t.subarray(r,r+Ho),"base64url"),o=st(t.subarray(r+Ho),"base64url"),new ke({...Xf,key_ops:["verify"],x:n,y:o});if(t.byteLength===$o*2+1)return n=st(t.subarray(r,r+$o),"base64url"),o=st(t.subarray(r+$o),"base64url"),new ke({...Qf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Vo*2+1)return n=st(t.subarray(r,r+Vo),"base64url"),o=st(t.subarray(r+Vo),"base64url"),new ke({...Jf,key_ops:["verify"],x:n,y:o});throw new yt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function oa(e){return en([ta(Uint8Array.from([1])),en([tl(e.crv)],160),en([ea(new ct(Uint8Array.from([4]),X(e.x??"","base64url"),X(e.y??"","base64url")))],161)]).subarray()}function tl(e){if(e==="P-256")return Yf;if(e==="P-384")return Gf;if(e==="P-521")return Wf;throw new yt(`Invalid curve ${e}`)}var ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=oa(this.jwk)),this._raw}toMultihash(){return Pt.digest(Ne(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}async verify(t,r,n){return $i(this.jwk,r,t,n)}};var rn=BigInt(4294967295),sa=BigInt(32);function el(e,t=!1){return t?{h:Number(e&rn),l:Number(e>>sa&rn)}:{h:Number(e>>sa&rn)|0,l:Number(e&rn)|0}}function ia(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=el(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var rl=e=>e/2**32|0,nl=e=>e>>>0;function aa(e,t,r,n){let o=rl(r),s=nl(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var jo=(e,t,r)=>e>>>r,Zo=(e,t,r)=>e<<32-r|t>>>r,de=(e,t,r)=>e>>>r|t<<32-r,he=(e,t,r)=>e<<32-r|t>>>r,yr=(e,t,r)=>e<<64-r|t>>>r-32,br=(e,t,r)=>e>>>r-32|t<<64-r;function zt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ca=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ua=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,fa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),la=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,da=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ha=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function nn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Yo=e=>e?`"${e}" `:"";function Vt(e,t=""){if(typeof e!="number")throw new TypeError(Yo(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Yo(t)+"expected integer >= 0, got "+e);return e}function Tt(e,t,r=""){if(nn(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Vt(t,"length");let n=nn(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=Yo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function on(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Vt(e.outputLen),Vt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var sl=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},pa=(e,t)=>{sl(e,t);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function Fe(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function sn(e,t){Tt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function pe(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function an(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Nt(e,t){return e<<32-t|e>>>t}var ga=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",il=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function cn(e){if(Tt(e),ga)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=il[e[r]];return t}function ma(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function un(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(ga)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=ma(e.charCodeAt(s)),a=ma(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Go(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Tt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function al(e,t,r="opts"){return pa(e,"defaults"),t!==void 0&&pa(t,r),Object.assign(Object.create(null),e,t)}function Wo(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=al({},t,"info");let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function ya(e=32){Vt(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Xo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ba(e,t,r){return e&t^~e&r}function wa(e,t,r){return e&t^e&r^t&r}var wr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=an(this.buffer)}update(t){Fe(this),Tt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=an(t);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){Fe(this),sn(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),aa(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:an(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(r),t}clone(){return this._cloneInto()}},xa=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ea=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var cl=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jt=new Uint32Array(64),Qo=class extends wr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let l=0;l<16;l++,r+=4)Jt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=Jt[l-15],p=Jt[l-2],S=Nt(d,7)^Nt(d,18)^d>>>3,b=Nt(p,17)^Nt(p,19)^p>>>10;Jt[l]=b+Jt[l-7]+S+Jt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Nt(a,6)^Nt(a,11)^Nt(a,25),p=f+d+ba(a,c,u)+cl[l]+Jt[l]|0,b=(Nt(n,2)^Nt(n,13)^Nt(n,22))+wa(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+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,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){pe(Jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),pe(this.buffer)}},Jo=class extends Qo{constructor(){super(32,xa)}};var Sa=ia(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),ul=Sa[0],fl=Sa[1],te=new Uint32Array(80),ee=new Uint32Array(80),ts=class extends wr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:p,Gl:S,Hh:b,Hl:y}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,p,S,b,y]}set(t,r,n,o,s,i,a,c,u,f,l,d,p,S,b,y){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=S|0,this.Hh=b|0,this.Hl=y|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let m=0;m<16;m++,r+=4)te[m]=t.getUint32(r),ee[m]=t.getUint32(r+=4);for(let m=16;m<80;m++){let _=te[m-15]|0,A=ee[m-15]|0,P=de(_,A,1)^de(_,A,8)^jo(_,A,7),F=he(_,A,1)^he(_,A,8)^Zo(_,A,7),k=te[m-2]|0,R=ee[m-2]|0,C=de(k,R,19)^yr(k,R,61)^jo(k,R,6),z=he(k,R,19)^br(k,R,61)^Zo(k,R,6),K=fa(F,z,ee[m-7],ee[m-16]),Z=la(K,P,C,te[m-7],te[m-16]);te[m]=Z|0,ee[m]=K|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:S,Gh:b,Gl:y,Hh:x,Hl:v}=this;for(let m=0;m<80;m++){let _=de(l,d,14)^de(l,d,18)^yr(l,d,41),A=he(l,d,14)^he(l,d,18)^br(l,d,41),P=l&p^~l&b,F=d&S^~d&y,k=da(v,A,F,fl[m],ee[m]),R=ha(k,x,_,P,ul[m],te[m]),C=k|0,z=de(n,o,28)^yr(n,o,34)^yr(n,o,39),K=he(n,o,28)^br(n,o,34)^br(n,o,39),Z=n&s^n&a^s&a,B=o&i^o&c^i&c;x=b|0,v=y|0,b=p|0,y=S|0,p=l|0,S=d|0,{h:l,l:d}=zt(u|0,f|0,R|0,C|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let U=ca(C,K,B);n=ua(U,R,z,Z),o=U|0}({h:n,l:o}=zt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=zt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=zt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=zt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=zt(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:S}=zt(this.Fh|0,this.Fl|0,p|0,S|0),{h:b,l:y}=zt(this.Gh|0,this.Gl|0,b|0,y|0),{h:x,l:v}=zt(this.Hh|0,this.Hl|0,x|0,v|0),this.set(n,o,s,i,a,c,u,f,l,d,p,S,b,y,x,v)}roundClean(){pe(te,ee)}destroy(){this.destroyed=!0,pe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},es=class extends ts{constructor(){super(64,Ea)}};var va=Wo(()=>new Jo,Xo(1));var rs=Wo(()=>new es,Xo(3));function ln(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var $=(e,t,r)=>Tt(e,t,r),ns=Vt;function Aa(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function re(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function me(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var xr=cn,Dt=(...e)=>Go(...e),Ue=e=>un(e),oe=nn,ge=e=>ya(e),fn=BigInt(0),_a=BigInt(1),ll=e=>e?`"${e}" `:"";function xt(e,t=""){if(typeof e!="boolean")throw new TypeError(ll(t)+"expected boolean, got type="+typeof e);return e}function dn(e){if(typeof e=="bigint"){if(!ne(e))throw new RangeError("positive bigint expected, got "+e)}else ns(e);return e}function jt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function Er(e){let t=dn(e).toString(16);return t.length&1?"0"+t:t}function Ia(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?fn:BigInt("0x"+e)}function qt(e){return Ia(cn(e))}function ye(e){return Ia(cn(Sr(Tt(e)).reverse()))}function hn(e,t){if(Vt(t),t===0)throw new Error("zero output length is invalid");e=dn(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return un(n.padStart(r,"0"))}function os(e,t){return hn(e,t).reverse()}function Sr(e){return Uint8Array.from($(e))}function ne(e){return typeof e=="bigint"&&fn<=e}function ss(e,t,r){return ne(e)&&ne(t)&&ne(r)&&t<=e&&e<r}function Me(e,t,r,n){if(!ss(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ke(e){if(e<fn)throw new Error("expected non-negative bigint, got "+e);return e===fn?0:e.toString(2).length}var vr=e=>(jt(e,"n"),(_a<<BigInt(e))-_a);function Ba(e,t,r){if(Vt(e,"hashLen"),Vt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...y)=>r(u,Dt(c,...y)),p=(y=o)=>{u=d(s,y),c=d(),y.length!==0&&(u=d(i,y),c=d())},S=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,x=[];for(;y<t;){c=d();let v=c.slice();x.push(v),y+=c.length}return Dt(...x)};return(y,x)=>{l(),p(y);let v;for(;(v=x(S()))===void 0;)p();return l(),v}}function Et(e,t={},r={},n="object"){re(e,n),re(t,"fields"),re(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=e[i];if(!Object.hasOwn(e,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var it=BigInt(0),V=BigInt(1),se=BigInt(2),Ra=BigInt(3),is=BigInt(4),La=BigInt(5),dl=BigInt(7),Ca=BigInt(8),hl=BigInt(9),pl=BigInt(15),Oa=BigInt(16),ml=BigInt("0x10000000000000000");function tt(e,t){if(t<=it)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=it?r:t+r}function Pa(e,t,r){if(r<=V)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<it)throw new Error("invalid exponent, negatives unsupported");if(t===it)return V;if(t===V)return e;let n=e%r;if(n<it&&(n+=r),t<ml){let a=V;for(;t>it;)t&V&&(a=a*n%r),n=n*n%r,t>>=V;return a}let o=[];for(;t>it;)o.push(Number(t&pl)),t>>=is;let s=new Array(16);s[0]=V,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function Q(e,t,r){if(r<=V)throw new Error("pow2: expected modulus > 1, got "+r);if(t<it)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >it;)n*=n,n%=r;return n}function Ta(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=V)throw new Error("invert: expected modulus > 1, got "+t);let r=tt(e,t),n=t,o=it,s=V;for(;r!==it;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==V)throw new Error("invert: does not exist");return tt(o,t)}function ka(e,t){if(t<=V)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=tt(e,t);if(r===it)throw new Error("invertCt: expected non-zero number");let n=Pa(r,t-se,t);if(tt(r*n,t)!==V)throw new Error("invertCt: does not exist");return n}function as(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function cs(e,t){if((e&V)===it)throw new Error(t+": expected odd modulus, got "+e)}function Na(e,t){let r=e,n=(r.ORDER+V)/is,o=r.pow(t,n);return as(r,o,t),o}function gl(e,t){let r=e,n=(r.ORDER-La)/Ca,o=r.mul(t,se),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,se),s),c=r.mul(i,r.sub(a,r.ONE));return as(r,c,t),c}function yl(e){let t=qe(e),r=Fa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+dl)/Oa;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),p=u.mul(f,s),S=u.eql(u.sqr(l),c),b=u.eql(u.sqr(d),c);f=u.cmov(f,l,S),l=u.cmov(p,d,b);let y=u.eql(u.sqr(l),c),x=u.cmov(f,l,y);return as(u,x,c),x})}function Fa(e){if(e<Ra)throw new Error("sqrt is not defined for small field");cs(e,"tonelliShanks");let t=e-V,r=0;for(;t%se===it;)t/=se,r++;let n=se,o=qe(e);for(;_r(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Na;let s=o.pow(n,t),i=(t+V)/se;return function(c,u){let f=c;if(f.is0(u))return u;if(_r(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),p=f.pow(u,t),S=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let b=1,y=f.sqr(p);for(;!f.eql(y,f.ONE);)if(b++,y=f.sqr(y),b===l)throw new Error("Cannot find square root");let x=V<<BigInt(l-b-1),v=f.pow(d,x);l=b,d=f.sqr(v),p=f.mul(p,d),S=f.mul(S,v)}return S}}function bl(e){return cs(e,"Fp.sqrt"),e%is===Ra?Na:e%Ca===La?gl:e%Oa===hl?yl(e):Fa(e)}var Ua=(e,t)=>(tt(e,t)&V)===V,wl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ze(e){if(re(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);jt(e.BYTES,"BYTES"),jt(e.BITS,"BITS");for(let t of wl)me(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=V)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function mn(e,t,r=!1){ze(e),ln(t,"nums"),xt(r,"passZero");let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function _r(e,t){ze(e);let r=e;cs(r.ORDER,"FpLegendre");let n=(r.ORDER-V)/se,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function xl(e,t){if(t!==void 0&&ns(t),e<=it)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Ke(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Da=new WeakMap,pn=class{ORDER;BITS;BYTES;isLE;ZERO=it;ONE=V;_lengths;_mod;constructor(t,r={}){if(t<=V)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=xl(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return tt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return it<=t&&t<this.ORDER}is0(t){return t===it}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return Pa(t,r,this.ORDER)}div(t,r){return tt(t*Ta(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Ta(t,this.ORDER)}sqrt(t){let r=Da.get(this);return r||Da.set(this,r=bl(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?os(t,this.BYTES):hn(t,this.BYTES)}fromBytes(t,r=!1){$(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?ye(t):qt(t);if(a&&(c=tt(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return mn(this,t,!0)}cmov(t,r,n){return xt(n,"condition"),n?r:t}};function qe(e,t={}){return Object.freeze(pn.prototype),new pn(e,t)}function Ma(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=V)throw new Error("field order must be greater than 1");let t=Ke(e-V);return Math.ceil(t/8)}function gn(e){let t=Ma(e);return t+Math.ceil(t/2)}function yn(e,t,r=!1){$(e);let n=e.length,o=Ma(t),s=Math.max(gn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ye(e):qt(e),a=tt(i,t-V)+V;return r?os(a,o):hn(a,o)}var ls=BigInt(0),Ar=BigInt(1),El=BigInt(4),us=16,Ka=128,Sl=5,za=2**31;function ie(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);me(t.fromAffine,"Point.fromAffine"),me(t.fromBytes,"Point.fromBytes"),me(t.fromHex,"Point.fromHex"),re(t.BASE,"Point.BASE"),re(t.ZERO,"Point.ZERO"),ze(t.Fp),ze(t.Fn)}function bn(e,t){ie(e),Ha(t,e);let r=mn(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function vl(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function _l(e,t){let r=e*(4*t+128);if(r>za)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+za/2**20+" MiB")}function ds(e,t){if(e!==void 0){me(e,"randomBytes");try{let r=e(t);if(!oe(r)||r.length!==t)return}catch{return}return e}}function Ha(e,t){ln(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Al(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,o)=>{if(!(r===void 0?t.isValid(n):ne(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var $a=new WeakMap;function fs(e){return $a.get(e)||1}function Il(e,t){let r=e.double(),n=[e];for(let o=1;o<t;o++)n.push(n[o-1].add(r));return n}function Bl(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>ls;){let i=0;e&Ar&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=Ar}return s}function Tl(e,t,r){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&s);e>>=i,u>o&&(u-=n,e+=Ar),a.push(u)}if(e!==ls)throw new Error("invalid wnaf");return a}function Dl(e,t,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=e;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=t[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var He=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){ie(t),this.randomBytes=ds(r,us),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=t;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(t,r){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=Tl(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],d=f*i,p=Math.abs(l)-1,S=s[d];for(let y=1;y<i;y++)S=y===p?s[d+y]:S;let b=S.negate();l===0?u=u.add(s[d]):c=c.add(l<0?b:S)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===t&&a.bits===n);return i||(i=this.buildWnafTable(r,t,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!ss(r,Ar,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=fs(t);return s===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Ka,s=this.randomBytes(us);if(!oe(s)||s.length!==us)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+qt(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,r,n){let o=Sl,s=1<<o,i=vr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<o;p++)u=u.double();let l=Number(r>>BigInt(f*o)&i),d=a[0];for(let p=1;p<s;p++)d=p===l?a[p]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===Ar?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,o):this.mulCT(t,r,o)}mulUnsafe(t,r,n){if(this.assertPoint(t),!ne(r))throw new Error("invalid scalar");let o=fs(t);if(o===1||r>=this.Point.Fn.ORDER)return wn(this.Point,[t],[r],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(t,r){this.assertPoint(t),vl(r,this.bits);let n=Math.ceil((this.bits+Ka)/r)+1;_l(n*2**(r-1),this.Point.Fp.BYTES),$a.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return fs(t)!==1}};function wn(e,t,r,n=!1){if(ie(e),Ha(t,e),xt(n,"allowOversized"),Al(r,e.Fn,n?e.Fn.ORDER**El:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>Il(i,4)),s=r.map(i=>Bl(i,4));return Dl(e.ZERO,o,s)}function qa(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ze(t),t}else return qe(e,{isLE:r})}function xn(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);Et(r);for(let c of["p","n","h"]){let u=t[c];if(!(ne(u)&&u!==ls))throw new Error(`CURVE.${c} must be positive bigint`)}let o=qa(t.p,r.Fp,n),s=qa(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function En(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Sn=BigInt(0),vn=BigInt(1),_n=BigInt(2),Rl=BigInt(4),Va=BigInt(8);function Ll(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function ja(e,t={}){Et(t,{},{},"extraOpts");let r=t,n=xn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(_r(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(_r(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Et(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?ge:r.randomBytes,u=_n<<BigInt(o.BYTES*8)-vn;function f(v){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(v)}let l=r.uvRatio===void 0?(v,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,m))}}catch{return{isValid:!1,value:Sn}}}:r.uvRatio;if(!Ll(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=o.eql(i.a,o.neg(o.ONE))?v=>o.neg(v):o.eql(i.a,o.ONE)?v=>v:v=>o.mul(i.a,v);function p(v,m,_=!1){let A=_?vn:Sn;return Me("coordinate "+v,m,A,u),m}function S(v){if(!(v instanceof b))throw new Error("EdwardsPoint expected")}class b{static BASE=new b(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new b(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,_,A,P){this.X=p("x",m),this.Y=p("y",_),this.Z=p("z",A,!0),this.T=p("t",P),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof b)throw new Error("extended point not allowed");let{x:_,y:A}=m||{};return p("x",_),p("y",A),new b(_,A,o.ONE,o.mul(_,A))}static fromBytes(m,_=!1){let A=o.BYTES,{a:P,d:F}=i;m=Sr($(m,A,"point")),xt(_,"zip215");let k=Sr(m),R=m[A-1];k[A-1]=R&-129;let C=ye(k),z=_?u:o.ORDER;Me("point.y",C,Sn,z);let K=o.sqr(C),Z=o.sub(K,o.ONE),B=o.sub(o.mulN(F,K),P),{isValid:U,value:M}=l(Z,B);if(!U)throw new Error("bad point: invalid y coordinate");let L=f(M),Y=(R&128)!==0;if(!_&&o.is0(M)&&Y)throw new Error("bad point: x=0 and x_0=1");return Y!==L&&(M=o.neg(M)),b.fromAffine({x:M,y:C})}static fromHex(m,_=!1){return b.fromBytes(Ue(m),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=6,_=!0){return x.setWindowSize(this,m),_||this.multiply(_n),this}assertValidity(){let m=this,{a:_,d:A}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:P,Y:F,Z:k,T:R}=m,C=o.sqr(P),z=o.sqr(F),K=o.sqr(k),Z=o.sqr(K),B=o.mul(C,_),U=o.mul(o.add(B,z),K),M=o.add(Z,o.mul(A,o.mul(C,z)));if(!o.eql(U,M))throw new Error("bad point: equation left != right (1)");let L=o.mul(P,F),Y=o.mul(k,R);if(!o.eql(L,Y))throw new Error("bad point: equation left != right (2)")}equals(m){S(m);let{X:_,Y:A,Z:P}=this,{X:F,Y:k,Z:R}=m,C=o.mul(_,R),z=o.mul(F,P),K=o.mul(A,R),Z=o.mul(k,P);return o.eql(C,z)&&o.eql(K,Z)}is0(){return this.equals(b.ZERO)}negate(){return new b(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:m,Y:_,Z:A}=this,P=o.sqr(m),F=o.sqr(_),k=o.mul(o.sqr(A),_n),R=d(P),C=o.addN(m,_),z=o.sub(o.subN(o.sqr(C),P),F),K=o.addN(R,F),Z=o.subN(K,k),B=o.subN(R,F),U=o.mul(z,Z),M=o.mul(K,B),L=o.mul(z,B),Y=o.mul(Z,K);return new b(U,M,Y,L)}add(m){S(m);let{d:_}=i,{X:A,Y:P,Z:F,T:k}=this,{X:R,Y:C,Z:z,T:K}=m,Z=o.mul(A,R),B=o.mul(P,C),U=o.mul(o.mulN(k,_),K),M=o.mul(F,z),L=o.sub(o.subN(o.mulN(o.addN(A,P),o.addN(R,C)),Z),B),Y=o.subN(M,U),J=o.addN(M,U),E=o.sub(B,d(Z)),h=o.mul(L,Y),g=o.mul(J,E),w=o.mul(L,E),I=o.mul(Y,J);return new b(h,g,I,w)}subtract(m){return S(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:_,f:A}=x.mulSecret(this,m,a,y);return y([_,A])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===Sn?b.ZERO:this.is0()||m===vn?this:x.mulUnsafe(this,m,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(m){let _=this,A=m;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:P,Y:F,Z:k}=_,R=_.is0();A==null&&(A=R?o.create(Va):o.inv(k));let C=o.mul(P,A),z=o.mul(F,A),K=o.mul(k,A);if(R)return{x:o.ZERO,y:o.ONE};if(!o.eql(K,o.ONE))throw new Error("invZ was invalid");return{x:C,y:z}}clearCofactor(){return a===vn?this:a===_n?this.double():a===Rl?this.double().double():a===Va?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:m,y:_}=this.toAffine(),A=o.toBytes(_);return A[A.length-1]|=f(m)?128:0,A}toHex(){return xr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=v=>bn(b,v),x=new He(b,c);return x.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function Za(e,t,r={}){if(ie(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Et(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(jt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?ge:o.randomBytes,d=o.toMontgomery,p=o.toMontgomerySecret,S=o.adjustScalarBytes===void 0?B=>B:o.adjustScalarBytes,b=o.domain===void 0?(B,U,M)=>{if(xt(M,"phflag"),U.length||M)throw new Error("Contexts/pre-hash are not supported");return B}:o.domain;function y(B){return c.create(ye(B))}function x(B){let U=R.secretKey;$(B,R.secretKey,"secretKey");let M=$(n(B),2*U,"hashedSecretKey"),L=S(M.slice(0,U)),Y=M.slice(U,2*U),J=y(L);return{head:L,prefix:Y,scalar:J}}function v(B){let{head:U,prefix:M,scalar:L}=x(B),Y=i.multiply(L),J=Y.toBytes();return{head:U,prefix:M,scalar:L,point:Y,pointBytes:J}}function m(B){return v(B).pointBytes}function _(B=Uint8Array.of(),...U){let M=Dt(...U);return y(n(b(M,$(B,void 0,"context"),!!s)))}function A(B,U,M={}){Et(M,{},{},"options"),B=Sr($(B,void 0,"message")),s&&(B=s(B));let{prefix:L,scalar:Y,pointBytes:J}=v(U),E=_(M.context,L,B),h=i.multiply(E).toBytes(),g=_(M.context,h,J,B),w=c.create(E+g*Y);if(!c.isValid(w))throw new Error("sign failed: invalid s");let I=Dt(h,c.toBytes(w));return $(I,R.signature,"result")}let P={zip215:o.zip215};function F(B,U,M,L=P){Et(L);let{context:Y}=L,J=L.zip215===void 0?!!P.zip215:L.zip215,E=R.signature;B=$(B,E,"signature"),U=$(U,void 0,"message"),M=$(M,R.publicKey,"publicKey"),J!==void 0&&xt(J,"zip215"),s&&(U=s(U));let h=E/2,g=B.subarray(0,h),w=ye(B.subarray(h,E)),I,T,D;try{I=e.fromBytes(M,J),T=e.fromBytes(g,J),D=i.multiplyUnsafe(w)}catch{return!1}if(!J&&I.isSmallOrder())return!1;let O=_(Y,g,M,U);return T.add(I.multiplyUnsafe(O)).subtract(D).clearCofactor().is0()}let k=a.BYTES,R={secretKey:k,publicKey:k,signature:2*k,seed:k};function C(B){return B=B===void 0?l(R.seed):B,$(B,R.seed,"seed")}function z(B){return oe(B)&&B.length===R.secretKey}function K(B,U){try{return!!e.fromBytes(B,U===void 0?P.zip215:U)}catch{return!1}}let Z={getExtendedPublicKey:v,randomSecretKey:C,isValidSecretKey:z,isValidPublicKey:K,toMontgomery(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(e.fromBytes(B))},toMontgomerySecret(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(B)}};return Object.freeze(R),Object.freeze(Z),Object.freeze({keygen:En(C,m),getPublicKey:m,sign:A,verify:F,utils:Z,Point:e,lengths:R})}var hs=BigInt(1),Ya=BigInt(2);var Cl=BigInt(5),Ol=BigInt(8),ps=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Pl={p:ps,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ol,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function kl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ps,a=e*e%s*e%s,c=Q(a,Ya,s)*a%s,u=Q(c,hs,s)*e%s,f=Q(u,Cl,s)*u%s,l=Q(f,t,s)*f%s,d=Q(l,r,s)*l%s,p=Q(d,n,s)*d%s,S=Q(p,o,s)*p%s,b=Q(S,o,s)*p%s,y=Q(b,t,s)*f%s;return{pow_p_5_8:Q(y,Ya,s)*e%s,b2:a}}function Xa(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ga=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Nl(e,t){let r=ps,n=tt(t*t*t,r),o=tt(n*n*t,r),s=kl(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,u=tt(i*Ga,r),f=a===e,l=a===tt(-e,r),d=a===tt(-e*Ga,r);return f&&(i=c),(l||d)&&(i=u),Ua(i,r)&&(i=tt(-i,r)),{isValid:f||l,value:i}}var ms=ja(Pl,{uvRatio:Nl}),Wa=ms.Fp;function Fl(e){let{y:t}=e;return Wa.toBytes(Wa.div(hs+t,hs-t))}function Ul(e){let t=ms.Fp.BYTES;return Tt(e,t),Xa(rs(e.subarray(0,t))).subarray(0,t)}function Ml(e){return Za(ms,rs,Object.assign({adjustScalarBytes:Xa,toMontgomery:Fl,toMontgomerySecret:Ul,zip215:!0},e))}var Qa=Ml({});var Ir=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},An=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var In={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new An("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Bn=32;var gs,Kl=(async()=>{try{return await In.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function zl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await In.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await In.get().subtle.verify({name:"Ed25519"},n,kt(t),kt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ql(e,t,r){return Qa.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ja(e,t,r){return gs==null&&(gs=await Kl),gs?zl(e,t,r):ql(e,t,r)}function Tn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Dn=class{type="Ed25519";raw;constructor(t){this.raw=ys(t,Bn)}toMultihash(){return Pt.digest(Ne(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ja(this.raw,r,t);return Tn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ec(e){return e=ys(e,Bn),new Dn(e)}function ys(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new yt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var $l=Math.pow(2,7),Vl=Math.pow(2,14),jl=Math.pow(2,21),bs=Math.pow(2,28),ws=Math.pow(2,35),xs=Math.pow(2,42),Es=Math.pow(2,49),j=128,mt=127;function St(e){if(e<$l)return 1;if(e<Vl)return 2;if(e<jl)return 3;if(e<bs)return 4;if(e<ws)return 5;if(e<xs)return 6;if(e<Es)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $e(e,t,r=0){switch(St(e)){case 8:t[r++]=e&255|j,e/=128;case 7:t[r++]=e&255|j,e/=128;case 6:t[r++]=e&255|j,e/=128;case 5:t[r++]=e&255|j,e/=128;case 4:t[r++]=e&255|j,e>>>=7;case 3:t[r++]=e&255|j,e>>>=7;case 2:t[r++]=e&255|j,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Zl(e,t,r=0){switch(St(e)){case 8:t.set(r++,e&255|j),e/=128;case 7:t.set(r++,e&255|j),e/=128;case 6:t.set(r++,e&255|j),e/=128;case 5:t.set(r++,e&255|j),e/=128;case 4:t.set(r++,e&255|j),e>>>=7;case 3:t.set(r++,e&255|j),e>>>=7;case 2:t.set(r++,e&255|j),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Ss(e,t){let r=e[t],n=0;if(n+=r&mt,r<j||(r=e[t+1],n+=(r&mt)<<7,r<j)||(r=e[t+2],n+=(r&mt)<<14,r<j)||(r=e[t+3],n+=(r&mt)<<21,r<j)||(r=e[t+4],n+=(r&mt)*bs,r<j)||(r=e[t+5],n+=(r&mt)*ws,r<j)||(r=e[t+6],n+=(r&mt)*xs,r<j)||(r=e[t+7],n+=(r&mt)*Es,r<j))return n;throw new RangeError("Could not decode varint")}function Yl(e,t){let r=e.get(t),n=0;if(n+=r&mt,r<j||(r=e.get(t+1),n+=(r&mt)<<7,r<j)||(r=e.get(t+2),n+=(r&mt)<<14,r<j)||(r=e.get(t+3),n+=(r&mt)<<21,r<j)||(r=e.get(t+4),n+=(r&mt)*bs,r<j)||(r=e.get(t+5),n+=(r&mt)*ws,r<j)||(r=e.get(t+6),n+=(r&mt)*xs,r<j)||(r=e.get(t+7),n+=(r&mt)*Es,r<j))return n;throw new RangeError("Could not decode varint")}function rc(e,t,r=0){return t==null&&(t=pt(St(e))),t instanceof Uint8Array?$e(e,t,r):Zl(e,t,r)}function Br(e,t=0){return e instanceof Uint8Array?Ss(e,t):Yl(e,t)}var vs=new Float32Array([-0]),ae=new Uint8Array(vs.buffer);function oc(e,t,r){vs[0]=e,t[r]=ae[0],t[r+1]=ae[1],t[r+2]=ae[2],t[r+3]=ae[3]}function sc(e,t){return ae[0]=e[t],ae[1]=e[t+1],ae[2]=e[t+2],ae[3]=e[t+3],vs[0]}var _s=new Float64Array([-0]),gt=new Uint8Array(_s.buffer);function ic(e,t,r){_s[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function ac(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],_s[0]}var Gl=BigInt(Number.MAX_SAFE_INTEGER),Wl=BigInt(Number.MIN_SAFE_INTEGER),_t=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return be;if(t<Gl&&t>Wl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>cc&&(o=0n,++n>cc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return be;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):be}},be=new _t(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var cc=4294967296n;function uc(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function fc(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function As(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Ft(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Rn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Is=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=kt(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,Ft(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 Ft(this,4);return Rn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ft(this,4);return Rn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ft(this,4);let t=sc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ft(this,4);let t=ac(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Ft(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return fc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ft(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ft(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 _t(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ft(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Ft(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ft(this,8);let t=Rn(this.buf,this.pos+=4),r=Rn(this.buf,this.pos+=4);return new _t(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ss(this.buf,this.pos);return this.pos+=St(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 Tr(e){return new Is(e instanceof Uint8Array?e:e.subarray())}function Rt(e,t,r){let n=Tr(e);return t.decode(n,void 0,r)}function Bs(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return pt(i);o+i>t&&(n=pt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var we=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ts(){}var Rs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Xl=Bs();function Ql(e){return globalThis.Buffer!=null?pt(e):Xl(e)}var Rr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(Ts,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new we(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ls((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(Ln,10,_t.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=_t.fromBigInt(t);return this._push(Ln,r.length(),r)}uint64Number(t){return this._push($e,St(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=_t.fromBigInt(t).zzEncode();return this._push(Ln,r.length(),r)}sint64Number(t){let r=_t.fromNumber(t).zzEncode();return this._push(Ln,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ds,1,t?1:0)}fixed32(t){return this._push(Dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=_t.fromBigInt(t);return this._push(Dr,4,r.lo)._push(Dr,4,r.hi)}fixed64Number(t){let r=_t.fromNumber(t);return this._push(Dr,4,r.lo)._push(Dr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(oc,4,t)}double(t){return this._push(ic,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ds,1,0):this.uint32(r)._push(td,r,t)}string(t){let r=uc(t);return r!==0?this.uint32(r)._push(As,r,t):this._push(Ds,1,0)}fork(){return this.states=new Rs(this),this.head=this.tail=new we(Ts,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 we(Ts,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Ql(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ds(e,t,r){t[r]=e&255}function Jl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ls=class extends we{next;constructor(t,r){super(Jl,t,r),this.next=void 0}};function Ln(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Dr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function td(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Rr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(ed,t,e),this},Rr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(rd,t,e),this});function ed(e,t,r){t.set(e,r)}function rd(e,t,r){e.length<40?As(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(X(e),r)}function Cs(){return new Rr}function Lt(e,t){let r=Cs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Ct(e,t,r){let n=Tr(e);yield*t.stream(n,void 0,"$",r)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function On(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function xe(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return On("enum",Cn.VARINT,r,n,o)}function Ot(e,t,r){return On("message",Cn.LENGTH_DELIMITED,e,t,r)}var Lr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var bt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(bt||(bt={}));var Os;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Os||(Os={}));(function(e){e.codec=()=>xe(Os)})(bt||(bt={}));var Cr;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),bt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:bt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(Cr||(Cr={}));var Ps;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),bt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:bt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(Ps||(Ps={}));var Pn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(on(t),Tt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),pe(o)}update(t){return Fe(this),this.iHash.update(t),this}digestInto(t){Fe(this),sn(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.canXOF=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},dc=(()=>{let e=((t,r,n)=>new Pn(t,r).update(n).digest());return e.create=(t,r)=>new Pn(t,r),e})();var od=BigInt(0),ks=class extends Error{constructor(t=""){super(t)}},Zt={Err:ks,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(jt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(Aa(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Er(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Er(o.length/2|128):"";return Er(e)+s+o+t},decode(e,t){let{Err:r}=Zt;t=$(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Zt;if(dn(e),e<od)throw new t("integer: negative integers are not allowed");let r=Er(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Zt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return qt(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:o}=Zt;if(t!==void 0&&(jt(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=$(e,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||f.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt;Et(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},kn=(Object.freeze(Zt._tlv),Object.freeze(Zt._int),Object.freeze(Zt));var hc=(e,t)=>(e+(e>=0?t:-t)/pc)/t;function sd(e,t,r){Me("scalar",e,Yt,r);let[[n,o],[s,i]]=t,a=hc(i*e,r),c=hc(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<Yt,d=f<Yt;l&&(u=-u),d&&(f=-f);let p=vr(Math.ceil(Ke(r)/2))+Ee;if(u<Yt||u>=p||f<Yt||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Us(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ns(e,t){Et(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return xt(r.lowS,"lowS"),xt(r.prehash,"prehash"),r.format!==void 0&&Us(r.format),r}var Yt=BigInt(0),Ee=BigInt(1),pc=BigInt(2),Fs=BigInt(3),id=BigInt(4);function mc(e,t={}){let r=xn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Et(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:d,toBytes:p}=t,S=t.randomBytes===void 0?ge:t.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=c?{beta:c.beta,basises:c.basises.map(E=>[...E])}:void 0,y=yc(n,o);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function v(E,h,g){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:w,y:I}=h.toAffine(),T=n.toBytes(w);if(xt(g,"isCompressed"),g){x();let D=!n.isOdd(I);return Dt(gc(D),T)}else return Dt(Uint8Array.of(4),T,n.toBytes(I))}function m(E){$(E,void 0,"Point");let{publicKey:h,publicKeyUncompressed:g}=y,w=E.length,I=E[0],T=E.subarray(1);if(u&&w===1&&I===0)return{x:n.ZERO,y:n.ZERO};if(w===h&&(I===2||I===3)){let D=n.fromBytes(T);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let O=k(D),N;try{N=n.sqrt(O)}catch(rt){let G=rt instanceof Error?": "+rt.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}x();let H=n.isOdd(N);return(I&1)===1!==H&&(N=n.neg(N)),{x:D,y:N}}else if(w===g&&I===4){let D=n.BYTES,O=n.fromBytes(T.subarray(0,D)),N=n.fromBytes(T.subarray(D,D*2));if(!R(O,N))throw new Error("bad point: is not on curve");return{x:O,y:N}}else throw new Error(`bad point: got length ${w}, expected compressed=${h} or uncompressed=${g}`)}let _=p===void 0?v:p,A=d===void 0?m:d,P=n.mul(s.b,Fs),F=n.is0(s.a)?E=>n.ZERO:E=>n.mul(s.a,E);function k(E){let h=n.sqr(E),g=n.mul(h,E);return n.add(n.add(g,n.mul(E,s.a)),s.b)}function R(E,h){let g=n.sqr(h),w=k(E);return n.eql(g,w)}if(!R(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let C=n.mul(n.pow(s.a,Fs),id),z=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(C,z)))throw new Error("bad curve params: a or b");function K(E,h,g=!1){if(!n.isValid(h)||g&&n.is0(h))throw new Error(`bad point coordinate ${E}`);return typeof h=="object"&&h!==null?n.create(h):h}function Z(E){if(!(E instanceof L))throw new Error("Weierstrass Point expected")}function B(E){if(!b||!b.basises)throw new Error("no endo");return sd(E,b.basises,o.ORDER)}function U(E,h,g,w){if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:I,k1:T,k2neg:D,k2:O}=B(w),N=new L(n.mul(g.X,b.beta),g.Y,g.Z);E.push(I?g.negate():g,D?N.negate():N),h.push(T,O)}else E.push(g),h.push(w)}let M=new WeakSet;class L{static BASE=new L(s.Gx,s.Gy,n.ONE);static ZERO=new L(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,g,w){this.X=K("x",h),this.Y=K("y",g,!0),this.Z=K("z",w),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:g,y:w}=h||{};if(!h||!n.isValid(g)||!n.isValid(w))throw new Error("invalid affine point");if(h instanceof L)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(w)?L.ZERO:new L(g,w,n.ONE)}static fromBytes(h){let g=L.fromAffine(A($(h,void 0,"point")));return g.assertValidity(),g}static fromHex(h){return L.fromBytes(Ue(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,g=!0){return J.setWindowSize(this,h),g||this.multiply(Fs),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(M.has(h))return;let{x:g,y:w}=h.toAffine();if(!n.isValid(g)||!n.isValid(w))throw new Error("bad point: x or y not field elements");if(!R(g,w))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");M.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){Z(h);let{X:g,Y:w,Z:I}=this,{X:T,Y:D,Z:O}=h,N=n.eql(n.mul(g,O),n.mul(T,I)),H=n.eql(n.mul(w,O),n.mul(D,I));return N&&H}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:g,Z:w}=this,I=n.ZERO,T=n.ZERO,D=n.ZERO,O=n.mul(h,h),N=n.mul(g,g),H=n.mul(w,w),q=n.mul(h,g);return q=n.add(q,q),D=n.mul(h,w),D=n.add(D,D),I=F(D),T=n.mul(P,H),T=n.add(I,T),I=n.sub(N,T),T=n.add(N,T),T=n.mul(I,T),I=n.mul(q,I),D=n.mul(P,D),H=F(H),q=n.sub(O,H),q=F(q),q=n.add(q,D),D=n.add(O,O),O=n.add(D,O),O=n.add(O,H),O=n.mul(O,q),T=n.add(T,O),H=n.mul(g,w),H=n.add(H,H),O=n.mul(H,q),I=n.sub(I,O),D=n.mul(H,N),D=n.add(D,D),D=n.add(D,D),new L(I,T,D)}add(h){Z(h);let{X:g,Y:w,Z:I}=this,{X:T,Y:D,Z:O}=h,N=n.ZERO,H=n.ZERO,q=n.ZERO,rt=n.mul(g,T),G=n.mul(w,D),at=n.mul(I,O),At=n.add(g,w),W=n.add(T,D);At=n.mul(At,W),W=n.add(rt,G),At=n.sub(At,W),W=n.add(g,I);let nt=n.add(T,O);return W=n.mul(W,nt),nt=n.add(rt,at),W=n.sub(W,nt),nt=n.add(w,I),N=n.add(D,O),nt=n.mul(nt,N),N=n.add(G,at),nt=n.sub(nt,N),q=F(W),N=n.mul(P,at),q=n.add(N,q),N=n.sub(G,q),q=n.add(G,q),H=n.mul(N,q),G=n.add(rt,rt),G=n.add(G,rt),at=F(at),W=n.mul(P,W),G=n.add(G,at),at=n.sub(rt,at),at=F(at),W=n.add(W,at),rt=n.mul(G,W),H=n.add(H,rt),rt=n.mul(nt,W),N=n.mul(At,N),N=n.sub(N,rt),rt=n.mul(At,G),q=n.mul(nt,q),q=n.add(q,rt),new L(N,H,q)}subtract(h){return Z(h),this.add(h.negate())}is0(){return this.equals(L.ZERO)}multiply(h){if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:g,f:w}=J.mulSecret(this,h,i,Y);return Y([g,w])[0]}multiplyUnsafe(h){let g=this,w=h;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Yt||g.is0())return L.ZERO;if(w===Ee)return g;if(J.hasWindowSize(this))return J.mulUnsafe(g,w,Y);let I=[],T=[];return U(I,T,g,w),wn(L,I,T)}mulAddUnsafe(h,g,w){Z(g);let I=[],T=[];return U(I,T,this,h),U(I,T,g,w),wn(L,I,T)}toAffine(h){let g=this,w=h;if(w!=null&&!n.isValid(w))throw new RangeError('"invertedZ" expected valid field element');let{X:I,Y:T,Z:D}=g;if(n.eql(D,n.ONE))return{x:I,y:T};let O=g.is0();w==null&&(w=O?n.ONE:n.inv(D));let N=n.mul(I,w),H=n.mul(T,w),q=n.mul(D,w);if(O)return{x:n.ZERO,y:n.ZERO};if(!n.eql(q,n.ONE))throw new Error("invZ was invalid");return{x:N,y:H}}isTorsionFree(){return i===Ee?!0:l?l(L,this):J.mulUnsafe(this,a).is0()}clearCofactor(){return i===Ee?this:f?f(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Ee?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return xt(h,"isCompressed"),this.assertValidity(),_(L,this,h)}toHex(h=!0){return xr(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Y=E=>bn(L,E),J=new He(L,S);return J.bits>=6&&L.BASE.precompute(6),Object.freeze(L.prototype),Object.freeze(L),L}function gc(e){return Uint8Array.of(e?2:3)}function yc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ad(e,t={}){ie(e);let{Fn:r}=e,n=t.randomBytes===void 0?ge:t.randomBytes,o=Object.assign(yc(e.Fp,r),{seed:Math.max(gn(r.ORDER),16)});function s(p){try{let S=r.fromBytes(p);return r.isValidNot0(S)}catch{return!1}}function i(p,S){let{publicKey:b,publicKeyUncompressed:y}=o;try{let x=p.length;return S===!0&&x!==b||S===!1&&x!==y?!1:!e.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,yn($(p,o.seed,"seed"),r.ORDER)}function c(p,S=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(S)}function u(p){let{secretKey:S,publicKey:b,publicKeyUncompressed:y}=o,x=r._lengths;if(!oe(p))return;let v=$(p,void 0,"key").length,m=v===b||v===y,_=v===S||!!x?.includes(v);if(!(m&&_))return m}function f(p,S,b=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(S)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(p),x=e.fromBytes(S);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(y).toBytes(b)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=En(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:e,utils:l,lengths:o})}function bc(e,t,r={}){ie(e);let n=t;on(n),Et(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?ge:o.randomBytes,i=o.hmac===void 0?(E,h)=>dc(n,E,h):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,l=gn(u),d=ds(s,l),{keygen:p,getPublicKey:S,getSharedSecret:b,utils:y,lengths:x}=ad(e,o),v={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},m=u*pc+Ee<a.ORDER;function _(E){let h=u>>Ee;return E>h}function A(E,h){if(!c.isValidNot0(h))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return h}function P(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function F(E,h,g){return P(),(E===g?0:2)|Number(a.isOdd(h))}function k(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(E,h){Us(h);let g=x.signature,w=h==="compact"?g:h==="recovered"?g+1:void 0;return $(E,w)}class C{r;s;recovery;constructor(h,g,w){if(this.r=A("r",h),this.s=A("s",g),w!=null){if(k(),![0,1,2,3].includes(w))throw new Error("invalid recovery id");this.recovery=w}Object.freeze(this)}static fromBytes(h,g=v.format){R(h,g);let w;if(g==="der"){if(h.length>2*c.BYTES+16)throw new kn.Err("invalid signature: DER signature too long");let{r:O,s:N}=kn.toSig($(h),c.BYTES+1);return new C(O,N)}g==="recovered"&&(w=h[0],g="compact",h=h.subarray(1));let I=x.signature/2,T=h.subarray(0,I),D=h.subarray(I,I*2);return new C(c.fromBytes(T),c.fromBytes(D),w)}static fromHex(h,g){return this.fromBytes(Ue(h),g)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new C(this.r,this.s,h)}recoverPublicKey(h){let{r:g,s:w}=this,I=this.assertRecovery(),T=I===2||I===3?g+u:g;if(!a.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=a.toBytes(T),O=e.fromBytes(Dt(gc((I&1)===0),D)),N=c.inv(T),H=K($(h,void 0,"msgHash")),q=c.create(-H*N),rt=c.create(w*N),G=e.BASE.mulAddUnsafe(q,O,rt);if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return _(this.s)}toBytes(h=v.format){if(Us(h),h==="der")return Ue(kn.hexFromSig(this));let{r:g,s:w}=this,I=c.toBytes(g),T=c.toBytes(w);return h==="recovered"?(k(),Dt(Uint8Array.of(this.assertRecovery()),I,T)):Dt(I,T)}toHex(h){return xr(this.toBytes(h))}}Object.freeze(C.prototype),Object.freeze(C);let z=o.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let g=qt(h),w=h.length*8-f;return w>0?g>>BigInt(w):g}:o.bits2int,K=o.bits2int_modN===void 0?function(h){return c.create(z(h))}:o.bits2int_modN,Z=vr(f);function B(E){return Me("num < 2^"+f,E,Yt,Z),c.toBytes(E)}function U(E,h){return $(E,void 0,"message"),h?$(n(E),void 0,"prehashed message"):E}function M(E,h,g){let{lowS:w,prehash:I,extraEntropy:T}=Ns(g,v);E=U(E,I);let D=K(E),O=c.fromBytes(h);if(!c.isValidNot0(O))throw new Error("invalid private key");let N=[B(O),B(D)];if(T!=null&&T!==!1){let G=T===!0?s(x.secretKey):T;N.push($(G,void 0,"extraEntropy"))}let H=Dt(...N),q=D;function rt(G){let at=z(G);if(!c.isValidNot0(at))return;let At=e.BASE.multiply(at).toAffine(),W=c.create(At.x);if(W===Yt)return;let nt;if(d!==void 0){let ir=qt(yn(d(l),u)),yu=c.inv(c.mul(ir,at)),bu=c.mul(ir,q),wu=c.mul(ir,O);nt=c.create(yu*c.create(bu+wu*W))}else{let ir=ka(at,u);nt=c.create(ir*c.create(q+W*O))}if(nt===Yt)return;let ho=F(At.x,At.y,W),Si=nt;return w&&_(nt)&&(Si=c.neg(nt),ho^=1),new C(W,Si,m?void 0:ho)}return{seed:H,k2sig:rt}}function L(E,h,g={}){let{seed:w,k2sig:I}=M(E,h,g);return Ba(n.outputLen,c.BYTES,i)(w,I).toBytes(g.format)}function Y(E,h,g,w={}){let{lowS:I,prehash:T,format:D}=Ns(w,v);if(g=$(g,void 0,"publicKey"),h=U(h,T),!oe(E)){let O=E instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}R(E,D);try{let O=C.fromBytes(E,D),N=e.fromBytes(g);if(N.is0()||I&&O.hasHighS())return!1;let{r:H,s:q}=O,rt=K(h),G=c.inv(q),at=c.create(rt*G),At=c.create(H*G),W=e.BASE.mulAddUnsafe(at,N,At);if(W.is0())return!1;let nt=W.toAffine();return!(c.create(nt.x)!==H||D==="recovered"&&O.recovery!==F(nt.x,nt.y,H))}catch{return!1}}function J(E,h,g={}){let{prehash:w}=Ns(g,v);return h=U(h,w),C.fromBytes(E,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:p,getPublicKey:S,getSharedSecret:b,utils:y,lengths:x,Point:e,sign:L,verify:Y,recoverPublicKey:J,Signature:C,hash:n})}var Ks={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},cd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var wc=BigInt(2);function ud(e){let t=Ks.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=Q(f,r,t)*f%t,d=Q(l,r,t)*f%t,p=Q(d,wc,t)*u%t,S=Q(p,o,t)*p%t,b=Q(S,s,t)*S%t,y=Q(b,a,t)*b%t,x=Q(y,c,t)*y%t,v=Q(x,a,t)*b%t,m=Q(v,r,t)*f%t,_=Q(m,i,t)*S%t,A=Q(_,n,t)*u%t,P=Q(A,wc,t);if(!Ms.eql(Ms.sqr(P),e))throw new Error("Cannot find square root");return P}var Ms=qe(Ks.p,{sqrt:ud}),fd=mc(Ks,{Fp:Ms,endo:cd}),Ve=bc(fd,va);function xc(e,t,r,n){let o=hr.digest(r instanceof Uint8Array?r:r.subarray());if(Tn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ir(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Ir(String(s))}}var Nn=class{type="secp256k1";raw;_key;constructor(t){this._key=Sc(t),this.raw=Ec(this._key)}toMultihash(){return Pt.digest(Ne(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,r,n){return xc(this._key,r,t,n)}};function vc(e){return new Nn(e)}function Ec(e){return Ve.Point.fromBytes(e).toBytes()}function Sc(e){try{return Ve.Point.fromBytes(e),e}catch(t){throw new Zr(String(t))}}function _c(e){let{Type:t,Data:r}=Cr.decode(e.digest),n=r??new Uint8Array;switch(t){case bt.Ed25519:return ec(n);case bt.secp256k1:return vc(n);case bt.ECDSA:return ra(n);default:throw new ar}}function Ne(e){return Cr.encode({Type:bt[e.type],Data:e.raw})}var Ac=Symbol.for("nodejs.util.inspect.custom"),ld=114,Or=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()})`}[mo]=!0;toString(){return this.string==null&&(this.string=ot.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(ld,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")}[Ac](){return`PeerId(${this.toString()})`}},Fn=class extends Or{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Un=class extends Or{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Mn=class extends Or{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},dd=2336,Kn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Pt.digest(X(this.url))}[Ac](){return`PeerId(${this.url})`}[mo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(dd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=st(t)),t.toString()===this.toString())}};function Ic(e){if(pd(e))return new Fn({multihash:e});if(hd(e))try{let t=_c(e);if(t.type==="Ed25519")return new Un({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Mn({multihash:e,publicKey:t})}catch{let r=st(e.digest);return new Kn(new URL(r))}throw new Gr("Supplied PeerID Multihash is invalid")}function hd(e){return e.code===Pt.code}function pd(e){return e.code===hr.code}function zs(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function zn(e){let t=lr(ot.decode(`z${e}`));return Ic(t)}var qn=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return zs(this.set.entries(),t=>{let r=zn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=zn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return zs(this.set.values(),t=>zn(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function qs(){return new qn}var Hs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Bc={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Tc=new globalThis.TextEncoder;function md(e,t){let r=Hs[t],n=Bc[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function gd(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Hs[t],o=Bc[t],s=e;for(;s.length>0;){let i=Tc.encodeInto(s,r);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(t,o*n)}return o}function $s(e,{size:t=32,utf8Buffer:r}={}){if(!Hs[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof e=="string"){if(r)return gd(e,t,r);e=Tc.encode(e)}return md(e,t)}var Pr={hash:e=>Number($s(e,{size:32})),hashV:(e,t)=>yd(Pr.hash(e,t))};function yd(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),X(t,"base16")}var Vs=64,Ut=class{fp;h;seed;constructor(t,r,n,o=2){if(o>Vs)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=wt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,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 Se(e,t){return Math.floor(Math.random()*(t-e))+e}var ve=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Ut))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Ut))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=t,!0;return!0}swap(t){if(!(t instanceof Ut))throw new TypeError("Invalid Fingerprint");let r=Se(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=t,n}remove(t){if(!(t instanceof Ut))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var bd=500,kr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Pr,this.seed=t.seed??Se(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=X(t));let r=new Ut(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ve(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ve(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[Se(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ve(this.bucketSize));for(let a=0;a<bd;a++){let c=this.buckets[i].swap(r);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ve(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=X(t));let r=new Ut(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(t){typeof t=="string"&&(t=X(t));let r=new Ut(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},wd={1:.5,2:.84,4:.95,8:.98};function xd(e=.001){return e>.002?2:e>1e-5?4:8}function Dc(e,t=.001){let r=xd(t),n=wd[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),Vs);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var Hn=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??Pr,this.seed=t.seed??Se(0,Math.pow(2,10)),this.filterSeries=[new kr({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 r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new kr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(t)}has(t){typeof t=="string"&&(t=X(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=X(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,r)=>t+r.count,0)}};function js(e,t=.001,r){return new Hn({...Dc(e,t),...r??{}})}function Nr(e){let t=e.getComponents(),r={},n=0;return t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r)}function je(e){let t=Nr(e);if(t==null)throw new yt(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var $n=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Rc=45,Ed=15,Ze=new $n;function Vn(e){if(!(e.length>Ed))return Ze.new(e).parseWith(()=>Ze.readIPv4Addr())}function jn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Rc))return Ze.new(e).parseWith(()=>Ze.readIPv6Addr())}function Ye(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Rc)return;let r=Ze.new(e).parseWith(()=>Ze.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function Lc(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Cc(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Zs(e){switch(e.length){case _e:return e.join(".");case Ae:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Oc(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function Pc(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var _e=4,Ae=16,Lb=parseInt("0xFFFF",16),Sd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Fr(e,t){t.length===Ae&&e.length===_e&&Lc(t,0,11)&&(t=t.slice(12)),t.length===_e&&e.length===Ae&&Cc(e,Sd,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function kc(e,t){if(typeof t=="string"&&(t=Ye(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function Ys(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=_e,o=Vn(t);if(o==null&&(n=Ae,o=jn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+e);let i=Gs(s,8*n);return{network:Fr(o,i),mask:i}}function Gs(e,t){if(t!==8*_e&&t!==8*Ae)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var Ur=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=Ys(t));else{let n=Ye(t);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Ye(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Gs(o,8*n.length);this.network=Fr(n,this.mask)}}contains(t){return kc({network:this.network,mask:this.mask},t)}toString(){let t=Oc(this.mask),r=t!==-1?String(t):Pc(this.mask);return Zs(this.network)+"/"+r}};function Nc(e,t){return new Ur(e).contains(t)}function Fc(e){try{let t=je(e);return t.type==="ip6"?Nc("2000::/3",t.host):!1}catch{return!1}}function Ge(e){return!!Vn(e)}function Zn(e){return!!jn(e)}var zc=Au(Kc(),1),Dd=["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"],Rd=Dd.map(e=>new zc.Netmask(e));function ri(e){for(let t of Rd)if(t.contains(e))return!0;return!1}function Ld(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function Cd(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return ri(o)}function Od(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function Pd(e){let t=e.split(":"),r=t[t.length-1];return ri(r)}function kd(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function Gn(e){if(Ge(e))return ri(e);if(Ld(e))return Cd(e);if(Od(e))return Pd(e);if(Zn(e))return kd(e)}function qc(e){try{let t=je(e);switch(t.type){case"ip4":case"ip6":return Gn(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Gt=class extends Error{static name="ValidationError";name="ValidationError"},Wn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Xn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function oi(e){return t=>st(t,e)}function si(e){return t=>X(t,e)}function Je(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Be(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Hc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=X(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Be(n);return Kt([r,o],r.length+o.length)}function $c(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Qt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Be(n);return Kt([r,o],r.length+o.length)}function ii(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=st(t,"base32"),o=Je(r);return`${n}:${o}`}var ai=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ft("Invalid byte value in IP address");t[n]=o}),t},Vc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=Ge(r[n]),i;s&&(i=ai(r[n]),r[n]=st(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,st(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ft("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},jc=function(e){if(e.byteLength!==4)throw new ft("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Zc=function(e){if(e.byteLength!==16)throw new ft("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${r}"`)}};function Yc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${e}"`)}}var ni=Object.values(pr).map(e=>e.decoder),Nd=(function(){let e=ni[0].or(ni[1]);return ni.slice(2).forEach(t=>e=e.or(t)),e})();function Gc(e){return Nd.decode(e)}function Wc(e){return t=>e.encoder.encode(t)}function Fd(e){if(parseInt(e).toString()!==e)throw new Gt("Value must be an integer")}function Ud(e){if(e<0)throw new Gt("Value must be a positive integer, or zero")}function Md(e){return t=>{if(t>e)throw new Gt(`Value must be smaller than or equal to ${e}`)}}function Kd(...e){return t=>{for(let r of e)r(t)}}var Mr=Kd(Fd,Ud,Md(65535));var ut=-1,ci=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Xn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Wt=new ci,Ah=[{code:4,name:"ip4",size:32,valueToBytes:ai,bytesToValue:jc,validate:e=>{if(!Ge(e))throw new Gt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Be,bytesToValue:Je,validate:Mr},{code:273,name:"udp",size:16,valueToBytes:Be,bytesToValue:Je,validate:Mr},{code:33,name:"dccp",size:16,valueToBytes:Be,bytesToValue:Je,validate:Mr},{code:41,name:"ip6",size:128,valueToBytes:Vc,bytesToValue:Zc,stringToValue:Yc,validate:e=>{if(!Zn(e))throw new Gt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ut},{code:43,name:"ipcidr",size:8,bytesToValue:oi("base10"),valueToBytes:si("base10")},{code:53,name:"dns",size:ut},{code:54,name:"dns4",size:ut},{code:55,name:"dns6",size:ut},{code:56,name:"dnsaddr",size:ut},{code:132,name:"sctp",size:16,valueToBytes:Be,bytesToValue:Je,validate:Mr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ut,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ut,bytesToValue:oi("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?si("base58btc")(e):dt.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ii,valueToBytes:Hc},{code:445,name:"onion3",size:296,bytesToValue:ii,valueToBytes:$c},{code:446,name:"garlic64",size:ut},{code:447,name:"garlic32",size:ut},{code:448,name:"tls"},{code:449,name:"sni",size:ut},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ut,bytesToValue:Wc(Co),valueToBytes:Gc},{code:480,name:"http"},{code:481,name:"http-path",size:ut,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ut}];Ah.forEach(e=>{Wt.addProtocol(e)});function Xc(e){let t=[],r=0;for(;r<e.length;){let n=Br(e,r),o=Wt.getProtocol(n),s=St(n),i=Ih(o,e,r+s),a=0;i>0&&o.size===ut&&(a=St(i));let c=s+a+i,u={code:n,name:o.name,bytes:kt(e.subarray(r,r+c))};if(i>0){let f=r+s+a,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??st(l)}t.push(u),r+=c}return t}function Qc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Wt.getProtocol(n.code),s=St(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??X(n.value),a=i.byteLength,o.size===ut&&(c=St(a)));let u=new Uint8Array(s+c+a),f=0;$e(n.code,u,f),f+=s,i!=null&&(o.size===ut&&($e(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Kt(r,t)}function Jc(e){if(e.charAt(0)!=="/")throw new ft('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Wt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ft(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ft(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return t}function tu(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Wt.getProtocol(t.code);if(r==null)throw new ft(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Ih(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Br(t,r)}var Bh=Symbol.for("nodejs.util.inspect.custom"),li=Symbol.for("@multiformats/multiaddr");function Th(e){if(e==null&&(e="/"),eu(e))return e.getComponents();if(e instanceof Uint8Array)return Xc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Jc(e);if(Array.isArray(e))return e;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Qn=class e{[li]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Th(t),r.validate!==!1&&Dh(this)}get bytes(){return this.#r==null&&(this.#r=Qc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=tu(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Wn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return ht(this.bytes,t.bytes)}[Bh](){return`Multiaddr(${this.toString()})`}};function Dh(e){e.getComponents().forEach(t=>{let r=Wt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function eu(e){return!!e?.[li]}function ru(e){return new Qn(e)}function tr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Jn=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}},er=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Jn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new Jn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var di=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function to(e={}){return Rh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function Rh(e,t){t=t??{};let r=t.onEnd,n=new er,o,s,i,a=tr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,x)=>{s=v=>{s=null,n.push(v);try{y(e(n))}catch(m){x(m)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=tr()})}},u=y=>s!=null?s(y):(n.push(y),o),f=y=>(n=new er,s!=null?s({error:y}):(n.push({error:y}),o)),l=y=>{if(i)return o;if(t?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},d=y=>i?o:(i=!0,y!=null?f(y):u({done:!0})),p=()=>(n=new er,d(),{done:!0}),S=y=>(d(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:S,push:l,end:d,get readableLength(){return n.size},onEmpty:async y=>{let x=y?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let v,m;x!=null&&(v=new Promise((_,A)=>{m=()=>{A(new di)},x.addEventListener("abort",m)}));try{await Promise.race([a.promise,v])}finally{m!=null&&x!=null&&x?.removeEventListener("abort",m)}}},r==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(y){return b.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(y){return b.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return b.readableLength},onEmpty:y=>b.onEmpty(y)},o}var hi=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},nu=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function pi(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,f=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){d(nu(i));return}if(i&&(c=()=>{d(nu(i))},i.addEventListener("abort",c,{once:!0})),e.then(l,d),r===Number.POSITIVE_INFINITY)return;let p=new hi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(S){d(S)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?d(o):(p.message=o??`Promise timed out after ${r} milliseconds`,d(p))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Lh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Ch(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=Lh(e),l=async(...p)=>{let S=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(S))return}catch(b){n(),i(b);return}c.push(S),r.count===c.length&&(n(),s(c))},d=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)f(p,l);for(let p of r.rejectionEvents)a.includes(p)||f(p,d)};for(let p of a)u(p,l);for(let p of r.rejectionEvents)a.includes(p)||u(p,d);r.signal&&r.signal.addEventListener("abort",()=>{d(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=pi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function rr(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Ch(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Kr(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var eo=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Te=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Oh(e){return e.reason}function zr(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??Oh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;return Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})]).finally(()=>{o!=null&&t.removeEventListener("abort",o)})}var ro=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=tr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Mt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Ph(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var ou=new WeakMap,no=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,r){this.id=Ph(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Mt),this.cleanup())}async join(t){let r=new ro(t);return this.recipients.push(r),t?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await zr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=ou.get(r);if(n==null&&(n=new WeakSet,ou.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.deferred.reject(t.signal?.reason??new Mt),t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var oo=class extends De{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=Kr(this.emitEmpty.bind(this),1),this.emitIdle=Kr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new eo;let n=new no(t,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Mt)}),this.clear()}async onEmpty(t){this.size!==0&&await rr(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await rr(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await rr(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=to({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Mt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function qr(e){let t=new globalThis.AbortController;function r(){let s=e.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let s of e){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}var kh=4194304,so=class extends Error{static name="UnwrappedError";name="UnwrappedError"},gi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},yi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},bi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Nh(e){return typeof e?.closeRead=="function"}function Fh(e){return typeof e?.close=="function"}function mi(e){return Nh(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Fh(e)?e.status!=="open":!1}function Uh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Mh(e,t){let r=t?.maxBufferSize??kh,n=new ct,o,s=!1,i;if(!Uh(e))throw new yt("Argument should be a Stream or a Multiaddr");let a=l=>{if(i==null){if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(d);let p=new Yr(`Read buffer overflow - ${d} > ${r}`);i=p,o?.reject(p),queueMicrotask(()=>{e.abort(p)});return}o?.resolve()}};e.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};e.addEventListener("close",c);let u=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new so("Stream was unwrapped");if(i!=null)throw i;if(mi(e)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new Te(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=d){o.resolve();break}if(await zr(o.promise,l?.signal),mi(e)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(mi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Te(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let S=n.sublist(0,p);return n.consume(p),S},async write(l,d){if(s===!0)throw new so("Stream was unwrapped");e.send(l)||await rr(e,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",a),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n))),e}};return f}function Kh(e,t={}){let r=Mh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=St(t.maxDataLength));let n=t?.lengthDecoder??Br,o=t?.lengthEncoder??rc;return{async read(i){let a=-1,c=new ct;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new gi("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new bi(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new yi(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new Te(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Te(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new ct(o(i.byteLength),i),a)},async writeV(i,a){let c=new ct(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function nr(e,t){let r=Kh(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.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:()=>r.unwrap()};return n}var io=class extends oo{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function su(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal},f;r?.timeout!=null&&(f=qr([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=f),s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Kr(i,r?.debounce??100),c=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var wi=class extends Map{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function iu(e){let{name:t,metrics:r}=e,n;return r!=null?n=new wi({name:t,metrics:r}):n=new Map,n}var xi="libp2p",Ei="autonat";var au="dial-request",cu="dial-back",uu=200n*1024n,fu=4096;var or;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s={...s},s.dialDataResponse!=null&&(s.dialDataRequest=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialDataRequest!=null&&(s.dialDataResponse=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialResponse!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialRequest=void 0),s.dialRequest!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialResponse=void 0),s.dialRequest!=null&&(i.uint32(10),Hr.codec().encode(s.dialRequest,i)),s.dialResponse!=null&&(i.uint32(18),$t.codec().encode(s.dialResponse,i)),s.dialDataRequest!=null&&(i.uint32(26),$r.codec().encode(s.dialDataRequest,i)),s.dialDataResponse!=null&&(i.uint32(34),Vr.codec().encode(s.dialDataResponse,i)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.dialRequest=Hr.codec().decode(s,s.uint32(),{limits:a.limits?.dialRequest});break}case 2:{c.dialResponse=$t.codec().decode(s,s.uint32(),{limits:a.limits?.dialResponse});break}case 3:{c.dialDataRequest=$r.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataRequest});break}case 4:{c.dialDataResponse=Vr.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}return c.dialDataResponse!=null&&(delete c.dialDataRequest,delete c.dialResponse,delete c.dialRequest),c.dialDataRequest!=null&&(delete c.dialDataResponse,delete c.dialResponse,delete c.dialRequest),c.dialResponse!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialRequest),c.dialRequest!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialResponse),c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield*Hr.codec().stream(s,s.uint32(),`${a}.dialRequest`,{limits:c.limits?.dialRequest});break}case 2:{yield*$t.codec().stream(s,s.uint32(),`${a}.dialResponse`,{limits:c.limits?.dialResponse});break}case 3:{yield*$r.codec().stream(s,s.uint32(),`${a}.dialDataRequest`,{limits:c.limits?.dialDataRequest});break}case 4:{yield*Vr.codec().stream(s,s.uint32(),`${a}.dialDataResponse`,{limits:c.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(or||(or={}));var Hr;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.addrs!=null&&s.addrs.length>0)for(let c of s.addrs)i.uint32(10),i.bytes(c);s.nonce!=null&&s.nonce!==0n&&(i.uint32(17),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrs:[],nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(a.limits?.addrs!=null&&c.addrs.length===a.limits.addrs)throw new Lr('Decode error - repeated field "addrs" had too many elements');c.addrs.push(s.bytes());break}case 2:{c.nonce=s.fixed64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={addrs:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(c.limits?.addrs!=null&&u.addrs===c.limits.addrs)throw new Lr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${a}.addrs[]`,index:u.addrs,value:s.bytes()},u.addrs++;break}case 2:{yield{field:`${a}.nonce`,value:s.fixed64()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(Hr||(Hr={}));var $r;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.addrIdx!=null&&s.addrIdx!==0&&(i.uint32(8),i.uint32(s.addrIdx)),s.numBytes!=null&&s.numBytes!==0n&&(i.uint32(16),i.uint64(s.numBytes)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrIdx:0,numBytes:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.addrIdx=s.uint32();break}case 2:{c.numBytes=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.addrIdx`,value:s.uint32()};break}case 2:{yield{field:`${a}.numBytes`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})($r||($r={}));var lt;(function(e){e.UNUSED="UNUSED",e.E_DIAL_ERROR="E_DIAL_ERROR",e.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",e.OK="OK"})(lt||(lt={}));var ao;(function(e){e[e.UNUSED=0]="UNUSED",e[e.E_DIAL_ERROR=100]="E_DIAL_ERROR",e[e.E_DIAL_BACK_ERROR=101]="E_DIAL_BACK_ERROR",e[e.OK=200]="OK"})(ao||(ao={}));(function(e){e.codec=()=>xe(ao)})(lt||(lt={}));var $t;(function(e){let t;(function(a){a.E_INTERNAL_ERROR="E_INTERNAL_ERROR",a.E_REQUEST_REJECTED="E_REQUEST_REJECTED",a.E_DIAL_REFUSED="E_DIAL_REFUSED",a.OK="OK"})(t=e.ResponseStatus||(e.ResponseStatus={}));let r;(function(a){a[a.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",a[a.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",a[a.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",a[a.OK=200]="OK"})(r||(r={})),(function(a){a.codec=()=>xe(r)})(t=e.ResponseStatus||(e.ResponseStatus={}));let n;e.codec=()=>(n==null&&(n=Ot((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&r[a.status]!==0&&(c.uint32(8),e.ResponseStatus.codec().encode(a.status,c)),a.addrIdx!=null&&a.addrIdx!==0&&(c.uint32(16),c.uint32(a.addrIdx)),a.dialStatus!=null&&ao[a.dialStatus]!==0&&(c.uint32(24),lt.codec().encode(a.dialStatus,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:lt.UNUSED},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{f.status=e.ResponseStatus.codec().decode(a);break}case 2:{f.addrIdx=a.uint32();break}case 3:{f.dialStatus=lt.codec().decode(a);break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{yield{field:`${u}.status`,value:e.ResponseStatus.codec().decode(a)};break}case 2:{yield{field:`${u}.addrIdx`,value:a.uint32()};break}case 3:{yield{field:`${u}.dialStatus`,value:lt.codec().decode(a)};break}default:{a.skipType(d&7);break}}}})),n);function o(a){return Lt(a,e.codec())}e.encode=o;function s(a,c){return Rt(a,e.codec(),c)}e.decode=s;function i(a,c){return Ct(a,e.codec(),c)}e.stream=i})($t||($t={}));var Vr;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.data!=null&&s.data.byteLength>0&&(i.uint32(10),i.bytes(s.data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={data:wt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.data=s.bytes():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.data`,value:s.bytes()}:s.skipType(f&7)}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(Vr||(Vr={}));var sr;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.nonce!=null&&s.nonce!==0n&&(i.uint32(9),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.nonce=s.fixed64():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.nonce`,value:s.fixed64()}:s.skipType(f&7)}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(sr||(sr={}));var ue;(function(e){let t;(function(a){a.OK="OK"})(t=e.DialBackStatus||(e.DialBackStatus={}));let r;(function(a){a[a.OK=0]="OK"})(r||(r={})),(function(a){a.codec=()=>xe(r)})(t=e.DialBackStatus||(e.DialBackStatus={}));let n;e.codec=()=>(n==null&&(n=Ot((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&r[a.status]!==0&&(c.uint32(8),e.DialBackStatus.codec().encode(a.status,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.OK},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?f.status=e.DialBackStatus.codec().decode(a):a.skipType(d&7)}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?yield{field:`${u}.status`,value:e.DialBackStatus.codec().decode(a)}:a.skipType(d&7)}})),n);function o(a){return Lt(a,e.codec())}e.encode=o;function s(a,c){return Rt(a,e.codec(),c)}e.decode=s;function i(a,c){return Ct(a,e.codec(),c)}e.stream=i})(ue||(ue={}));function co(e,t){return Math.round(Math.random()*(t-e)+e)}var qh=4,Hh=8,uo=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;safeDispatchEvent;constructor(t,r){this.components=t,this.safeDispatchEvent=r.safeDispatchEvent,this.log=t.logger.forComponent("libp2p:auto-nat-v2:client"),this.started=!1,this.dialRequestProtocol=r.dialRequestProtocol,this.dialBackProtocol=r.dialBackProtocol,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.connectionThreshold=r.connectionThreshold??80,this.maxMessageSize=r.maxMessageSize??8192,this.dialResults=iu({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=su(this.findRandomPeers.bind(this),6e4),this.addressFilter=js(1024),this.queue=new io({concurrency:3,maxSize:50}),this.maxDialDataBytes=r.maxDialDataBytes??uu,this.dialDataChunkSize=r.dialDataChunkSize??fu,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[Wr]=["@libp2p/autonat"];get[Xr](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.components.registrar.register(this.dialRequestProtocol,{onConnect:(t,r)=>{this.verifyExternalAddresses(r).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),await this.components.registrar.handle(this.dialBackProtocol,(t,r)=>{this.handleDialBackStream(t,r).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),await this.components.registrar.unhandle(this.dialBackProtocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let r=qr([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:r})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:r})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleDialBackStream(t,r){let n=AbortSignal.timeout(this.timeout);let o=nr(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read(sr,{signal:n});if(!this.nonces.has(s.nonce))throw new It("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:ue.DialBackStatus.OK},ue),await t.close({signal:n})}catch(s){this.log.error("error handling incoming dial back stream - %e",s),t.abort(s)}}getUnverifiedMultiaddrs(t,r){let n=this.components.addressManager.getAddressesWithMetadata().sort((s,i)=>s.type==="observed"&&i.type!=="observed"?1:i.type==="observed"&&s.type!=="observed"?-1:0).filter(s=>{if(!(s.expires<Date.now()))return!1;let a=Nr(s.multiaddr);return!(a==null||a.type==="ip6"&&(!r||!Fc(s.multiaddr))||qc(s.multiaddr))}),o=[];for(let s of n){let i=s.multiaddr.toString(),a=this.dialResults.get(i);if(a!=null&&a.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",a.multiaddr,t);continue}if(a==null){let c=s.expires<Date.now();if(c&&this.addressFilter.remove?.(i),this.addressFilter.has(i))continue;this.addressFilter.add(i),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",i),a={multiaddr:s.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:qs(),type:s.type,lastVerified:s.lastVerified},this.dialResults.set(i,a)}o.push(a)}return o}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:a})=>Nr(a)?.type==="ip6"),o=Nr(t.remoteAddr);if(o?.type!=="ip4"&&o?.type!=="ip6")return;let s=this.getNetworkSegment(t.remoteAddr),i=this.getUnverifiedMultiaddrs(s,n);if(i.length!==0){if(!this.hasConnectionCapacity()){i[0]?.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",i[0].multiaddr),this.confirmAddress(i[0])):this.log("skipping verifying %a because we are too close to the connection limit",i[0]?.multiaddr);return}this.queue.add(async a=>{let c=qr([a.signal,AbortSignal.timeout(this.timeout)]),u=BigInt(co(0,Number.MAX_SAFE_INTEGER));this.nonces.add(u);try{await this.askPeerToVerify(t,s,u,a)}finally{c.clear(),this.nonces.delete(u)}},{peerId:t.remotePeer}).catch(a=>{this.log.error("error from %p verifying addresses - %e",t.remotePeer,a)})}}async askPeerToVerify(t,r,n,o){let s=[...this.dialResults.values()].filter(a=>a.result==null).map(a=>a.multiaddr);if(s.length===0){this.queue.clear();return}this.log.trace("asking %a to verify multiaddrs %s",t.remoteAddr,s);let i=await t.newStream(this.dialRequestProtocol,o);try{let a=nr(i).pb(or);await a.write({dialRequest:{addrs:s.map(c=>c.bytes),nonce:n}},o);for(let c=0;c<s.length;c++){let u=await a.read(o);if(u.dialDataRequest!=null){if(u.dialDataRequest.numBytes>this.maxDialDataBytes){this.log("too many dial data byte requested by %p - %s/%s",t.remotePeer,u.dialDataRequest.numBytes,this.maxDialDataBytes);continue}this.log("sending %d bytes to %p as anti-amplification attack protection",u.dialDataRequest.numBytes,t.remotePeer);let p=new Uint8Array(this.dialDataChunkSize),S=BigInt(this.dialDataChunkSize);for(let b=0n;b<u.dialDataRequest.numBytes;b+=S)await a.write({dialDataResponse:{data:p}},o);u=await a.read(o)}if(u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}if(u.dialResponse.status!==$t.ResponseStatus.OK)return;let l=s[u.dialResponse.addrIdx];if(l==null){this.log.trace("peer dialed unknown address");continue}let d=this.dialResults.get(l.toString());if(d==null){this.log.trace("peer reported %a as %s but there is no result object",l,u.dialResponse.status);continue}if(d.networkSegments.includes(r)){this.log.trace("%a results already included network segment %s",l,r);continue}if(d.result!=null){this.log.trace("already resolved result for %a, ignoring response from",l,t.remotePeer);continue}if(d.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,l);continue}if(d.verifyingPeers.add(t.remotePeer),d.networkSegments.push(r),u.dialResponse.dialStatus===lt.OK){if(this.log.trace("%p dialed %a successfully",t.remotePeer,d.multiaddr),this.emitReachabilityEvent(d,"verifying"),d.success++,d.type!=="observed"){this.confirmAddress(d);continue}}else if(u.dialResponse.dialStatus===lt.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,d.multiaddr),this.emitReachabilityEvent(d,"verifying"),d.failure++;else if(u.dialResponse.dialStatus===lt.E_DIAL_BACK_ERROR){this.log.trace("%p saw error while dialing %a",t.remotePeer,d.multiaddr);continue}this.log("%a success %d failure %d",d.multiaddr,d.success,d.failure),d.success===qh&&this.confirmAddress(d),d.failure===Hh&&this.unconfirmAddress(d)}}finally{try{await i.close(o)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let r=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return r/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,this.emitReachabilityEvent(t,"reachable")}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,this.emitReachabilityEvent(t,"unreachable")}emitReachabilityEvent(t,r){this.safeDispatchEvent(`address:${r}`,{detail:{addr:t.multiaddr,type:t.type,success:t.success,failure:t.failure}})}getNetworkSegment(t){let r=je(t);switch(r.type){case"ip4":return r.host.split(".")[0].padStart(3,"0");case"ip6":return r.host.split(":")[0].padStart(4,"0");default:throw new yt(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};var fo=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:server"),this.started=!1,this.dialRequestProtocol=r.dialRequestProtocol,this.dialBackProtocol=r.dialBackProtocol,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.maxMessageSize=r.maxMessageSize??8192,this.handleDialRequestStream=this.handleDialRequestStream.bind(this)}async start(){this.started||(await this.components.registrar.handle(this.dialRequestProtocol,this.handleDialRequestStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),this.started=!1}async handleDialRequestStream(t,r){let n=AbortSignal.timeout(this.timeout);let o=nr(t,{maxDataLength:this.maxMessageSize}).pb(or),s=mu(r.remoteAddr);if(s==null)throw new It(`Could not find IP address in connection address "${r.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new It("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new It("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=ru(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:$t.ResponseStatus.E_DIAL_REFUSED,dialStatus:lt.UNUSED}},{signal:n});continue}let f=mu(c);if(f==null)throw new It(`Could not find IP address in requested address "${c}"`);if(Gn(f))throw new It(`Requested address had private IP "${c}"`);f!==s&&await this.preventAmplificationAttack(o,a,{signal:n});let l=await this.dialClientBack(c,i.nonce,{signal:n});await o.write({dialResponse:{addrIdx:a,status:$t.ResponseStatus.OK,dialStatus:l}},{signal:n})}catch(c){this.log.error("error handling incoming dialback request - %e",c)}await t.close({signal:n})}async preventAmplificationAttack(t,r,n){let o=co(3e4,1e5);await t.write({dialDataRequest:{addrIdx:r,numBytes:BigInt(o)}},n);let s=0;for(;s<o;){let{dialDataResponse:i}=await t.read(n);if(i==null)throw new It("Did not receive DialDataResponse message on incoming dial request stream");s+=i.data.byteLength}}async dialClientBack(t,r,n){let o;try{o=await this.components.connectionManager.openConnection(t,{force:!0,...n})}catch(s){return this.log.error("failed to open connection to %a - %e",t,s),lt.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=nr(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:r},sr,n),(await i.read(ue,n)).status!==ue.DialBackStatus.OK)throw new It("DialBackResponse status was not OK");await o.close(n)}catch(s){return this.log.error("could not perform dial back - %e",s),o.abort(s),lt.E_DIAL_BACK_ERROR}return lt.OK}};function mu(e){return e.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var lo=class extends De{client;server;constructor(t,r){super();let n=`/${r.protocolPrefix??xi}/${Ei}/${"2"}/${au}`,o=`/${r.protocolPrefix??xi}/${Ei}/${"2"}/${cu}`;this.client=new uo(t,{...r,dialRequestProtocol:n,dialBackProtocol:o,safeDispatchEvent:this.safeDispatchEvent.bind(this)}),this.server=new fo(t,{...r,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[Wr]=["@libp2p/autonat"];get[Xr](){return["@libp2p/identify"]}async start(){await Ai(this.client,this.server)}async stop(){await Ii(this.client,this.server)}};function $h(e={}){return t=>new lo(t,e)}return Iu(Vh);})();
2
+ "use strict";var Libp2PAutonatV2=(()=>{var xu=Object.create;var jr=Object.defineProperty;var Eu=Object.getOwnPropertyDescriptor;var Su=Object.getOwnPropertyNames;var vu=Object.getPrototypeOf,_u=Object.prototype.hasOwnProperty;var po=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},vt=(e,t)=>{for(var r in t)jr(e,r,{get:t[r],enumerable:!0})},vi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Su(t))!_u.call(e,o)&&o!==r&&jr(e,o,{get:()=>t[o],enumerable:!(n=Eu(t,o))||n.enumerable});return e};var Au=(e,t,r)=>(r=e!=null?xu(vu(e)):{},vi(t||!e||!e.__esModule?jr(r,"default",{value:e,enumerable:!0}):r,e)),Iu=e=>vi(jr({},"__esModule",{value:!0}),e);var Xs=po(Xe=>{"use strict";Object.defineProperty(Xe,"__esModule",{value:!0});Xe.Netmask4Impl=void 0;Xe.ip2long=We;Xe.long2ip=Ht;function Ht(e){let t=(e&-16777216)>>>24,r=(e&255<<16)>>>16,n=(e&65280)>>>8,o=e&255;return[t,r,n,o].join(".")}var vd=48,_d=97,Ad=65;function Id(e){let t=0,r=10,n="9",o=0;e.length>1&&e[o]==="0"&&(e[o+1]==="x"||e[o+1]==="X"?(o+=2,r=16):"0"<=e[o+1]&&e[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<e.length;){if("0"<=e[o]&&e[o]<=n)t=t*r+(e.charCodeAt(o)-vd)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-_d)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-Ad)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function We(e){let t=[];for(let r=0;r<=3&&e.length!==0;r++){if(r>0){if(e[0]!==".")throw new Error("Invalid IP");e=e.substring(1)}let[n,o]=Id(e);e=e.substring(o),t.push(n)}if(e.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var Ws=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=We(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(We(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Ht(this.netLong),this.mask=Ht(this.maskLong),this.hostmask=Ht(~this.maskLong),this.first=this.bitmask<=30?Ht(this.netLong+1):this.base,this.last=this.bitmask<=30?Ht(this.netLong+this.size-2):Ht(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Ht(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):(We(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new e(Ht(this.netLong+this.size*t),this.mask)}forEach(t){let r=We(this.first),n=We(this.last),o=0;for(;r<=n;)t(Ht(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Xe.Netmask4Impl=Ws});var Mc=po(Qe=>{"use strict";Object.defineProperty(Qe,"__esModule",{value:!0});Qe.Netmask6Impl=void 0;Qe.ip6bigint=Js;Qe.bigint2ip6=Ie;var Bd=Xs(),Qs=(1n<<128n)-1n;function Js(e){let t=e.indexOf("%");t!==-1&&(e=e.substring(0,t));let r=e.lastIndexOf(":");if(r!==-1&&e.indexOf(".",r)!==-1){let n=e.substring(r+1),o=(0,Bd.ip2long)(n),s=e.substring(0,r+1)+"0:0";return Uc(s)&~0xffffffffn|BigInt(o)}return Uc(e)}function Uc(e){let t=e.indexOf("::"),r;if(t!==-1){let o=e.substring(0,t),s=e.substring(t+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=e.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Ie(e){if(e<0n||e>Qs)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(e&0xffffn)),e>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return t.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=t.slice(0,r).map(c=>c.toString(16)),a=t.slice(r+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var ti=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Qs>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Js(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Ie(this.netBigint),this.mask=Ie(this.maskBigint),this.hostmask=Ie(~this.maskBigint&Qs),this.first=this.base,this.last=Ie(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.last):(Js(t)&this.maskBigint)===this.netBigint}next(t=1){let r=1n<<BigInt(128-this.bitmask);return new e(Ie(this.netBigint+r*BigInt(t)),this.bitmask)}forEach(t){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)t(Ie(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};Qe.Netmask6Impl=ti});var Kc=po(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.long2ip=ce.ip2long=ce.Netmask=void 0;var Yn=Xs();Object.defineProperty(ce,"ip2long",{enumerable:!0,get:function(){return Yn.ip2long}});Object.defineProperty(ce,"long2ip",{enumerable:!0,get:function(){return Yn.long2ip}});var Td=Mc(),ei=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new Td.Netmask6Impl(t,r):this._impl=new Yn.Netmask4Impl(t,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Yn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new e(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new e(t))),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let r=this._impl.next(t);return new e(r.base,r.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ce.Netmask=ei});var Vh={};vt(Vh,{autoNATv2:()=>$h});var Mt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var yt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Zr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Yr=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Gr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var It=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var ar=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var mo=Symbol.for("@libp2p/peer-id");function _i(e){return e!=null&&typeof e.start=="function"&&typeof e.stop=="function"}async function Ai(...e){let t=[];for(let r of e)_i(r)&&t.push(r);await Promise.all(t.map(async r=>{r.beforeStart!=null&&await r.beforeStart()})),await Promise.all(t.map(async r=>{await r.start()})),await Promise.all(t.map(async r=>{r.afterStart!=null&&await r.afterStart()}))}async function Ii(...e){let t=[];for(let r of e)_i(r)&&t.push(r);await Promise.all(t.map(async r=>{r.beforeStop!=null&&await r.beforeStop()})),await Promise.all(t.map(async r=>{await r.stop()})),await Promise.all(t.map(async r=>{r.afterStop!=null&&await r.afterStop()}))}function Bu(e){return typeof e?.handleEvent=="function"}function Tu(e){return e===!0||e===!1}function Du(e){return Tu(e)?e:e?.capture??!1}function go(e){let t={capture:Du(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function Bi(e,t){return go(e).capture===go(t).capture}var De=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let o=go(n);if(o?.signal?.aborted===!0)return;let s=u=>{o.once&&this.removeEventListener(t,r,o),Bu(r)?r.handleEvent(u):r(u)},i=this.#t.get(t);if(i==null&&(i=[],this.#t.set(t,i)),i.some(u=>u.callback!==r?!1:Bi(u.options,o)))return;super.addEventListener(t,s,o);let c=()=>{this.removeEventListener(t,r,o)};o.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:s,options:o,onAbort:c})}removeEventListener(t,r,n){let o=this.#t.get(t);if(o==null){super.removeEventListener(t,r??null,n);return}this.#t.set(t,o.filter(s=>s.callback===r&&Bi(s.options,n)?(super.removeEventListener(t,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Wr=Symbol.for("@libp2p/service-capabilities"),Xr=Symbol.for("@libp2p/service-dependencies");var Eo={};vt(Eo,{base58btc:()=>ot,base58flickr:()=>Fu});var Sp=new Uint8Array(0);function Di(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Bt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return fe(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return fe(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Ri(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var Ti=4096;function Li(e){let t=e.length;if(t<=Ti)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=Ti));return r}function Ru(e){return e?.buffer instanceof ArrayBuffer}function fe(e){return Ru(e)?e:e.slice()}function Lu(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<e.length;s++){var i=e.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=e.length,l=e.charAt(0),d=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function S(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var v=0,m=0,_=0,A=x.length;_!==A&&x[_]===0;)_++,v++;for(var P=(A-_)*p+1>>>0,F=new Uint8Array(P);_!==A;){for(var k=x[_],R=0,C=P-1;(k!==0||R<m)&&C!==-1;C--,R++)k+=256*F[C]>>>0,F[C]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");m=R,_++}for(var z=P-m;z!==P&&F[z]===0;)z++;for(var K=l.repeat(v);z<P;++z)K+=e.charAt(F[z]);return K}function b(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var v=0;if(x[v]!==" "){for(var m=0,_=0;x[v]===l;)m++,v++;for(var A=(x.length-v)*d+1>>>0,P=new Uint8Array(A);x[v];){var F=n[x.charCodeAt(v)];if(F===255)return;for(var k=0,R=A-1;(F!==0||k<_)&&R!==-1;R--,k++)F+=f*P[R]>>>0,P[R]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");_=k,v++}if(x[v]!==" "){for(var C=A-_;C!==A&&P[C]===0;)C++;for(var z=new Uint8Array(m+(A-C)),K=m;C!==A;)z[K++]=P[C++];return z}}}function y(x){var v=b(x);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:S,decodeUnsafe:b,decode:y}}var Cu=Lu,Ou=Cu,Oi=Ou;var yo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},bo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Pi(this,t)}},wo=class{decoders;constructor(t){this.decoders=t}or(t){return Pi(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Pi(e,t){return new wo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var xo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new yo(t,r,n),this.decoder=new bo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Re({name:e,prefix:t,encode:r,decode:n}){return new xo(e,t,r,n)}function Xt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Oi(r,e,n);return Re({prefix:t,name:e,encode:o,decode:i=>Bt(s(i))})}function Pu(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ku(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Nu(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let o=e[n].toLowerCase(),s=e[n].toUpperCase();o!==e[n]&&(r[o]=n),s!==e[n]&&(r[s]=n)}return r}function et({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Nu(n,o);return Re({prefix:t,name:e,encode(i){return ku(i,n,r)},decode(i){return Pu(i,s,r,e)}})}var ot=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Fu=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var So={};vt(So,{base32:()=>Qt,base32hex:()=>zu,base32hexpad:()=>Hu,base32hexpadupper:()=>$u,base32hexupper:()=>qu,base32pad:()=>Mu,base32padupper:()=>Ku,base32upper:()=>Uu,base32z:()=>Vu});var Qt=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Uu=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Mu=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Ku=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),zu=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),qu=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Hu=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),$u=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Vu=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var vo={};vt(vo,{base36:()=>cr,base36upper:()=>ju});var cr=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),ju=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Zu=Fi,ki=128,Yu=127,Gu=~Yu,Wu=Math.pow(2,31);function Fi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Wu;)t[r++]=e&255|ki,e/=128;for(;e&Gu;)t[r++]=e&255|ki,e>>>=7;return t[r]=e|0,Fi.bytes=r-n+1,t}var Xu=_o,Qu=128,Ni=127;function _o(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw _o.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ni)<<o:(i&Ni)*Math.pow(2,o),o+=7}while(i>=Qu);return _o.bytes=s-n,r}var Ju=Math.pow(2,7),tf=Math.pow(2,14),ef=Math.pow(2,21),rf=Math.pow(2,28),nf=Math.pow(2,35),of=Math.pow(2,42),sf=Math.pow(2,49),af=Math.pow(2,56),cf=Math.pow(2,63),uf=function(e){return e<Ju?1:e<tf?2:e<ef?3:e<rf?4:e<nf?5:e<of?6:e<sf?7:e<af?8:e<cf?9:10},ff={encode:Zu,decode:Xu,encodingLength:uf},lf=ff,ur=lf;function fr(e,t=0){let r=ur.decode(e,t),n=ur.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Le(e,t,r=0){return ur.encode(e,t,r),t}function Ce(e){return ur.encodingLength(e)}function Pe(e,t){let r=t.byteLength,n=Ce(e),o=n+Ce(r),s=new Uint8Array(o+r);return Le(e,s,0),Le(r,s,n),s.set(t,o),new Oe(e,r,t,s)}function lr(e){let t=Bt(e),[r,n]=fr(t),[o,s]=fr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Oe(r,o,i,t)}function Ui(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Di(e.bytes,r.bytes)}}var Oe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=fe(n),this.bytes=fe(o)}};function Mi(e,t){let{bytes:r,version:n}=e;return n===0?hf(r,Ao(e),t??ot.encoder):pf(r,Ao(e),t??Qt.encoder)}var Ki=new WeakMap;function Ao(e){let t=Ki.get(e);if(t==null){let r=new Map;return Ki.set(e,r),r}return t}var dt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=fe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==mf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Pe(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ui(t.multihash,n.multihash)}toString(t){return Mi(this,t)}toJSON(){return{"/":Mi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??zi(n,o,s.bytes))}else if(r[gf]===!0){let{version:n,multihash:o,code:s}=r,i=lr(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==dr)throw new Error(`Version 0 CID must use dag-pb (code: ${dr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=zi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,dr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Bt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Oe(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,d]=fr(t.subarray(r));return r+=d,l},o=n(),s=dr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=df(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ao(s).set(n,t),s}};function df(e,t){switch(e[0]){case"Q":{let r=t??ot;return[ot.prefix,r.decode(`${ot.prefix}${e}`)]}case ot.prefix:{let r=t??ot;return[ot.prefix,r.decode(e)]}case Qt.prefix:{let r=t??Qt;return[Qt.prefix,r.decode(e)]}case cr.prefix:{let r=t??cr;return[cr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function hf(e,t,r){let{prefix:n}=r;if(n!==ot.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function pf(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var dr=112,mf=18;function zi(e,t,r){let n=Ce(e),o=n+Ce(t),s=new Uint8Array(o+r.byteLength);return Le(e,s,0),Le(t,s,n),s.set(r,o),s}var gf=Symbol.for("@ipld/js-cid/CID");var Io={};vt(Io,{identity:()=>Pt});var qi=0,yf="identity",Hi=Bt;function bf(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Pe(qi,Hi(e))}var Pt={code:qi,name:yf,encode:Hi,digest:bf};function ht(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function wf(e){return e.buffer instanceof ArrayBuffer}function kt(e){return wf(e)?e:e.slice()}async function $i(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,kt(t),kt(r.subarray()));return n?.signal?.throwIfAborted(),s}function wt(e=0){return new Uint8Array(e)}function pt(e=0){return new Uint8Array(e)}function xf(e){return e?.buffer instanceof ArrayBuffer}function Bo(e){if(xf(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Kt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=pt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return Bo(r)}var ji=Symbol.for("@achingbrain/uint8arraylist");function Vi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Jr(e){return!!e?.[ji]}var ct=class e{bufs;length;[ji]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Jr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Jr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Vi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Vi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Jr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Kt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Kt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Jr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){f=Math.max(1,d-a[p]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=wt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=wt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=wt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=wt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ht(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var To={};vt(To,{base10:()=>Ef});var Ef=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Do={};vt(Do,{base16:()=>Sf,base16upper:()=>vf});var Sf=et({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),vf=et({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ro={};vt(Ro,{base2:()=>_f});var _f=et({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Lo={};vt(Lo,{base256emoji:()=>Df});var Zi=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Af=Zi.reduce((e,t,r)=>(e[r]=t,e),[]),If=Zi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Bf(e){return e.reduce((t,r)=>(t+=Af[r],t),"")}function Tf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=If[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Df=Re({prefix:"\u{1F680}",name:"base256emoji",encode:Bf,decode:Tf});var Oo={};vt(Oo,{base64:()=>Rf,base64pad:()=>Lf,base64url:()=>Co,base64urlpad:()=>Cf});var Rf=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Lf=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Co=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Cf=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Po={};vt(Po,{base8:()=>Of});var Of=et({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ko={};vt(ko,{identity:()=>Pf});var Pf=Re({prefix:"\0",name:"identity",encode:e=>Li(Bt(e)),decode:e=>Bt(Ri(e))});var a0=new TextEncoder,c0=new TextDecoder;var Uo={};vt(Uo,{sha256:()=>hr,sha512:()=>Uf});var Ff=20;function Fo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new No(e,t,r,n,o)}var No=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Ff,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Yi(n,this.code,r?.truncate):n.then(o=>Yi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Yi(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Pe(t,e)}function Wi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var hr=Fo({name:"sha2-256",code:18,encode:Wi("SHA-256")}),Uf=Fo({name:"sha2-512",code:19,encode:Wi("SHA-512")});var pr={...ko,...Ro,...Po,...To,...Do,...So,...vo,...Eo,...Oo,...Lo},x0={...Uo,...Io};function Qi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Xi=Qi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Mo=Qi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=pt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Mf={utf8:Xi,"utf-8":Xi,hex:pr.base16,latin1:Mo,ascii:Mo,binary:Mo,...pr},tn=Mf;function X(e,t="utf8"){let r=tn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function st(e,t="utf8"){let r=tn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Kf=parseInt("11111",2),Ko=parseInt("10000000",2),zf=parseInt("01111111",2),Ji={0:mr,1:mr,2:qf,3:Vf,4:jf,5:$f,6:Hf,16:mr,22:mr,48:mr};function zo(e,t={offset:0}){let r=e[t.offset]&Kf;if(t.offset++,Ji[r]!=null)return Ji[r](e,t);throw new Error("No decoder for tag "+r)}function gr(e,t){let r=0;if((e[t.offset]&Ko)===Ko){let n=e[t.offset]&zf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");o+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function mr(e,t){gr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=zo(e,t);if(n===null)break;r.push(n)}return r}function qf(e,t){let r=gr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Hf(e,t){let r=gr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function $f(e,t){return t.offset++,null}function Vf(e,t){let r=gr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function jf(e,t){let r=gr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Zf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ct;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function qo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Zf(e.byteLength);return new ct(Uint8Array.from([t.byteLength|Ko]),t)}function ta(e){let t=new ct,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ct(Uint8Array.from([2]),qo(t),t)}function ea(e){let t=Uint8Array.from([0]),r=new ct(t,e);return new ct(Uint8Array.from([3]),qo(r),r)}function en(e,t=48){let r=new ct;for(let n of e)r.append(n);return new ct(Uint8Array.from([t]),qo(r),r)}var Yf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Gf=Uint8Array.from([6,5,43,129,4,0,34]),Wf=Uint8Array.from([6,5,43,129,4,0,35]),Xf={ext:!0,kty:"EC",crv:"P-256"},Qf={ext:!0,kty:"EC",crv:"P-384"},Jf={ext:!0,kty:"EC",crv:"P-521"},Ho=32,$o=48,Vo=66;function ra(e){let t=zo(e);return na(t)}function na(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ho*2+1)return n=st(t.subarray(r,r+Ho),"base64url"),o=st(t.subarray(r+Ho),"base64url"),new ke({...Xf,key_ops:["verify"],x:n,y:o});if(t.byteLength===$o*2+1)return n=st(t.subarray(r,r+$o),"base64url"),o=st(t.subarray(r+$o),"base64url"),new ke({...Qf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Vo*2+1)return n=st(t.subarray(r,r+Vo),"base64url"),o=st(t.subarray(r+Vo),"base64url"),new ke({...Jf,key_ops:["verify"],x:n,y:o});throw new yt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function oa(e){return en([ta(Uint8Array.from([1])),en([tl(e.crv)],160),en([ea(new ct(Uint8Array.from([4]),X(e.x??"","base64url"),X(e.y??"","base64url")))],161)]).subarray()}function tl(e){if(e==="P-256")return Yf;if(e==="P-384")return Gf;if(e==="P-521")return Wf;throw new yt(`Invalid curve ${e}`)}var ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=oa(this.jwk)),this._raw}toMultihash(){return Pt.digest(Ne(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}async verify(t,r,n){return $i(this.jwk,r,t,n)}};var rn=BigInt(4294967295),sa=BigInt(32);function el(e,t=!1){return t?{h:Number(e&rn),l:Number(e>>sa&rn)}:{h:Number(e>>sa&rn)|0,l:Number(e&rn)|0}}function ia(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=el(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var rl=e=>e/2**32|0,nl=e=>e>>>0;function aa(e,t,r,n){let o=rl(r),s=nl(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var jo=(e,t,r)=>e>>>r,Zo=(e,t,r)=>e<<32-r|t>>>r,de=(e,t,r)=>e>>>r|t<<32-r,he=(e,t,r)=>e<<32-r|t>>>r,yr=(e,t,r)=>e<<64-r|t>>>r-32,br=(e,t,r)=>e>>>r-32|t<<64-r;function zt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ca=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ua=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,fa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),la=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,da=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ha=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function nn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Yo=e=>e?`"${e}" `:"";function Vt(e,t=""){if(typeof e!="number")throw new TypeError(Yo(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Yo(t)+"expected integer >= 0, got "+e);return e}function Tt(e,t,r=""){if(nn(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Vt(t,"length");let n=nn(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=Yo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function on(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Vt(e.outputLen),Vt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var sl=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},pa=(e,t)=>{sl(e,t);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function Fe(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function sn(e,t){Tt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function pe(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function an(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Nt(e,t){return e<<32-t|e>>>t}var ga=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",il=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function cn(e){if(Tt(e),ga)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=il[e[r]];return t}function ma(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function un(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(ga)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=ma(e.charCodeAt(s)),a=ma(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Go(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Tt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function al(e,t,r="opts"){return pa(e,"defaults"),t!==void 0&&pa(t,r),Object.assign(Object.create(null),e,t)}function Wo(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=al({},t,"info");let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function ya(e=32){Vt(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Xo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ba(e,t,r){return e&t^~e&r}function wa(e,t,r){return e&t^e&r^t&r}var wr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=an(this.buffer)}update(t){Fe(this),Tt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=an(t);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){Fe(this),sn(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),aa(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:an(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(r),t}clone(){return this._cloneInto()}},xa=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ea=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var cl=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jt=new Uint32Array(64),Qo=class extends wr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let l=0;l<16;l++,r+=4)Jt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=Jt[l-15],p=Jt[l-2],S=Nt(d,7)^Nt(d,18)^d>>>3,b=Nt(p,17)^Nt(p,19)^p>>>10;Jt[l]=b+Jt[l-7]+S+Jt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Nt(a,6)^Nt(a,11)^Nt(a,25),p=f+d+ba(a,c,u)+cl[l]+Jt[l]|0,b=(Nt(n,2)^Nt(n,13)^Nt(n,22))+wa(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+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,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){pe(Jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),pe(this.buffer)}},Jo=class extends Qo{constructor(){super(32,xa)}};var Sa=ia(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),ul=Sa[0],fl=Sa[1],te=new Uint32Array(80),ee=new Uint32Array(80),ts=class extends wr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:p,Gl:S,Hh:b,Hl:y}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,p,S,b,y]}set(t,r,n,o,s,i,a,c,u,f,l,d,p,S,b,y){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=S|0,this.Hh=b|0,this.Hl=y|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let m=0;m<16;m++,r+=4)te[m]=t.getUint32(r),ee[m]=t.getUint32(r+=4);for(let m=16;m<80;m++){let _=te[m-15]|0,A=ee[m-15]|0,P=de(_,A,1)^de(_,A,8)^jo(_,A,7),F=he(_,A,1)^he(_,A,8)^Zo(_,A,7),k=te[m-2]|0,R=ee[m-2]|0,C=de(k,R,19)^yr(k,R,61)^jo(k,R,6),z=he(k,R,19)^br(k,R,61)^Zo(k,R,6),K=fa(F,z,ee[m-7],ee[m-16]),Z=la(K,P,C,te[m-7],te[m-16]);te[m]=Z|0,ee[m]=K|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:S,Gh:b,Gl:y,Hh:x,Hl:v}=this;for(let m=0;m<80;m++){let _=de(l,d,14)^de(l,d,18)^yr(l,d,41),A=he(l,d,14)^he(l,d,18)^br(l,d,41),P=l&p^~l&b,F=d&S^~d&y,k=da(v,A,F,fl[m],ee[m]),R=ha(k,x,_,P,ul[m],te[m]),C=k|0,z=de(n,o,28)^yr(n,o,34)^yr(n,o,39),K=he(n,o,28)^br(n,o,34)^br(n,o,39),Z=n&s^n&a^s&a,B=o&i^o&c^i&c;x=b|0,v=y|0,b=p|0,y=S|0,p=l|0,S=d|0,{h:l,l:d}=zt(u|0,f|0,R|0,C|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let U=ca(C,K,B);n=ua(U,R,z,Z),o=U|0}({h:n,l:o}=zt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=zt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=zt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=zt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=zt(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:S}=zt(this.Fh|0,this.Fl|0,p|0,S|0),{h:b,l:y}=zt(this.Gh|0,this.Gl|0,b|0,y|0),{h:x,l:v}=zt(this.Hh|0,this.Hl|0,x|0,v|0),this.set(n,o,s,i,a,c,u,f,l,d,p,S,b,y,x,v)}roundClean(){pe(te,ee)}destroy(){this.destroyed=!0,pe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},es=class extends ts{constructor(){super(64,Ea)}};var va=Wo(()=>new Jo,Xo(1));var rs=Wo(()=>new es,Xo(3));function ln(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var $=(e,t,r)=>Tt(e,t,r),ns=Vt;function Aa(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function re(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function me(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var xr=cn,Dt=(...e)=>Go(...e),Ue=e=>un(e),oe=nn,ge=e=>ya(e),fn=BigInt(0),_a=BigInt(1),ll=e=>e?`"${e}" `:"";function xt(e,t=""){if(typeof e!="boolean")throw new TypeError(ll(t)+"expected boolean, got type="+typeof e);return e}function dn(e){if(typeof e=="bigint"){if(!ne(e))throw new RangeError("positive bigint expected, got "+e)}else ns(e);return e}function jt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function Er(e){let t=dn(e).toString(16);return t.length&1?"0"+t:t}function Ia(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?fn:BigInt("0x"+e)}function qt(e){return Ia(cn(e))}function ye(e){return Ia(cn(Sr(Tt(e)).reverse()))}function hn(e,t){if(Vt(t),t===0)throw new Error("zero output length is invalid");e=dn(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return un(n.padStart(r,"0"))}function os(e,t){return hn(e,t).reverse()}function Sr(e){return Uint8Array.from($(e))}function ne(e){return typeof e=="bigint"&&fn<=e}function ss(e,t,r){return ne(e)&&ne(t)&&ne(r)&&t<=e&&e<r}function Me(e,t,r,n){if(!ss(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ke(e){if(e<fn)throw new Error("expected non-negative bigint, got "+e);return e===fn?0:e.toString(2).length}var vr=e=>(jt(e,"n"),(_a<<BigInt(e))-_a);function Ba(e,t,r){if(Vt(e,"hashLen"),Vt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...y)=>r(u,Dt(c,...y)),p=(y=o)=>{u=d(s,y),c=d(),y.length!==0&&(u=d(i,y),c=d())},S=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,x=[];for(;y<t;){c=d();let v=c.slice();x.push(v),y+=c.length}return Dt(...x)};return(y,x)=>{l(),p(y);let v;for(;(v=x(S()))===void 0;)p();return l(),v}}function Et(e,t={},r={},n="object"){re(e,n),re(t,"fields"),re(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=e[i];if(!Object.hasOwn(e,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var it=BigInt(0),V=BigInt(1),se=BigInt(2),Ra=BigInt(3),is=BigInt(4),La=BigInt(5),dl=BigInt(7),Ca=BigInt(8),hl=BigInt(9),pl=BigInt(15),Oa=BigInt(16),ml=BigInt("0x10000000000000000");function tt(e,t){if(t<=it)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=it?r:t+r}function Pa(e,t,r){if(r<=V)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<it)throw new Error("invalid exponent, negatives unsupported");if(t===it)return V;if(t===V)return e;let n=e%r;if(n<it&&(n+=r),t<ml){let a=V;for(;t>it;)t&V&&(a=a*n%r),n=n*n%r,t>>=V;return a}let o=[];for(;t>it;)o.push(Number(t&pl)),t>>=is;let s=new Array(16);s[0]=V,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function Q(e,t,r){if(r<=V)throw new Error("pow2: expected modulus > 1, got "+r);if(t<it)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >it;)n*=n,n%=r;return n}function Ta(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=V)throw new Error("invert: expected modulus > 1, got "+t);let r=tt(e,t),n=t,o=it,s=V;for(;r!==it;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==V)throw new Error("invert: does not exist");return tt(o,t)}function ka(e,t){if(t<=V)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=tt(e,t);if(r===it)throw new Error("invertCt: expected non-zero number");let n=Pa(r,t-se,t);if(tt(r*n,t)!==V)throw new Error("invertCt: does not exist");return n}function as(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function cs(e,t){if((e&V)===it)throw new Error(t+": expected odd modulus, got "+e)}function Na(e,t){let r=e,n=(r.ORDER+V)/is,o=r.pow(t,n);return as(r,o,t),o}function gl(e,t){let r=e,n=(r.ORDER-La)/Ca,o=r.mul(t,se),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,se),s),c=r.mul(i,r.sub(a,r.ONE));return as(r,c,t),c}function yl(e){let t=qe(e),r=Fa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+dl)/Oa;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),p=u.mul(f,s),S=u.eql(u.sqr(l),c),b=u.eql(u.sqr(d),c);f=u.cmov(f,l,S),l=u.cmov(p,d,b);let y=u.eql(u.sqr(l),c),x=u.cmov(f,l,y);return as(u,x,c),x})}function Fa(e){if(e<Ra)throw new Error("sqrt is not defined for small field");cs(e,"tonelliShanks");let t=e-V,r=0;for(;t%se===it;)t/=se,r++;let n=se,o=qe(e);for(;_r(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Na;let s=o.pow(n,t),i=(t+V)/se;return function(c,u){let f=c;if(f.is0(u))return u;if(_r(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),p=f.pow(u,t),S=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let b=1,y=f.sqr(p);for(;!f.eql(y,f.ONE);)if(b++,y=f.sqr(y),b===l)throw new Error("Cannot find square root");let x=V<<BigInt(l-b-1),v=f.pow(d,x);l=b,d=f.sqr(v),p=f.mul(p,d),S=f.mul(S,v)}return S}}function bl(e){return cs(e,"Fp.sqrt"),e%is===Ra?Na:e%Ca===La?gl:e%Oa===hl?yl(e):Fa(e)}var Ua=(e,t)=>(tt(e,t)&V)===V,wl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ze(e){if(re(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);jt(e.BYTES,"BYTES"),jt(e.BITS,"BITS");for(let t of wl)me(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=V)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function mn(e,t,r=!1){ze(e),ln(t,"nums"),xt(r,"passZero");let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function _r(e,t){ze(e);let r=e;cs(r.ORDER,"FpLegendre");let n=(r.ORDER-V)/se,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function xl(e,t){if(t!==void 0&&ns(t),e<=it)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Ke(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Da=new WeakMap,pn=class{ORDER;BITS;BYTES;isLE;ZERO=it;ONE=V;_lengths;_mod;constructor(t,r={}){if(t<=V)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=xl(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return tt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return it<=t&&t<this.ORDER}is0(t){return t===it}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return Pa(t,r,this.ORDER)}div(t,r){return tt(t*Ta(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Ta(t,this.ORDER)}sqrt(t){let r=Da.get(this);return r||Da.set(this,r=bl(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?os(t,this.BYTES):hn(t,this.BYTES)}fromBytes(t,r=!1){$(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?ye(t):qt(t);if(a&&(c=tt(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return mn(this,t,!0)}cmov(t,r,n){return xt(n,"condition"),n?r:t}};function qe(e,t={}){return Object.freeze(pn.prototype),new pn(e,t)}function Ma(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=V)throw new Error("field order must be greater than 1");let t=Ke(e-V);return Math.ceil(t/8)}function gn(e){let t=Ma(e);return t+Math.ceil(t/2)}function yn(e,t,r=!1){$(e);let n=e.length,o=Ma(t),s=Math.max(gn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ye(e):qt(e),a=tt(i,t-V)+V;return r?os(a,o):hn(a,o)}var ls=BigInt(0),Ar=BigInt(1),El=BigInt(4),us=16,Ka=128,Sl=5,za=2**31;function ie(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);me(t.fromAffine,"Point.fromAffine"),me(t.fromBytes,"Point.fromBytes"),me(t.fromHex,"Point.fromHex"),re(t.BASE,"Point.BASE"),re(t.ZERO,"Point.ZERO"),ze(t.Fp),ze(t.Fn)}function bn(e,t){ie(e),Ha(t,e);let r=mn(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function vl(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function _l(e,t){let r=e*(4*t+128);if(r>za)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+za/2**20+" MiB")}function ds(e,t){if(e!==void 0){me(e,"randomBytes");try{let r=e(t);if(!oe(r)||r.length!==t)return}catch{return}return e}}function Ha(e,t){ln(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Al(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,o)=>{if(!(r===void 0?t.isValid(n):ne(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var $a=new WeakMap;function fs(e){return $a.get(e)||1}function Il(e,t){let r=e.double(),n=[e];for(let o=1;o<t;o++)n.push(n[o-1].add(r));return n}function Bl(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>ls;){let i=0;e&Ar&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=Ar}return s}function Tl(e,t,r){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&s);e>>=i,u>o&&(u-=n,e+=Ar),a.push(u)}if(e!==ls)throw new Error("invalid wnaf");return a}function Dl(e,t,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=e;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=t[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var He=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){ie(t),this.randomBytes=ds(r,us),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=t;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(t,r){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=Tl(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],d=f*i,p=Math.abs(l)-1,S=s[d];for(let y=1;y<i;y++)S=y===p?s[d+y]:S;let b=S.negate();l===0?u=u.add(s[d]):c=c.add(l<0?b:S)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===t&&a.bits===n);return i||(i=this.buildWnafTable(r,t,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!ss(r,Ar,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=fs(t);return s===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Ka,s=this.randomBytes(us);if(!oe(s)||s.length!==us)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+qt(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,r,n){let o=Sl,s=1<<o,i=vr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<o;p++)u=u.double();let l=Number(r>>BigInt(f*o)&i),d=a[0];for(let p=1;p<s;p++)d=p===l?a[p]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===Ar?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,o):this.mulCT(t,r,o)}mulUnsafe(t,r,n){if(this.assertPoint(t),!ne(r))throw new Error("invalid scalar");let o=fs(t);if(o===1||r>=this.Point.Fn.ORDER)return wn(this.Point,[t],[r],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(t,r){this.assertPoint(t),vl(r,this.bits);let n=Math.ceil((this.bits+Ka)/r)+1;_l(n*2**(r-1),this.Point.Fp.BYTES),$a.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return fs(t)!==1}};function wn(e,t,r,n=!1){if(ie(e),Ha(t,e),xt(n,"allowOversized"),Al(r,e.Fn,n?e.Fn.ORDER**El:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>Il(i,4)),s=r.map(i=>Bl(i,4));return Dl(e.ZERO,o,s)}function qa(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ze(t),t}else return qe(e,{isLE:r})}function xn(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);Et(r);for(let c of["p","n","h"]){let u=t[c];if(!(ne(u)&&u!==ls))throw new Error(`CURVE.${c} must be positive bigint`)}let o=qa(t.p,r.Fp,n),s=qa(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function En(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Sn=BigInt(0),vn=BigInt(1),_n=BigInt(2),Rl=BigInt(4),Va=BigInt(8);function Ll(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function ja(e,t={}){Et(t,{},{},"extraOpts");let r=t,n=xn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(_r(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(_r(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Et(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?ge:r.randomBytes,u=_n<<BigInt(o.BYTES*8)-vn;function f(v){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(v)}let l=r.uvRatio===void 0?(v,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,m))}}catch{return{isValid:!1,value:Sn}}}:r.uvRatio;if(!Ll(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=o.eql(i.a,o.neg(o.ONE))?v=>o.neg(v):o.eql(i.a,o.ONE)?v=>v:v=>o.mul(i.a,v);function p(v,m,_=!1){let A=_?vn:Sn;return Me("coordinate "+v,m,A,u),m}function S(v){if(!(v instanceof b))throw new Error("EdwardsPoint expected")}class b{static BASE=new b(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new b(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,_,A,P){this.X=p("x",m),this.Y=p("y",_),this.Z=p("z",A,!0),this.T=p("t",P),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof b)throw new Error("extended point not allowed");let{x:_,y:A}=m||{};return p("x",_),p("y",A),new b(_,A,o.ONE,o.mul(_,A))}static fromBytes(m,_=!1){let A=o.BYTES,{a:P,d:F}=i;m=Sr($(m,A,"point")),xt(_,"zip215");let k=Sr(m),R=m[A-1];k[A-1]=R&-129;let C=ye(k),z=_?u:o.ORDER;Me("point.y",C,Sn,z);let K=o.sqr(C),Z=o.sub(K,o.ONE),B=o.sub(o.mulN(F,K),P),{isValid:U,value:M}=l(Z,B);if(!U)throw new Error("bad point: invalid y coordinate");let L=f(M),Y=(R&128)!==0;if(!_&&o.is0(M)&&Y)throw new Error("bad point: x=0 and x_0=1");return Y!==L&&(M=o.neg(M)),b.fromAffine({x:M,y:C})}static fromHex(m,_=!1){return b.fromBytes(Ue(m),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=6,_=!0){return x.setWindowSize(this,m),_||this.multiply(_n),this}assertValidity(){let m=this,{a:_,d:A}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:P,Y:F,Z:k,T:R}=m,C=o.sqr(P),z=o.sqr(F),K=o.sqr(k),Z=o.sqr(K),B=o.mul(C,_),U=o.mul(o.add(B,z),K),M=o.add(Z,o.mul(A,o.mul(C,z)));if(!o.eql(U,M))throw new Error("bad point: equation left != right (1)");let L=o.mul(P,F),Y=o.mul(k,R);if(!o.eql(L,Y))throw new Error("bad point: equation left != right (2)")}equals(m){S(m);let{X:_,Y:A,Z:P}=this,{X:F,Y:k,Z:R}=m,C=o.mul(_,R),z=o.mul(F,P),K=o.mul(A,R),Z=o.mul(k,P);return o.eql(C,z)&&o.eql(K,Z)}is0(){return this.equals(b.ZERO)}negate(){return new b(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:m,Y:_,Z:A}=this,P=o.sqr(m),F=o.sqr(_),k=o.mul(o.sqr(A),_n),R=d(P),C=o.addN(m,_),z=o.sub(o.subN(o.sqr(C),P),F),K=o.addN(R,F),Z=o.subN(K,k),B=o.subN(R,F),U=o.mul(z,Z),M=o.mul(K,B),L=o.mul(z,B),Y=o.mul(Z,K);return new b(U,M,Y,L)}add(m){S(m);let{d:_}=i,{X:A,Y:P,Z:F,T:k}=this,{X:R,Y:C,Z:z,T:K}=m,Z=o.mul(A,R),B=o.mul(P,C),U=o.mul(o.mulN(k,_),K),M=o.mul(F,z),L=o.sub(o.subN(o.mulN(o.addN(A,P),o.addN(R,C)),Z),B),Y=o.subN(M,U),J=o.addN(M,U),E=o.sub(B,d(Z)),h=o.mul(L,Y),g=o.mul(J,E),w=o.mul(L,E),I=o.mul(Y,J);return new b(h,g,I,w)}subtract(m){return S(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:_,f:A}=x.mulSecret(this,m,a,y);return y([_,A])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===Sn?b.ZERO:this.is0()||m===vn?this:x.mulUnsafe(this,m,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(m){let _=this,A=m;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:P,Y:F,Z:k}=_,R=_.is0();A==null&&(A=R?o.create(Va):o.inv(k));let C=o.mul(P,A),z=o.mul(F,A),K=o.mul(k,A);if(R)return{x:o.ZERO,y:o.ONE};if(!o.eql(K,o.ONE))throw new Error("invZ was invalid");return{x:C,y:z}}clearCofactor(){return a===vn?this:a===_n?this.double():a===Rl?this.double().double():a===Va?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:m,y:_}=this.toAffine(),A=o.toBytes(_);return A[A.length-1]|=f(m)?128:0,A}toHex(){return xr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=v=>bn(b,v),x=new He(b,c);return x.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function Za(e,t,r={}){if(ie(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Et(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(jt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?ge:o.randomBytes,d=o.toMontgomery,p=o.toMontgomerySecret,S=o.adjustScalarBytes===void 0?B=>B:o.adjustScalarBytes,b=o.domain===void 0?(B,U,M)=>{if(xt(M,"phflag"),U.length||M)throw new Error("Contexts/pre-hash are not supported");return B}:o.domain;function y(B){return c.create(ye(B))}function x(B){let U=R.secretKey;$(B,R.secretKey,"secretKey");let M=$(n(B),2*U,"hashedSecretKey"),L=S(M.slice(0,U)),Y=M.slice(U,2*U),J=y(L);return{head:L,prefix:Y,scalar:J}}function v(B){let{head:U,prefix:M,scalar:L}=x(B),Y=i.multiply(L),J=Y.toBytes();return{head:U,prefix:M,scalar:L,point:Y,pointBytes:J}}function m(B){return v(B).pointBytes}function _(B=Uint8Array.of(),...U){let M=Dt(...U);return y(n(b(M,$(B,void 0,"context"),!!s)))}function A(B,U,M={}){Et(M,{},{},"options"),B=Sr($(B,void 0,"message")),s&&(B=s(B));let{prefix:L,scalar:Y,pointBytes:J}=v(U),E=_(M.context,L,B),h=i.multiply(E).toBytes(),g=_(M.context,h,J,B),w=c.create(E+g*Y);if(!c.isValid(w))throw new Error("sign failed: invalid s");let I=Dt(h,c.toBytes(w));return $(I,R.signature,"result")}let P={zip215:o.zip215};function F(B,U,M,L=P){Et(L);let{context:Y}=L,J=L.zip215===void 0?!!P.zip215:L.zip215,E=R.signature;B=$(B,E,"signature"),U=$(U,void 0,"message"),M=$(M,R.publicKey,"publicKey"),J!==void 0&&xt(J,"zip215"),s&&(U=s(U));let h=E/2,g=B.subarray(0,h),w=ye(B.subarray(h,E)),I,T,D;try{I=e.fromBytes(M,J),T=e.fromBytes(g,J),D=i.multiplyUnsafe(w)}catch{return!1}if(!J&&I.isSmallOrder())return!1;let O=_(Y,g,M,U);return T.add(I.multiplyUnsafe(O)).subtract(D).clearCofactor().is0()}let k=a.BYTES,R={secretKey:k,publicKey:k,signature:2*k,seed:k};function C(B){return B=B===void 0?l(R.seed):B,$(B,R.seed,"seed")}function z(B){return oe(B)&&B.length===R.secretKey}function K(B,U){try{return!!e.fromBytes(B,U===void 0?P.zip215:U)}catch{return!1}}let Z={getExtendedPublicKey:v,randomSecretKey:C,isValidSecretKey:z,isValidPublicKey:K,toMontgomery(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(e.fromBytes(B))},toMontgomerySecret(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(B)}};return Object.freeze(R),Object.freeze(Z),Object.freeze({keygen:En(C,m),getPublicKey:m,sign:A,verify:F,utils:Z,Point:e,lengths:R})}var hs=BigInt(1),Ya=BigInt(2);var Cl=BigInt(5),Ol=BigInt(8),ps=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Pl={p:ps,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ol,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function kl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ps,a=e*e%s*e%s,c=Q(a,Ya,s)*a%s,u=Q(c,hs,s)*e%s,f=Q(u,Cl,s)*u%s,l=Q(f,t,s)*f%s,d=Q(l,r,s)*l%s,p=Q(d,n,s)*d%s,S=Q(p,o,s)*p%s,b=Q(S,o,s)*p%s,y=Q(b,t,s)*f%s;return{pow_p_5_8:Q(y,Ya,s)*e%s,b2:a}}function Xa(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ga=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Nl(e,t){let r=ps,n=tt(t*t*t,r),o=tt(n*n*t,r),s=kl(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,u=tt(i*Ga,r),f=a===e,l=a===tt(-e,r),d=a===tt(-e*Ga,r);return f&&(i=c),(l||d)&&(i=u),Ua(i,r)&&(i=tt(-i,r)),{isValid:f||l,value:i}}var ms=ja(Pl,{uvRatio:Nl}),Wa=ms.Fp;function Fl(e){let{y:t}=e;return Wa.toBytes(Wa.div(hs+t,hs-t))}function Ul(e){let t=ms.Fp.BYTES;return Tt(e,t),Xa(rs(e.subarray(0,t))).subarray(0,t)}function Ml(e){return Za(ms,rs,Object.assign({adjustScalarBytes:Xa,toMontgomery:Fl,toMontgomerySecret:Ul,zip215:!0},e))}var Qa=Ml({});var Ir=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},An=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var In={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new An("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Bn=32;var gs,Kl=(async()=>{try{return await In.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function zl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await In.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await In.get().subtle.verify({name:"Ed25519"},n,kt(t),kt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ql(e,t,r){return Qa.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ja(e,t,r){return gs==null&&(gs=await Kl),gs?zl(e,t,r):ql(e,t,r)}function Tn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Dn=class{type="Ed25519";raw;constructor(t){this.raw=ys(t,Bn)}toMultihash(){return Pt.digest(Ne(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ja(this.raw,r,t);return Tn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ec(e){return e=ys(e,Bn),new Dn(e)}function ys(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new yt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var $l=Math.pow(2,7),Vl=Math.pow(2,14),jl=Math.pow(2,21),bs=Math.pow(2,28),ws=Math.pow(2,35),xs=Math.pow(2,42),Es=Math.pow(2,49),j=128,mt=127;function St(e){if(e<$l)return 1;if(e<Vl)return 2;if(e<jl)return 3;if(e<bs)return 4;if(e<ws)return 5;if(e<xs)return 6;if(e<Es)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $e(e,t,r=0){switch(St(e)){case 8:t[r++]=e&255|j,e/=128;case 7:t[r++]=e&255|j,e/=128;case 6:t[r++]=e&255|j,e/=128;case 5:t[r++]=e&255|j,e/=128;case 4:t[r++]=e&255|j,e>>>=7;case 3:t[r++]=e&255|j,e>>>=7;case 2:t[r++]=e&255|j,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Zl(e,t,r=0){switch(St(e)){case 8:t.set(r++,e&255|j),e/=128;case 7:t.set(r++,e&255|j),e/=128;case 6:t.set(r++,e&255|j),e/=128;case 5:t.set(r++,e&255|j),e/=128;case 4:t.set(r++,e&255|j),e>>>=7;case 3:t.set(r++,e&255|j),e>>>=7;case 2:t.set(r++,e&255|j),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Ss(e,t){let r=e[t],n=0;if(n+=r&mt,r<j||(r=e[t+1],n+=(r&mt)<<7,r<j)||(r=e[t+2],n+=(r&mt)<<14,r<j)||(r=e[t+3],n+=(r&mt)<<21,r<j)||(r=e[t+4],n+=(r&mt)*bs,r<j)||(r=e[t+5],n+=(r&mt)*ws,r<j)||(r=e[t+6],n+=(r&mt)*xs,r<j)||(r=e[t+7],n+=(r&mt)*Es,r<j))return n;throw new RangeError("Could not decode varint")}function Yl(e,t){let r=e.get(t),n=0;if(n+=r&mt,r<j||(r=e.get(t+1),n+=(r&mt)<<7,r<j)||(r=e.get(t+2),n+=(r&mt)<<14,r<j)||(r=e.get(t+3),n+=(r&mt)<<21,r<j)||(r=e.get(t+4),n+=(r&mt)*bs,r<j)||(r=e.get(t+5),n+=(r&mt)*ws,r<j)||(r=e.get(t+6),n+=(r&mt)*xs,r<j)||(r=e.get(t+7),n+=(r&mt)*Es,r<j))return n;throw new RangeError("Could not decode varint")}function rc(e,t,r=0){return t==null&&(t=pt(St(e))),t instanceof Uint8Array?$e(e,t,r):Zl(e,t,r)}function Br(e,t=0){return e instanceof Uint8Array?Ss(e,t):Yl(e,t)}var vs=new Float32Array([-0]),ae=new Uint8Array(vs.buffer);function oc(e,t,r){vs[0]=e,t[r]=ae[0],t[r+1]=ae[1],t[r+2]=ae[2],t[r+3]=ae[3]}function sc(e,t){return ae[0]=e[t],ae[1]=e[t+1],ae[2]=e[t+2],ae[3]=e[t+3],vs[0]}var _s=new Float64Array([-0]),gt=new Uint8Array(_s.buffer);function ic(e,t,r){_s[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function ac(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],_s[0]}var Gl=BigInt(Number.MAX_SAFE_INTEGER),Wl=BigInt(Number.MIN_SAFE_INTEGER),_t=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return be;if(t<Gl&&t>Wl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>cc&&(o=0n,++n>cc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return be;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):be}},be=new _t(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var cc=4294967296n;function uc(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function fc(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function As(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Ft(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Rn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Is=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=kt(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,Ft(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 Ft(this,4);return Rn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ft(this,4);return Rn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ft(this,4);let t=sc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ft(this,4);let t=ac(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Ft(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return fc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ft(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ft(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 _t(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ft(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Ft(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ft(this,8);let t=Rn(this.buf,this.pos+=4),r=Rn(this.buf,this.pos+=4);return new _t(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ss(this.buf,this.pos);return this.pos+=St(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 Tr(e){return new Is(e instanceof Uint8Array?e:e.subarray())}function Rt(e,t,r){let n=Tr(e);return t.decode(n,void 0,r)}function Bs(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return pt(i);o+i>t&&(n=pt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var we=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ts(){}var Rs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Xl=Bs();function Ql(e){return globalThis.Buffer!=null?pt(e):Xl(e)}var Rr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(Ts,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new we(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ls((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(Ln,10,_t.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=_t.fromBigInt(t);return this._push(Ln,r.length(),r)}uint64Number(t){return this._push($e,St(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=_t.fromBigInt(t).zzEncode();return this._push(Ln,r.length(),r)}sint64Number(t){let r=_t.fromNumber(t).zzEncode();return this._push(Ln,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ds,1,t?1:0)}fixed32(t){return this._push(Dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=_t.fromBigInt(t);return this._push(Dr,4,r.lo)._push(Dr,4,r.hi)}fixed64Number(t){let r=_t.fromNumber(t);return this._push(Dr,4,r.lo)._push(Dr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(oc,4,t)}double(t){return this._push(ic,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ds,1,0):this.uint32(r)._push(td,r,t)}string(t){let r=uc(t);return r!==0?this.uint32(r)._push(As,r,t):this._push(Ds,1,0)}fork(){return this.states=new Rs(this),this.head=this.tail=new we(Ts,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 we(Ts,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Ql(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ds(e,t,r){t[r]=e&255}function Jl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ls=class extends we{next;constructor(t,r){super(Jl,t,r),this.next=void 0}};function Ln(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Dr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function td(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Rr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(ed,t,e),this},Rr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(rd,t,e),this});function ed(e,t,r){t.set(e,r)}function rd(e,t,r){e.length<40?As(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(X(e),r)}function Cs(){return new Rr}function Lt(e,t){let r=Cs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Ct(e,t,r){let n=Tr(e);yield*t.stream(n,void 0,".",r)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function On(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function xe(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i,a){};return On("enum",Cn.VARINT,r,n,o)}function Ot(e,t,r){return On("message",Cn.LENGTH_DELIMITED,e,t,r)}var Lr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var bt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(bt||(bt={}));var Os;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Os||(Os={}));(function(e){e.codec=()=>xe(Os)})(bt||(bt={}));var Cr;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),bt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:bt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(Cr||(Cr={}));var Ps;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),bt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:bt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(Ps||(Ps={}));var Pn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(on(t),Tt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),pe(o)}update(t){return Fe(this),this.iHash.update(t),this}digestInto(t){Fe(this),sn(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.canXOF=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},dc=(()=>{let e=((t,r,n)=>new Pn(t,r).update(n).digest());return e.create=(t,r)=>new Pn(t,r),e})();var od=BigInt(0),ks=class extends Error{constructor(t=""){super(t)}},Zt={Err:ks,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(jt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(Aa(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Er(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Er(o.length/2|128):"";return Er(e)+s+o+t},decode(e,t){let{Err:r}=Zt;t=$(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Zt;if(dn(e),e<od)throw new t("integer: negative integers are not allowed");let r=Er(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Zt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return qt(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:o}=Zt;if(t!==void 0&&(jt(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=$(e,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||f.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt;Et(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},kn=(Object.freeze(Zt._tlv),Object.freeze(Zt._int),Object.freeze(Zt));var hc=(e,t)=>(e+(e>=0?t:-t)/pc)/t;function sd(e,t,r){Me("scalar",e,Yt,r);let[[n,o],[s,i]]=t,a=hc(i*e,r),c=hc(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<Yt,d=f<Yt;l&&(u=-u),d&&(f=-f);let p=vr(Math.ceil(Ke(r)/2))+Ee;if(u<Yt||u>=p||f<Yt||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Us(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ns(e,t){Et(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return xt(r.lowS,"lowS"),xt(r.prehash,"prehash"),r.format!==void 0&&Us(r.format),r}var Yt=BigInt(0),Ee=BigInt(1),pc=BigInt(2),Fs=BigInt(3),id=BigInt(4);function mc(e,t={}){let r=xn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Et(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:d,toBytes:p}=t,S=t.randomBytes===void 0?ge:t.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=c?{beta:c.beta,basises:c.basises.map(E=>[...E])}:void 0,y=yc(n,o);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function v(E,h,g){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:w,y:I}=h.toAffine(),T=n.toBytes(w);if(xt(g,"isCompressed"),g){x();let D=!n.isOdd(I);return Dt(gc(D),T)}else return Dt(Uint8Array.of(4),T,n.toBytes(I))}function m(E){$(E,void 0,"Point");let{publicKey:h,publicKeyUncompressed:g}=y,w=E.length,I=E[0],T=E.subarray(1);if(u&&w===1&&I===0)return{x:n.ZERO,y:n.ZERO};if(w===h&&(I===2||I===3)){let D=n.fromBytes(T);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let O=k(D),N;try{N=n.sqrt(O)}catch(rt){let G=rt instanceof Error?": "+rt.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}x();let H=n.isOdd(N);return(I&1)===1!==H&&(N=n.neg(N)),{x:D,y:N}}else if(w===g&&I===4){let D=n.BYTES,O=n.fromBytes(T.subarray(0,D)),N=n.fromBytes(T.subarray(D,D*2));if(!R(O,N))throw new Error("bad point: is not on curve");return{x:O,y:N}}else throw new Error(`bad point: got length ${w}, expected compressed=${h} or uncompressed=${g}`)}let _=p===void 0?v:p,A=d===void 0?m:d,P=n.mul(s.b,Fs),F=n.is0(s.a)?E=>n.ZERO:E=>n.mul(s.a,E);function k(E){let h=n.sqr(E),g=n.mul(h,E);return n.add(n.add(g,n.mul(E,s.a)),s.b)}function R(E,h){let g=n.sqr(h),w=k(E);return n.eql(g,w)}if(!R(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let C=n.mul(n.pow(s.a,Fs),id),z=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(C,z)))throw new Error("bad curve params: a or b");function K(E,h,g=!1){if(!n.isValid(h)||g&&n.is0(h))throw new Error(`bad point coordinate ${E}`);return typeof h=="object"&&h!==null?n.create(h):h}function Z(E){if(!(E instanceof L))throw new Error("Weierstrass Point expected")}function B(E){if(!b||!b.basises)throw new Error("no endo");return sd(E,b.basises,o.ORDER)}function U(E,h,g,w){if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:I,k1:T,k2neg:D,k2:O}=B(w),N=new L(n.mul(g.X,b.beta),g.Y,g.Z);E.push(I?g.negate():g,D?N.negate():N),h.push(T,O)}else E.push(g),h.push(w)}let M=new WeakSet;class L{static BASE=new L(s.Gx,s.Gy,n.ONE);static ZERO=new L(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,g,w){this.X=K("x",h),this.Y=K("y",g,!0),this.Z=K("z",w),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:g,y:w}=h||{};if(!h||!n.isValid(g)||!n.isValid(w))throw new Error("invalid affine point");if(h instanceof L)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(w)?L.ZERO:new L(g,w,n.ONE)}static fromBytes(h){let g=L.fromAffine(A($(h,void 0,"point")));return g.assertValidity(),g}static fromHex(h){return L.fromBytes(Ue(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,g=!0){return J.setWindowSize(this,h),g||this.multiply(Fs),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(M.has(h))return;let{x:g,y:w}=h.toAffine();if(!n.isValid(g)||!n.isValid(w))throw new Error("bad point: x or y not field elements");if(!R(g,w))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");M.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){Z(h);let{X:g,Y:w,Z:I}=this,{X:T,Y:D,Z:O}=h,N=n.eql(n.mul(g,O),n.mul(T,I)),H=n.eql(n.mul(w,O),n.mul(D,I));return N&&H}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:g,Z:w}=this,I=n.ZERO,T=n.ZERO,D=n.ZERO,O=n.mul(h,h),N=n.mul(g,g),H=n.mul(w,w),q=n.mul(h,g);return q=n.add(q,q),D=n.mul(h,w),D=n.add(D,D),I=F(D),T=n.mul(P,H),T=n.add(I,T),I=n.sub(N,T),T=n.add(N,T),T=n.mul(I,T),I=n.mul(q,I),D=n.mul(P,D),H=F(H),q=n.sub(O,H),q=F(q),q=n.add(q,D),D=n.add(O,O),O=n.add(D,O),O=n.add(O,H),O=n.mul(O,q),T=n.add(T,O),H=n.mul(g,w),H=n.add(H,H),O=n.mul(H,q),I=n.sub(I,O),D=n.mul(H,N),D=n.add(D,D),D=n.add(D,D),new L(I,T,D)}add(h){Z(h);let{X:g,Y:w,Z:I}=this,{X:T,Y:D,Z:O}=h,N=n.ZERO,H=n.ZERO,q=n.ZERO,rt=n.mul(g,T),G=n.mul(w,D),at=n.mul(I,O),At=n.add(g,w),W=n.add(T,D);At=n.mul(At,W),W=n.add(rt,G),At=n.sub(At,W),W=n.add(g,I);let nt=n.add(T,O);return W=n.mul(W,nt),nt=n.add(rt,at),W=n.sub(W,nt),nt=n.add(w,I),N=n.add(D,O),nt=n.mul(nt,N),N=n.add(G,at),nt=n.sub(nt,N),q=F(W),N=n.mul(P,at),q=n.add(N,q),N=n.sub(G,q),q=n.add(G,q),H=n.mul(N,q),G=n.add(rt,rt),G=n.add(G,rt),at=F(at),W=n.mul(P,W),G=n.add(G,at),at=n.sub(rt,at),at=F(at),W=n.add(W,at),rt=n.mul(G,W),H=n.add(H,rt),rt=n.mul(nt,W),N=n.mul(At,N),N=n.sub(N,rt),rt=n.mul(At,G),q=n.mul(nt,q),q=n.add(q,rt),new L(N,H,q)}subtract(h){return Z(h),this.add(h.negate())}is0(){return this.equals(L.ZERO)}multiply(h){if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:g,f:w}=J.mulSecret(this,h,i,Y);return Y([g,w])[0]}multiplyUnsafe(h){let g=this,w=h;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Yt||g.is0())return L.ZERO;if(w===Ee)return g;if(J.hasWindowSize(this))return J.mulUnsafe(g,w,Y);let I=[],T=[];return U(I,T,g,w),wn(L,I,T)}mulAddUnsafe(h,g,w){Z(g);let I=[],T=[];return U(I,T,this,h),U(I,T,g,w),wn(L,I,T)}toAffine(h){let g=this,w=h;if(w!=null&&!n.isValid(w))throw new RangeError('"invertedZ" expected valid field element');let{X:I,Y:T,Z:D}=g;if(n.eql(D,n.ONE))return{x:I,y:T};let O=g.is0();w==null&&(w=O?n.ONE:n.inv(D));let N=n.mul(I,w),H=n.mul(T,w),q=n.mul(D,w);if(O)return{x:n.ZERO,y:n.ZERO};if(!n.eql(q,n.ONE))throw new Error("invZ was invalid");return{x:N,y:H}}isTorsionFree(){return i===Ee?!0:l?l(L,this):J.mulUnsafe(this,a).is0()}clearCofactor(){return i===Ee?this:f?f(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Ee?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return xt(h,"isCompressed"),this.assertValidity(),_(L,this,h)}toHex(h=!0){return xr(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Y=E=>bn(L,E),J=new He(L,S);return J.bits>=6&&L.BASE.precompute(6),Object.freeze(L.prototype),Object.freeze(L),L}function gc(e){return Uint8Array.of(e?2:3)}function yc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ad(e,t={}){ie(e);let{Fn:r}=e,n=t.randomBytes===void 0?ge:t.randomBytes,o=Object.assign(yc(e.Fp,r),{seed:Math.max(gn(r.ORDER),16)});function s(p){try{let S=r.fromBytes(p);return r.isValidNot0(S)}catch{return!1}}function i(p,S){let{publicKey:b,publicKeyUncompressed:y}=o;try{let x=p.length;return S===!0&&x!==b||S===!1&&x!==y?!1:!e.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,yn($(p,o.seed,"seed"),r.ORDER)}function c(p,S=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(S)}function u(p){let{secretKey:S,publicKey:b,publicKeyUncompressed:y}=o,x=r._lengths;if(!oe(p))return;let v=$(p,void 0,"key").length,m=v===b||v===y,_=v===S||!!x?.includes(v);if(!(m&&_))return m}function f(p,S,b=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(S)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(p),x=e.fromBytes(S);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(y).toBytes(b)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=En(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:e,utils:l,lengths:o})}function bc(e,t,r={}){ie(e);let n=t;on(n),Et(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?ge:o.randomBytes,i=o.hmac===void 0?(E,h)=>dc(n,E,h):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,l=gn(u),d=ds(s,l),{keygen:p,getPublicKey:S,getSharedSecret:b,utils:y,lengths:x}=ad(e,o),v={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},m=u*pc+Ee<a.ORDER;function _(E){let h=u>>Ee;return E>h}function A(E,h){if(!c.isValidNot0(h))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return h}function P(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function F(E,h,g){return P(),(E===g?0:2)|Number(a.isOdd(h))}function k(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(E,h){Us(h);let g=x.signature,w=h==="compact"?g:h==="recovered"?g+1:void 0;return $(E,w)}class C{r;s;recovery;constructor(h,g,w){if(this.r=A("r",h),this.s=A("s",g),w!=null){if(k(),![0,1,2,3].includes(w))throw new Error("invalid recovery id");this.recovery=w}Object.freeze(this)}static fromBytes(h,g=v.format){R(h,g);let w;if(g==="der"){if(h.length>2*c.BYTES+16)throw new kn.Err("invalid signature: DER signature too long");let{r:O,s:N}=kn.toSig($(h),c.BYTES+1);return new C(O,N)}g==="recovered"&&(w=h[0],g="compact",h=h.subarray(1));let I=x.signature/2,T=h.subarray(0,I),D=h.subarray(I,I*2);return new C(c.fromBytes(T),c.fromBytes(D),w)}static fromHex(h,g){return this.fromBytes(Ue(h),g)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new C(this.r,this.s,h)}recoverPublicKey(h){let{r:g,s:w}=this,I=this.assertRecovery(),T=I===2||I===3?g+u:g;if(!a.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=a.toBytes(T),O=e.fromBytes(Dt(gc((I&1)===0),D)),N=c.inv(T),H=K($(h,void 0,"msgHash")),q=c.create(-H*N),rt=c.create(w*N),G=e.BASE.mulAddUnsafe(q,O,rt);if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return _(this.s)}toBytes(h=v.format){if(Us(h),h==="der")return Ue(kn.hexFromSig(this));let{r:g,s:w}=this,I=c.toBytes(g),T=c.toBytes(w);return h==="recovered"?(k(),Dt(Uint8Array.of(this.assertRecovery()),I,T)):Dt(I,T)}toHex(h){return xr(this.toBytes(h))}}Object.freeze(C.prototype),Object.freeze(C);let z=o.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let g=qt(h),w=h.length*8-f;return w>0?g>>BigInt(w):g}:o.bits2int,K=o.bits2int_modN===void 0?function(h){return c.create(z(h))}:o.bits2int_modN,Z=vr(f);function B(E){return Me("num < 2^"+f,E,Yt,Z),c.toBytes(E)}function U(E,h){return $(E,void 0,"message"),h?$(n(E),void 0,"prehashed message"):E}function M(E,h,g){let{lowS:w,prehash:I,extraEntropy:T}=Ns(g,v);E=U(E,I);let D=K(E),O=c.fromBytes(h);if(!c.isValidNot0(O))throw new Error("invalid private key");let N=[B(O),B(D)];if(T!=null&&T!==!1){let G=T===!0?s(x.secretKey):T;N.push($(G,void 0,"extraEntropy"))}let H=Dt(...N),q=D;function rt(G){let at=z(G);if(!c.isValidNot0(at))return;let At=e.BASE.multiply(at).toAffine(),W=c.create(At.x);if(W===Yt)return;let nt;if(d!==void 0){let ir=qt(yn(d(l),u)),yu=c.inv(c.mul(ir,at)),bu=c.mul(ir,q),wu=c.mul(ir,O);nt=c.create(yu*c.create(bu+wu*W))}else{let ir=ka(at,u);nt=c.create(ir*c.create(q+W*O))}if(nt===Yt)return;let ho=F(At.x,At.y,W),Si=nt;return w&&_(nt)&&(Si=c.neg(nt),ho^=1),new C(W,Si,m?void 0:ho)}return{seed:H,k2sig:rt}}function L(E,h,g={}){let{seed:w,k2sig:I}=M(E,h,g);return Ba(n.outputLen,c.BYTES,i)(w,I).toBytes(g.format)}function Y(E,h,g,w={}){let{lowS:I,prehash:T,format:D}=Ns(w,v);if(g=$(g,void 0,"publicKey"),h=U(h,T),!oe(E)){let O=E instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}R(E,D);try{let O=C.fromBytes(E,D),N=e.fromBytes(g);if(N.is0()||I&&O.hasHighS())return!1;let{r:H,s:q}=O,rt=K(h),G=c.inv(q),at=c.create(rt*G),At=c.create(H*G),W=e.BASE.mulAddUnsafe(at,N,At);if(W.is0())return!1;let nt=W.toAffine();return!(c.create(nt.x)!==H||D==="recovered"&&O.recovery!==F(nt.x,nt.y,H))}catch{return!1}}function J(E,h,g={}){let{prehash:w}=Ns(g,v);return h=U(h,w),C.fromBytes(E,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:p,getPublicKey:S,getSharedSecret:b,utils:y,lengths:x,Point:e,sign:L,verify:Y,recoverPublicKey:J,Signature:C,hash:n})}var Ks={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},cd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var wc=BigInt(2);function ud(e){let t=Ks.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=Q(f,r,t)*f%t,d=Q(l,r,t)*f%t,p=Q(d,wc,t)*u%t,S=Q(p,o,t)*p%t,b=Q(S,s,t)*S%t,y=Q(b,a,t)*b%t,x=Q(y,c,t)*y%t,v=Q(x,a,t)*b%t,m=Q(v,r,t)*f%t,_=Q(m,i,t)*S%t,A=Q(_,n,t)*u%t,P=Q(A,wc,t);if(!Ms.eql(Ms.sqr(P),e))throw new Error("Cannot find square root");return P}var Ms=qe(Ks.p,{sqrt:ud}),fd=mc(Ks,{Fp:Ms,endo:cd}),Ve=bc(fd,va);function xc(e,t,r,n){let o=hr.digest(r instanceof Uint8Array?r:r.subarray());if(Tn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ir(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Ir(String(s))}}var Nn=class{type="secp256k1";raw;_key;constructor(t){this._key=Sc(t),this.raw=Ec(this._key)}toMultihash(){return Pt.digest(Ne(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,r,n){return xc(this._key,r,t,n)}};function vc(e){return new Nn(e)}function Ec(e){return Ve.Point.fromBytes(e).toBytes()}function Sc(e){try{return Ve.Point.fromBytes(e),e}catch(t){throw new Zr(String(t))}}function _c(e){let{Type:t,Data:r}=Cr.decode(e.digest),n=r??new Uint8Array;switch(t){case bt.Ed25519:return ec(n);case bt.secp256k1:return vc(n);case bt.ECDSA:return ra(n);default:throw new ar}}function Ne(e){return Cr.encode({Type:bt[e.type],Data:e.raw})}var Ac=Symbol.for("nodejs.util.inspect.custom"),ld=114,Or=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()})`}[mo]=!0;toString(){return this.string==null&&(this.string=ot.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(ld,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")}[Ac](){return`PeerId(${this.toString()})`}},Fn=class extends Or{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Un=class extends Or{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Mn=class extends Or{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},dd=2336,Kn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Pt.digest(X(this.url))}[Ac](){return`PeerId(${this.url})`}[mo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(dd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=st(t)),t.toString()===this.toString())}};function Ic(e){if(pd(e))return new Fn({multihash:e});if(hd(e))try{let t=_c(e);if(t.type==="Ed25519")return new Un({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Mn({multihash:e,publicKey:t})}catch{let r=st(e.digest);return new Kn(new URL(r))}throw new Gr("Supplied PeerID Multihash is invalid")}function hd(e){return e.code===Pt.code}function pd(e){return e.code===hr.code}function zs(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function zn(e){let t=lr(ot.decode(`z${e}`));return Ic(t)}var qn=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return zs(this.set.entries(),t=>{let r=zn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=zn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return zs(this.set.values(),t=>zn(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function qs(){return new qn}var Hs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Bc={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Tc=new globalThis.TextEncoder;function md(e,t){let r=Hs[t],n=Bc[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function gd(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Hs[t],o=Bc[t],s=e;for(;s.length>0;){let i=Tc.encodeInto(s,r);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(t,o*n)}return o}function $s(e,{size:t=32,utf8Buffer:r}={}){if(!Hs[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof e=="string"){if(r)return gd(e,t,r);e=Tc.encode(e)}return md(e,t)}var Pr={hash:e=>Number($s(e,{size:32})),hashV:(e,t)=>yd(Pr.hash(e,t))};function yd(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),X(t,"base16")}var Vs=64,Ut=class{fp;h;seed;constructor(t,r,n,o=2){if(o>Vs)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=wt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,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 Se(e,t){return Math.floor(Math.random()*(t-e))+e}var ve=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Ut))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Ut))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=t,!0;return!0}swap(t){if(!(t instanceof Ut))throw new TypeError("Invalid Fingerprint");let r=Se(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=t,n}remove(t){if(!(t instanceof Ut))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var bd=500,kr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Pr,this.seed=t.seed??Se(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=X(t));let r=new Ut(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ve(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ve(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[Se(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ve(this.bucketSize));for(let a=0;a<bd;a++){let c=this.buckets[i].swap(r);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ve(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=X(t));let r=new Ut(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(t){typeof t=="string"&&(t=X(t));let r=new Ut(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},wd={1:.5,2:.84,4:.95,8:.98};function xd(e=.001){return e>.002?2:e>1e-5?4:8}function Dc(e,t=.001){let r=xd(t),n=wd[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),Vs);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var Hn=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??Pr,this.seed=t.seed??Se(0,Math.pow(2,10)),this.filterSeries=[new kr({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 r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new kr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(t)}has(t){typeof t=="string"&&(t=X(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=X(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,r)=>t+r.count,0)}};function js(e,t=.001,r){return new Hn({...Dc(e,t),...r??{}})}function Nr(e){let t=e.getComponents(),r={},n=0;return t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r)}function je(e){let t=Nr(e);if(t==null)throw new yt(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var $n=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Rc=45,Ed=15,Ze=new $n;function Vn(e){if(!(e.length>Ed))return Ze.new(e).parseWith(()=>Ze.readIPv4Addr())}function jn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Rc))return Ze.new(e).parseWith(()=>Ze.readIPv6Addr())}function Ye(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Rc)return;let r=Ze.new(e).parseWith(()=>Ze.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function Lc(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Cc(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Zs(e){switch(e.length){case _e:return e.join(".");case Ae:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Oc(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function Pc(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var _e=4,Ae=16,Lb=parseInt("0xFFFF",16),Sd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Fr(e,t){t.length===Ae&&e.length===_e&&Lc(t,0,11)&&(t=t.slice(12)),t.length===_e&&e.length===Ae&&Cc(e,Sd,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function kc(e,t){if(typeof t=="string"&&(t=Ye(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function Ys(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=_e,o=Vn(t);if(o==null&&(n=Ae,o=jn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+e);let i=Gs(s,8*n);return{network:Fr(o,i),mask:i}}function Gs(e,t){if(t!==8*_e&&t!==8*Ae)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var Ur=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=Ys(t));else{let n=Ye(t);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Ye(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Gs(o,8*n.length);this.network=Fr(n,this.mask)}}contains(t){return kc({network:this.network,mask:this.mask},t)}toString(){let t=Oc(this.mask),r=t!==-1?String(t):Pc(this.mask);return Zs(this.network)+"/"+r}};function Nc(e,t){return new Ur(e).contains(t)}function Fc(e){try{let t=je(e);return t.type==="ip6"?Nc("2000::/3",t.host):!1}catch{return!1}}function Ge(e){return!!Vn(e)}function Zn(e){return!!jn(e)}var zc=Au(Kc(),1),Dd=["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"],Rd=Dd.map(e=>new zc.Netmask(e));function ri(e){for(let t of Rd)if(t.contains(e))return!0;return!1}function Ld(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function Cd(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return ri(o)}function Od(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function Pd(e){let t=e.split(":"),r=t[t.length-1];return ri(r)}function kd(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function Gn(e){if(Ge(e))return ri(e);if(Ld(e))return Cd(e);if(Od(e))return Pd(e);if(Zn(e))return kd(e)}function qc(e){try{let t=je(e);switch(t.type){case"ip4":case"ip6":return Gn(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Gt=class extends Error{static name="ValidationError";name="ValidationError"},Wn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Xn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function oi(e){return t=>st(t,e)}function si(e){return t=>X(t,e)}function Je(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Be(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Hc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=X(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Be(n);return Kt([r,o],r.length+o.length)}function $c(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Qt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Be(n);return Kt([r,o],r.length+o.length)}function ii(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=st(t,"base32"),o=Je(r);return`${n}:${o}`}var ai=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ft("Invalid byte value in IP address");t[n]=o}),t},Vc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=Ge(r[n]),i;s&&(i=ai(r[n]),r[n]=st(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,st(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ft("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},jc=function(e){if(e.byteLength!==4)throw new ft("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Zc=function(e){if(e.byteLength!==16)throw new ft("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${r}"`)}};function Yc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${e}"`)}}var ni=Object.values(pr).map(e=>e.decoder),Nd=(function(){let e=ni[0].or(ni[1]);return ni.slice(2).forEach(t=>e=e.or(t)),e})();function Gc(e){return Nd.decode(e)}function Wc(e){return t=>e.encoder.encode(t)}function Fd(e){if(parseInt(e).toString()!==e)throw new Gt("Value must be an integer")}function Ud(e){if(e<0)throw new Gt("Value must be a positive integer, or zero")}function Md(e){return t=>{if(t>e)throw new Gt(`Value must be smaller than or equal to ${e}`)}}function Kd(...e){return t=>{for(let r of e)r(t)}}var Mr=Kd(Fd,Ud,Md(65535));var ut=-1,ci=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Xn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Wt=new ci,Ah=[{code:4,name:"ip4",size:32,valueToBytes:ai,bytesToValue:jc,validate:e=>{if(!Ge(e))throw new Gt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Be,bytesToValue:Je,validate:Mr},{code:273,name:"udp",size:16,valueToBytes:Be,bytesToValue:Je,validate:Mr},{code:33,name:"dccp",size:16,valueToBytes:Be,bytesToValue:Je,validate:Mr},{code:41,name:"ip6",size:128,valueToBytes:Vc,bytesToValue:Zc,stringToValue:Yc,validate:e=>{if(!Zn(e))throw new Gt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ut},{code:43,name:"ipcidr",size:8,bytesToValue:oi("base10"),valueToBytes:si("base10")},{code:53,name:"dns",size:ut},{code:54,name:"dns4",size:ut},{code:55,name:"dns6",size:ut},{code:56,name:"dnsaddr",size:ut},{code:132,name:"sctp",size:16,valueToBytes:Be,bytesToValue:Je,validate:Mr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ut,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ut,bytesToValue:oi("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?si("base58btc")(e):dt.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ii,valueToBytes:Hc},{code:445,name:"onion3",size:296,bytesToValue:ii,valueToBytes:$c},{code:446,name:"garlic64",size:ut},{code:447,name:"garlic32",size:ut},{code:448,name:"tls"},{code:449,name:"sni",size:ut},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ut,bytesToValue:Wc(Co),valueToBytes:Gc},{code:480,name:"http"},{code:481,name:"http-path",size:ut,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ut}];Ah.forEach(e=>{Wt.addProtocol(e)});function Xc(e){let t=[],r=0;for(;r<e.length;){let n=Br(e,r),o=Wt.getProtocol(n),s=St(n),i=Ih(o,e,r+s),a=0;i>0&&o.size===ut&&(a=St(i));let c=s+a+i,u={code:n,name:o.name,bytes:kt(e.subarray(r,r+c))};if(i>0){let f=r+s+a,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??st(l)}t.push(u),r+=c}return t}function Qc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Wt.getProtocol(n.code),s=St(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??X(n.value),a=i.byteLength,o.size===ut&&(c=St(a)));let u=new Uint8Array(s+c+a),f=0;$e(n.code,u,f),f+=s,i!=null&&(o.size===ut&&($e(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Kt(r,t)}function Jc(e){if(e.charAt(0)!=="/")throw new ft('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Wt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ft(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ft(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return t}function tu(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Wt.getProtocol(t.code);if(r==null)throw new ft(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Ih(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Br(t,r)}var Bh=Symbol.for("nodejs.util.inspect.custom"),li=Symbol.for("@multiformats/multiaddr");function Th(e){if(e==null&&(e="/"),eu(e))return e.getComponents();if(e instanceof Uint8Array)return Xc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Jc(e);if(Array.isArray(e))return e;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Qn=class e{[li]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Th(t),r.validate!==!1&&Dh(this)}get bytes(){return this.#r==null&&(this.#r=Qc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=tu(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Wn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return ht(this.bytes,t.bytes)}[Bh](){return`Multiaddr(${this.toString()})`}};function Dh(e){e.getComponents().forEach(t=>{let r=Wt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function eu(e){return!!e?.[li]}function ru(e){return new Qn(e)}function tr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Jn=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}},er=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Jn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new Jn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var di=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function to(e={}){return Rh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function Rh(e,t){t=t??{};let r=t.onEnd,n=new er,o,s,i,a=tr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,x)=>{s=v=>{s=null,n.push(v);try{y(e(n))}catch(m){x(m)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=tr()})}},u=y=>s!=null?s(y):(n.push(y),o),f=y=>(n=new er,s!=null?s({error:y}):(n.push({error:y}),o)),l=y=>{if(i)return o;if(t?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},d=y=>i?o:(i=!0,y!=null?f(y):u({done:!0})),p=()=>(n=new er,d(),{done:!0}),S=y=>(d(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:S,push:l,end:d,get readableLength(){return n.size},onEmpty:async y=>{let x=y?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let v,m;x!=null&&(v=new Promise((_,A)=>{m=()=>{A(new di)},x.addEventListener("abort",m)}));try{await Promise.race([a.promise,v])}finally{m!=null&&x!=null&&x?.removeEventListener("abort",m)}}},r==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(y){return b.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(y){return b.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return b.readableLength},onEmpty:y=>b.onEmpty(y)},o}var hi=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},nu=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function pi(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,f=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){d(nu(i)),e.then(l,d);return}if(i&&(c=()=>{d(nu(i))},i.addEventListener("abort",c,{once:!0})),e.then(l,d),r===Number.POSITIVE_INFINITY)return;let p=new hi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(S){d(S)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?d(o):(p.message=o??`Promise timed out after ${r} milliseconds`,d(p))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Lh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Ch(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=Lh(e),l=async(...p)=>{let S=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(S))return}catch(b){n(),i(b);return}c.push(S),r.count===c.length&&(n(),s(c))},d=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)f(p,l);for(let p of r.rejectionEvents)a.includes(p)||f(p,d)};for(let p of a)u(p,l);for(let p of r.rejectionEvents)a.includes(p)||u(p,d);r.signal&&r.signal.addEventListener("abort",()=>{d(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=pi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function rr(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Ch(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Kr(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var eo=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Te=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Oh(e){return e.reason}function zr(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??Oh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;return Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})]).finally(()=>{o!=null&&t.removeEventListener("abort",o)})}var ro=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=tr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Mt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Ph(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var ou=new WeakMap,no=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,r){this.id=Ph(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Mt),this.cleanup())}async join(t){let r=new ro(t);return this.recipients.push(r),t?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await zr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=ou.get(r);if(n==null&&(n=new WeakSet,ou.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.deferred.reject(t.signal?.reason??new Mt),t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var oo=class extends De{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=Kr(this.emitEmpty.bind(this),1),this.emitIdle=Kr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new eo;let n=new no(t,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Mt)}),this.clear()}async onEmpty(t){this.size!==0&&await rr(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await rr(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await rr(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=to({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Mt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function qr(e){let t=new globalThis.AbortController;function r(){let s=e.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let s of e){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}var kh=4194304,so=class extends Error{static name="UnwrappedError";name="UnwrappedError"},gi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},yi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},bi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Nh(e){return typeof e?.closeRead=="function"}function Fh(e){return typeof e?.close=="function"}function mi(e){return Nh(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Fh(e)?e.status!=="open":!1}function Uh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Mh(e,t){let r=t?.maxBufferSize??kh,n=new ct,o,s=!1,i;if(!Uh(e))throw new yt("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(d);let p=new Yr(`Read buffer overflow - ${d} > ${r}`);i=p,o?.reject(p),queueMicrotask(()=>{e.abort(p)});return}o?.resolve()}};e.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};e.addEventListener("close",c);let u=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new so("Stream was unwrapped");if(i!=null)throw i;if(mi(e)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new Te(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=d){o.resolve();break}if(await zr(o.promise,l?.signal),mi(e)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(mi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Te(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let S=n.sublist(0,p);return n.consume(p),S},async write(l,d){if(s===!0)throw new so("Stream was unwrapped");e.send(l)||await rr(e,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",a),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n),n.consume(n.byteLength))),e}};return f}function Kh(e,t={}){let r=Mh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=St(t.maxDataLength));let n=t?.lengthDecoder??Br,o=t?.lengthEncoder??rc;return{async read(i){let a=-1,c=new ct;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new gi("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new bi(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new yi(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new Te(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Te(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new ct(o(i.byteLength),i),a)},async writeV(i,a){let c=new ct(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function nr(e,t){let r=Kh(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.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:()=>r.unwrap()};return n}var io=class extends oo{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function su(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal},f;r?.timeout!=null&&(f=qr([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=f),s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Kr(i,r?.debounce??100),c=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var wi=class extends Map{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function iu(e){let{name:t,metrics:r}=e,n;return r!=null?n=new wi({name:t,metrics:r}):n=new Map,n}var xi="libp2p",Ei="autonat";var au="dial-request",cu="dial-back",uu=200n*1024n,fu=4096;var or;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s={...s},s.dialDataResponse!=null&&(s.dialDataRequest=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialDataRequest!=null&&(s.dialDataResponse=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialResponse!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialRequest=void 0),s.dialRequest!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialResponse=void 0),s.dialRequest!=null&&(i.uint32(10),Hr.codec().encode(s.dialRequest,i)),s.dialResponse!=null&&(i.uint32(18),$t.codec().encode(s.dialResponse,i)),s.dialDataRequest!=null&&(i.uint32(26),$r.codec().encode(s.dialDataRequest,i)),s.dialDataResponse!=null&&(i.uint32(34),Vr.codec().encode(s.dialDataResponse,i)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.dialRequest=Hr.codec().decode(s,s.uint32(),{limits:a.limits?.dialRequest});break}case 2:{c.dialResponse=$t.codec().decode(s,s.uint32(),{limits:a.limits?.dialResponse});break}case 3:{c.dialDataRequest=$r.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataRequest});break}case 4:{c.dialDataResponse=Vr.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}return c.dialDataResponse!=null&&(delete c.dialDataRequest,delete c.dialResponse,delete c.dialRequest),c.dialDataRequest!=null&&(delete c.dialDataResponse,delete c.dialResponse,delete c.dialRequest),c.dialResponse!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialRequest),c.dialRequest!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialResponse),c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield*Hr.codec().stream(s,s.uint32(),`${a}.dialRequest`,{limits:c.limits?.dialRequest});break}case 2:{yield*$t.codec().stream(s,s.uint32(),`${a}.dialResponse`,{limits:c.limits?.dialResponse});break}case 3:{yield*$r.codec().stream(s,s.uint32(),`${a}.dialDataRequest`,{limits:c.limits?.dialDataRequest});break}case 4:{yield*Vr.codec().stream(s,s.uint32(),`${a}.dialDataResponse`,{limits:c.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(or||(or={}));var Hr;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.addrs!=null&&s.addrs.length>0)for(let c of s.addrs)i.uint32(10),i.bytes(c);s.nonce!=null&&s.nonce!==0n&&(i.uint32(17),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrs:[],nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(a.limits?.addrs!=null&&c.addrs.length===a.limits.addrs)throw new Lr('Decode error - repeated field "addrs" had too many elements');c.addrs.push(s.bytes());break}case 2:{c.nonce=s.fixed64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={addrs:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(c.limits?.addrs!=null&&u.addrs===c.limits.addrs)throw new Lr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${a}.addrs[]`,index:u.addrs,value:s.bytes()},u.addrs++;break}case 2:{yield{field:`${a}.nonce`,value:s.fixed64()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(Hr||(Hr={}));var $r;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.addrIdx!=null&&s.addrIdx!==0&&(i.uint32(8),i.uint32(s.addrIdx)),s.numBytes!=null&&s.numBytes!==0n&&(i.uint32(16),i.uint64(s.numBytes)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrIdx:0,numBytes:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.addrIdx=s.uint32();break}case 2:{c.numBytes=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.addrIdx`,value:s.uint32()};break}case 2:{yield{field:`${a}.numBytes`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})($r||($r={}));var lt;(function(e){e.UNUSED="UNUSED",e.E_DIAL_ERROR="E_DIAL_ERROR",e.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",e.OK="OK"})(lt||(lt={}));var ao;(function(e){e[e.UNUSED=0]="UNUSED",e[e.E_DIAL_ERROR=100]="E_DIAL_ERROR",e[e.E_DIAL_BACK_ERROR=101]="E_DIAL_BACK_ERROR",e[e.OK=200]="OK"})(ao||(ao={}));(function(e){e.codec=()=>xe(ao)})(lt||(lt={}));var $t;(function(e){let t;(function(a){a.E_INTERNAL_ERROR="E_INTERNAL_ERROR",a.E_REQUEST_REJECTED="E_REQUEST_REJECTED",a.E_DIAL_REFUSED="E_DIAL_REFUSED",a.OK="OK"})(t=e.ResponseStatus||(e.ResponseStatus={}));let r;(function(a){a[a.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",a[a.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",a[a.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",a[a.OK=200]="OK"})(r||(r={})),(function(a){a.codec=()=>xe(r)})(t=e.ResponseStatus||(e.ResponseStatus={}));let n;e.codec=()=>(n==null&&(n=Ot((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&r[a.status]!==0&&(c.uint32(8),e.ResponseStatus.codec().encode(a.status,c)),a.addrIdx!=null&&a.addrIdx!==0&&(c.uint32(16),c.uint32(a.addrIdx)),a.dialStatus!=null&&ao[a.dialStatus]!==0&&(c.uint32(24),lt.codec().encode(a.dialStatus,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:lt.UNUSED},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{f.status=e.ResponseStatus.codec().decode(a);break}case 2:{f.addrIdx=a.uint32();break}case 3:{f.dialStatus=lt.codec().decode(a);break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{yield{field:`${u}.status`,value:e.ResponseStatus.codec().decode(a)};break}case 2:{yield{field:`${u}.addrIdx`,value:a.uint32()};break}case 3:{yield{field:`${u}.dialStatus`,value:lt.codec().decode(a)};break}default:{a.skipType(d&7);break}}}})),n);function o(a){return Lt(a,e.codec())}e.encode=o;function s(a,c){return Rt(a,e.codec(),c)}e.decode=s;function i(a,c){return Ct(a,e.codec(),c)}e.stream=i})($t||($t={}));var Vr;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.data!=null&&s.data.byteLength>0&&(i.uint32(10),i.bytes(s.data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={data:wt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.data=s.bytes():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.data`,value:s.bytes()}:s.skipType(f&7)}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(Vr||(Vr={}));var sr;(function(e){let t;e.codec=()=>(t==null&&(t=Ot((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.nonce!=null&&s.nonce!==0n&&(i.uint32(9),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.nonce=s.fixed64():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.nonce`,value:s.fixed64()}:s.skipType(f&7)}})),t);function r(s){return Lt(s,e.codec())}e.encode=r;function n(s,i){return Rt(s,e.codec(),i)}e.decode=n;function o(s,i){return Ct(s,e.codec(),i)}e.stream=o})(sr||(sr={}));var ue;(function(e){let t;(function(a){a.OK="OK"})(t=e.DialBackStatus||(e.DialBackStatus={}));let r;(function(a){a[a.OK=0]="OK"})(r||(r={})),(function(a){a.codec=()=>xe(r)})(t=e.DialBackStatus||(e.DialBackStatus={}));let n;e.codec=()=>(n==null&&(n=Ot((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&r[a.status]!==0&&(c.uint32(8),e.DialBackStatus.codec().encode(a.status,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.OK},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?f.status=e.DialBackStatus.codec().decode(a):a.skipType(d&7)}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?yield{field:`${u}.status`,value:e.DialBackStatus.codec().decode(a)}:a.skipType(d&7)}})),n);function o(a){return Lt(a,e.codec())}e.encode=o;function s(a,c){return Rt(a,e.codec(),c)}e.decode=s;function i(a,c){return Ct(a,e.codec(),c)}e.stream=i})(ue||(ue={}));function co(e,t){return Math.round(Math.random()*(t-e)+e)}var qh=4,Hh=8,uo=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;safeDispatchEvent;constructor(t,r){this.components=t,this.safeDispatchEvent=r.safeDispatchEvent,this.log=t.logger.forComponent("libp2p:auto-nat-v2:client"),this.started=!1,this.dialRequestProtocol=r.dialRequestProtocol,this.dialBackProtocol=r.dialBackProtocol,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.connectionThreshold=r.connectionThreshold??80,this.maxMessageSize=r.maxMessageSize??8192,this.dialResults=iu({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=su(this.findRandomPeers.bind(this),6e4),this.addressFilter=js(1024),this.queue=new io({concurrency:3,maxSize:50}),this.maxDialDataBytes=r.maxDialDataBytes??uu,this.dialDataChunkSize=r.dialDataChunkSize??fu,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[Wr]=["@libp2p/autonat"];get[Xr](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.components.registrar.register(this.dialRequestProtocol,{onConnect:(t,r)=>{this.verifyExternalAddresses(r).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),await this.components.registrar.handle(this.dialBackProtocol,(t,r)=>{this.handleDialBackStream(t,r).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),await this.components.registrar.unhandle(this.dialBackProtocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let r=qr([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:r})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:r})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleDialBackStream(t,r){let n=AbortSignal.timeout(this.timeout);let o=nr(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read(sr,{signal:n});if(!this.nonces.has(s.nonce))throw new It("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:ue.DialBackStatus.OK},ue),await t.close({signal:n})}catch(s){this.log.error("error handling incoming dial back stream - %e",s),t.abort(s)}}getUnverifiedMultiaddrs(t,r){let n=this.components.addressManager.getAddressesWithMetadata().sort((s,i)=>s.type==="observed"&&i.type!=="observed"?1:i.type==="observed"&&s.type!=="observed"?-1:0).filter(s=>{if(!(s.expires<Date.now()))return!1;let a=Nr(s.multiaddr);return!(a==null||a.type==="ip6"&&(!r||!Fc(s.multiaddr))||qc(s.multiaddr))}),o=[];for(let s of n){let i=s.multiaddr.toString(),a=this.dialResults.get(i);if(a!=null&&a.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",a.multiaddr,t);continue}if(a==null){let c=s.expires<Date.now();if(c&&this.addressFilter.remove?.(i),this.addressFilter.has(i))continue;this.addressFilter.add(i),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",i),a={multiaddr:s.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:qs(),type:s.type,lastVerified:s.lastVerified},this.dialResults.set(i,a)}o.push(a)}return o}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:a})=>Nr(a)?.type==="ip6"),o=Nr(t.remoteAddr);if(o?.type!=="ip4"&&o?.type!=="ip6")return;let s=this.getNetworkSegment(t.remoteAddr),i=this.getUnverifiedMultiaddrs(s,n);if(i.length!==0){if(!this.hasConnectionCapacity()){i[0]?.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",i[0].multiaddr),this.confirmAddress(i[0])):this.log("skipping verifying %a because we are too close to the connection limit",i[0]?.multiaddr);return}this.queue.add(async a=>{let c=qr([a.signal,AbortSignal.timeout(this.timeout)]),u=BigInt(co(0,Number.MAX_SAFE_INTEGER));this.nonces.add(u);try{await this.askPeerToVerify(t,s,u,a)}finally{c.clear(),this.nonces.delete(u)}},{peerId:t.remotePeer}).catch(a=>{this.log.error("error from %p verifying addresses - %e",t.remotePeer,a)})}}async askPeerToVerify(t,r,n,o){let s=[...this.dialResults.values()].filter(a=>a.result==null).map(a=>a.multiaddr);if(s.length===0){this.queue.clear();return}this.log.trace("asking %a to verify multiaddrs %s",t.remoteAddr,s);let i=await t.newStream(this.dialRequestProtocol,o);try{let a=nr(i).pb(or);await a.write({dialRequest:{addrs:s.map(c=>c.bytes),nonce:n}},o);for(let c=0;c<s.length;c++){let u=await a.read(o);if(u.dialDataRequest!=null){if(u.dialDataRequest.numBytes>this.maxDialDataBytes){this.log("too many dial data byte requested by %p - %s/%s",t.remotePeer,u.dialDataRequest.numBytes,this.maxDialDataBytes);continue}this.log("sending %d bytes to %p as anti-amplification attack protection",u.dialDataRequest.numBytes,t.remotePeer);let p=new Uint8Array(this.dialDataChunkSize),S=BigInt(this.dialDataChunkSize);for(let b=0n;b<u.dialDataRequest.numBytes;b+=S)await a.write({dialDataResponse:{data:p}},o);u=await a.read(o)}if(u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}if(u.dialResponse.status!==$t.ResponseStatus.OK)return;let l=s[u.dialResponse.addrIdx];if(l==null){this.log.trace("peer dialed unknown address");continue}let d=this.dialResults.get(l.toString());if(d==null){this.log.trace("peer reported %a as %s but there is no result object",l,u.dialResponse.status);continue}if(d.networkSegments.includes(r)){this.log.trace("%a results already included network segment %s",l,r);continue}if(d.result!=null){this.log.trace("already resolved result for %a, ignoring response from",l,t.remotePeer);continue}if(d.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,l);continue}if(d.verifyingPeers.add(t.remotePeer),d.networkSegments.push(r),u.dialResponse.dialStatus===lt.OK){if(this.log.trace("%p dialed %a successfully",t.remotePeer,d.multiaddr),this.emitReachabilityEvent(d,"verifying"),d.success++,d.type!=="observed"){this.confirmAddress(d);continue}}else if(u.dialResponse.dialStatus===lt.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,d.multiaddr),this.emitReachabilityEvent(d,"verifying"),d.failure++;else if(u.dialResponse.dialStatus===lt.E_DIAL_BACK_ERROR){this.log.trace("%p saw error while dialing %a",t.remotePeer,d.multiaddr);continue}this.log("%a success %d failure %d",d.multiaddr,d.success,d.failure),d.success===qh&&this.confirmAddress(d),d.failure===Hh&&this.unconfirmAddress(d)}}finally{try{await i.close(o)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let r=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return r/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,this.emitReachabilityEvent(t,"reachable")}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,this.emitReachabilityEvent(t,"unreachable")}emitReachabilityEvent(t,r){this.safeDispatchEvent(`address:${r}`,{detail:{addr:t.multiaddr,type:t.type,success:t.success,failure:t.failure}})}getNetworkSegment(t){let r=je(t);switch(r.type){case"ip4":return r.host.split(".")[0].padStart(3,"0");case"ip6":return r.host.split(":")[0].padStart(4,"0");default:throw new yt(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};var fo=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:server"),this.started=!1,this.dialRequestProtocol=r.dialRequestProtocol,this.dialBackProtocol=r.dialBackProtocol,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.maxMessageSize=r.maxMessageSize??8192,this.handleDialRequestStream=this.handleDialRequestStream.bind(this)}async start(){this.started||(await this.components.registrar.handle(this.dialRequestProtocol,this.handleDialRequestStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),this.started=!1}async handleDialRequestStream(t,r){let n=AbortSignal.timeout(this.timeout);let o=nr(t,{maxDataLength:this.maxMessageSize}).pb(or),s=mu(r.remoteAddr);if(s==null)throw new It(`Could not find IP address in connection address "${r.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new It("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new It("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=ru(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:$t.ResponseStatus.E_DIAL_REFUSED,dialStatus:lt.UNUSED}},{signal:n});continue}let f=mu(c);if(f==null)throw new It(`Could not find IP address in requested address "${c}"`);if(Gn(f))throw new It(`Requested address had private IP "${c}"`);f!==s&&await this.preventAmplificationAttack(o,a,{signal:n});let l=await this.dialClientBack(c,i.nonce,{signal:n});await o.write({dialResponse:{addrIdx:a,status:$t.ResponseStatus.OK,dialStatus:l}},{signal:n})}catch(c){this.log.error("error handling incoming dialback request - %e",c)}await t.close({signal:n})}async preventAmplificationAttack(t,r,n){let o=co(3e4,1e5);await t.write({dialDataRequest:{addrIdx:r,numBytes:BigInt(o)}},n);let s=0;for(;s<o;){let{dialDataResponse:i}=await t.read(n);if(i==null)throw new It("Did not receive DialDataResponse message on incoming dial request stream");s+=i.data.byteLength}}async dialClientBack(t,r,n){let o;try{o=await this.components.connectionManager.openConnection(t,{force:!0,...n})}catch(s){return this.log.error("failed to open connection to %a - %e",t,s),lt.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=nr(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:r},sr,n),(await i.read(ue,n)).status!==ue.DialBackStatus.OK)throw new It("DialBackResponse status was not OK");await o.close(n)}catch(s){return this.log.error("could not perform dial back - %e",s),o.abort(s),lt.E_DIAL_BACK_ERROR}return lt.OK}};function mu(e){return e.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var lo=class extends De{client;server;constructor(t,r){super();let n=`/${r.protocolPrefix??xi}/${Ei}/${"2"}/${au}`,o=`/${r.protocolPrefix??xi}/${Ei}/${"2"}/${cu}`;this.client=new uo(t,{...r,dialRequestProtocol:n,dialBackProtocol:o,safeDispatchEvent:this.safeDispatchEvent.bind(this)}),this.server=new fo(t,{...r,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[Wr]=["@libp2p/autonat"];get[Xr](){return["@libp2p/identify"]}async start(){await Ai(this.client,this.server)}async stop(){await Ii(this.client,this.server)}};function $h(e={}){return t=>new lo(t,e)}return Iu(Vh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: