@libp2p/autonat 3.0.32-0d3ca9f0c → 3.0.32-42064ed68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PAutonat=(()=>{var Gc=Object.create;var kr=Object.defineProperty;var Wc=Object.getOwnPropertyDescriptor;var Xc=Object.getOwnPropertyNames;var Qc=Object.getPrototypeOf,Jc=Object.prototype.hasOwnProperty;var Qn=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},St=(e,t)=>{for(var r in t)kr(e,r,{get:t[r],enumerable:!0})},ii=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xc(t))!Jc.call(e,o)&&o!==r&&kr(e,o,{get:()=>t[o],enumerable:!(n=Wc(t,o))||n.enumerable});return e};var tu=(e,t,r)=>(r=e!=null?Gc(Qc(e)):{},ii(t||!e||!e.__esModule?kr(r,"default",{value:e,enumerable:!0}):r,e)),eu=e=>ii(kr({},"__esModule",{value:!0}),e);var Ns=Qn(Ye=>{"use strict";Object.defineProperty(Ye,"__esModule",{value:!0});Ye.Netmask4Impl=void 0;Ye.ip2long=Ze;Ye.long2ip=Mt;function Mt(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 Jl=48,td=97,ed=65;function rd(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)-Jl)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-td)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-ed)>>>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 Ze(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]=rd(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 ks=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=Ze(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=(Ze(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=Mt(this.netLong),this.mask=Mt(this.maskLong),this.hostmask=Mt(~this.maskLong),this.first=this.bitmask<=30?Mt(this.netLong+1):this.base,this.last=this.bitmask<=30?Mt(this.netLong+this.size-2):Mt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Mt(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):(Ze(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new e(Mt(this.netLong+this.size*t),this.mask)}forEach(t){let r=Ze(this.first),n=Ze(this.last),o=0;for(;r<=n;)t(Mt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Ye.Netmask4Impl=ks});var xc=Qn(Ge=>{"use strict";Object.defineProperty(Ge,"__esModule",{value:!0});Ge.Netmask6Impl=void 0;Ge.ip6bigint=Us;Ge.bigint2ip6=_e;var nd=Ns(),Fs=(1n<<128n)-1n;function Us(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,nd.ip2long)(n),s=e.substring(0,r+1)+"0:0";return wc(s)&~0xffffffffn|BigInt(o)}return wc(e)}function wc(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 _e(e){if(e<0n||e>Fs)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 Ms=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=Fs>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Us(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=_e(this.netBigint),this.mask=_e(this.maskBigint),this.hostmask=_e(~this.maskBigint&Fs),this.first=this.base,this.last=_e(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):(Us(t)&this.maskBigint)===this.netBigint}next(t=1){let r=1n<<BigInt(128-this.bitmask);return new e(_e(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(_e(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};Ge.Netmask6Impl=Ms});var Ec=Qn(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.long2ip=ce.ip2long=ce.Netmask=void 0;var Nn=Ns();Object.defineProperty(ce,"ip2long",{enumerable:!0,get:function(){return Nn.ip2long}});Object.defineProperty(ce,"long2ip",{enumerable:!0,get:function(){return Nn.long2ip}});var od=xc(),zs=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 od.Netmask6Impl(t,r):this._impl=new Nn.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 Nn.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=zs});var Oh={};St(Oh,{autoNAT:()=>Ch});var kt=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"}},er=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Nr=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Fr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var rr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Jn=Symbol.for("@libp2p/peer-id");function ru(e){return typeof e?.handleEvent=="function"}function nu(e){return e===!0||e===!1}function ou(e){return nu(e)?e:e?.capture??!1}function to(e){let t={capture:ou(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function ai(e,t){return to(e).capture===to(t).capture}var Ur=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=to(n);if(o?.signal?.aborted===!0)return;let s=u=>{o.once&&this.removeEventListener(t,r,o),ru(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:ai(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&&ai(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 ci=Symbol.for("@libp2p/service-capabilities"),ui=Symbol.for("@libp2p/service-dependencies");function lt(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}var so={};St(so,{base58btc:()=>st,base58flickr:()=>du});var up=new Uint8Array(0);function li(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 At(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ue(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ue(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function di(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var fi=4096;function hi(e){let t=e.length;if(t<=fi)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=fi));return r}function su(e){return e?.buffer instanceof ArrayBuffer}function ue(e){return su(e)?e:e.slice()}function iu(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 l=e.length,d=e.charAt(0),f=Math.log(l)/Math.log(256),p=Math.log(256)/Math.log(l);function v(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var y=0,g=0,b=0,S=h.length;b!==S&&h[b]===0;)b++,y++;for(var I=(S-b)*p+1>>>0,k=new Uint8Array(I);b!==S;){for(var N=h[b],C=0,R=I-1;(N!==0||C<g)&&R!==-1;R--,C++)N+=256*k[R]>>>0,k[R]=N%l>>>0,N=N/l>>>0;if(N!==0)throw new Error("Non-zero carry");g=C,b++}for(var K=I-g;K!==I&&k[K]===0;)K++;for(var z=d.repeat(y);K<I;++K)z+=e.charAt(k[K]);return z}function E(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var y=0;if(h[y]!==" "){for(var g=0,b=0;h[y]===d;)g++,y++;for(var S=(h.length-y)*f+1>>>0,I=new Uint8Array(S);h[y];){var k=n[h.charCodeAt(y)];if(k===255)return;for(var N=0,C=S-1;(k!==0||N<b)&&C!==-1;C--,N++)k+=l*I[C]>>>0,I[C]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");b=N,y++}if(h[y]!==" "){for(var R=S-b;R!==S&&I[R]===0;)R++;for(var K=new Uint8Array(g+(S-R)),z=g;R!==S;)K[z++]=I[R++];return K}}}function w(h){var y=E(h);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:v,decodeUnsafe:E,decode:w}}var au=iu,cu=au,mi=cu;var eo=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")}},ro=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 gi(this,t)}},no=class{decoders;constructor(t){this.decoders=t}or(t){return gi(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 gi(e,t){return new no({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var oo=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 eo(t,r,n),this.decoder=new ro(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Be({name:e,prefix:t,encode:r,decode:n}){return new oo(e,t,r,n)}function Wt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=mi(r,e,n);return Be({prefix:t,name:e,encode:o,decode:i=>At(s(i))})}function uu(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 l=t[e[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,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 fu(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 lu(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 rt({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=lu(n,o);return Be({prefix:t,name:e,encode(i){return fu(i,n,r)},decode(i){return uu(i,s,r,e)}})}var st=Wt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),du=Wt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var io={};St(io,{base32:()=>Xt,base32hex:()=>gu,base32hexpad:()=>bu,base32hexpadupper:()=>wu,base32hexupper:()=>yu,base32pad:()=>pu,base32padupper:()=>mu,base32upper:()=>hu,base32z:()=>xu});var Xt=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),hu=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),pu=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),mu=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),gu=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),yu=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),bu=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),wu=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),xu=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ao={};St(ao,{base36:()=>nr,base36upper:()=>Eu});var nr=Wt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Eu=Wt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Su=wi,yi=128,vu=127,_u=~vu,Au=Math.pow(2,31);function wi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Au;)t[r++]=e&255|yi,e/=128;for(;e&_u;)t[r++]=e&255|yi,e>>>=7;return t[r]=e|0,wi.bytes=r-n+1,t}var Iu=co,Bu=128,bi=127;function co(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw co.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&bi)<<o:(i&bi)*Math.pow(2,o),o+=7}while(i>=Bu);return co.bytes=s-n,r}var Tu=Math.pow(2,7),Lu=Math.pow(2,14),Du=Math.pow(2,21),Cu=Math.pow(2,28),Ou=Math.pow(2,35),Ru=Math.pow(2,42),Pu=Math.pow(2,49),ku=Math.pow(2,56),Nu=Math.pow(2,63),Fu=function(e){return e<Tu?1:e<Lu?2:e<Du?3:e<Cu?4:e<Ou?5:e<Ru?6:e<Pu?7:e<ku?8:e<Nu?9:10},Uu={encode:Su,decode:Iu,encodingLength:Fu},Mu=Uu,or=Mu;function sr(e,t=0){let r=or.decode(e,t),n=or.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 Te(e,t,r=0){return or.encode(e,t,r),t}function Le(e){return or.encodingLength(e)}function Ce(e,t){let r=t.byteLength,n=Le(e),o=n+Le(r),s=new Uint8Array(o+r);return Te(e,s,0),Te(r,s,n),s.set(t,o),new De(e,r,t,s)}function fe(e){let t=At(e),[r,n]=sr(t),[o,s]=sr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new De(r,o,i,t)}function xi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&li(e.bytes,r.bytes)}}var De=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=ue(n),this.bytes=ue(o)}};function Ei(e,t){let{bytes:r,version:n}=e;return n===0?Ku(r,uo(e),t??st.encoder):qu(r,uo(e),t??Xt.encoder)}var Si=new WeakMap;function uo(e){let t=Si.get(e);if(t==null){let r=new Map;return Si.set(e,r),r}return t}var ht=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=ue(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!==ir)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Hu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ce(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&&xi(t.multihash,n.multihash)}toString(t){return Ei(this,t)}toJSON(){return{"/":Ei(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??vi(n,o,s.bytes))}else if(r[Vu]===!0){let{version:n,multihash:o,code:s}=r,i=fe(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!==ir)throw new Error(`Version 0 CID must use dag-pb (code: ${ir}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=vi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ir,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=At(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 De(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[d,f]=sr(t.subarray(r));return r+=f,d},o=n(),s=ir;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,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,r){let[n,o]=zu(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 uo(s).set(n,t),s}};function zu(e,t){switch(e[0]){case"Q":{let r=t??st;return[st.prefix,r.decode(`${st.prefix}${e}`)]}case st.prefix:{let r=t??st;return[st.prefix,r.decode(e)]}case Xt.prefix:{let r=t??Xt;return[Xt.prefix,r.decode(e)]}case nr.prefix:{let r=t??nr;return[nr.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 Ku(e,t,r){let{prefix:n}=r;if(n!==st.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 qu(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 ir=112,Hu=18;function vi(e,t,r){let n=Le(e),o=n+Le(t),s=new Uint8Array(o+r.byteLength);return Te(e,s,0),Te(t,s,n),s.set(r,o),s}var Vu=Symbol.for("@ipld/js-cid/CID");var fo={};St(fo,{identity:()=>Lt});var _i=0,$u="identity",Ai=At;function ju(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 Ce(_i,Ai(e))}var Lt={code:_i,name:$u,encode:Ai,digest:ju};function Zu(e){return e.buffer instanceof ArrayBuffer}function Dt(e){return Zu(e)?e:e.slice()}async function Ii(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,Dt(t),Dt(r.subarray()));return n?.signal?.throwIfAborted(),s}function It(e=0){return new Uint8Array(e)}function pt(e=0){return new Uint8Array(e)}function Yu(e){return e?.buffer instanceof ArrayBuffer}function lo(e){if(Yu(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Nt(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 lo(r)}var Ti=Symbol.for("@achingbrain/uint8arraylist");function Bi(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 zr(e){return!!e?.[Ti]}var ut=class e{bufs;length;[Ti]=!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(zr(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(zr(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=Bi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Bi(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(zr(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 Nt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Nt(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,l=r>a&&r<=c;if(u&&l){if(t===a&&r===c){n.push(i);break}let d=t-a;n.push(i.subarray(d,d+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){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(!zr(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 d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=r;d<=c;d+=l){l=0;for(let f=u;f>=0;f--){let p=this.get(d+f);if(n[f]!==p){l=Math.max(1,f-a[p]);break}}if(l===0)return d}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=It(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=It(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=It(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=It(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=It(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!lt(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 ho={};St(ho,{base10:()=>Gu});var Gu=Wt({prefix:"9",name:"base10",alphabet:"0123456789"});var po={};St(po,{base16:()=>Wu,base16upper:()=>Xu});var Wu=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Xu=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var mo={};St(mo,{base2:()=>Qu});var Qu=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var go={};St(go,{base256emoji:()=>nf});var Li=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}"),Ju=Li.reduce((e,t,r)=>(e[r]=t,e),[]),tf=Li.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function ef(e){return e.reduce((t,r)=>(t+=Ju[r],t),"")}function rf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=tf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var nf=Be({prefix:"\u{1F680}",name:"base256emoji",encode:ef,decode:rf});var bo={};St(bo,{base64:()=>of,base64pad:()=>sf,base64url:()=>yo,base64urlpad:()=>af});var of=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sf=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yo=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),af=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wo={};St(wo,{base8:()=>cf});var cf=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xo={};St(xo,{identity:()=>uf});var uf=Be({prefix:"\0",name:"identity",encode:e=>hi(At(e)),decode:e=>At(di(e))});var Zp=new TextEncoder,Yp=new TextDecoder;var vo={};St(vo,{sha256:()=>ar,sha512:()=>hf});var df=20;function So({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Eo(e,t,r,n,o)}var Eo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??df,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?Di(n,this.code,r?.truncate):n.then(o=>Di(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Di(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 Ce(t,e)}function Oi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ar=So({name:"sha2-256",code:18,encode:Oi("SHA-256")}),hf=So({name:"sha2-512",code:19,encode:Oi("SHA-512")});var cr={...xo,...mo,...wo,...ho,...po,...io,...ao,...so,...bo,...go},i0={...vo,...fo};function Pi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ri=Pi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),_o=Pi("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}),pf={utf8:Ri,"utf-8":Ri,hex:cr.base16,latin1:_o,ascii:_o,binary:_o,...cr},Kr=pf;function Q(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function it(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var mf=parseInt("11111",2),Ao=parseInt("10000000",2),gf=parseInt("01111111",2),ki={0:ur,1:ur,2:yf,3:xf,4:Ef,5:wf,6:bf,16:ur,22:ur,48:ur};function Io(e,t={offset:0}){let r=e[t.offset]&mf;if(t.offset++,ki[r]!=null)return ki[r](e,t);throw new Error("No decoder for tag "+r)}function fr(e,t){let r=0;if((e[t.offset]&Ao)===Ao){let n=e[t.offset]&gf,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 ur(e,t){fr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Io(e,t);if(n===null)break;r.push(n)}return r}function yf(e,t){let r=fr(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 bf(e,t){let r=fr(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 l=0;for(let d=0;d<c.length;d++)l+=c[d]<<d*7;a+=`.${l}`,c=[]}}return a}function wf(e,t){return t.offset++,null}function xf(e,t){let r=fr(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 Ef(e,t){let r=fr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Sf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ut;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Bo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Sf(e.byteLength);return new ut(Uint8Array.from([t.byteLength|Ao]),t)}function Ni(e){let t=new ut,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ut(Uint8Array.from([2]),Bo(t),t)}function Fi(e){let t=Uint8Array.from([0]),r=new ut(t,e);return new ut(Uint8Array.from([3]),Bo(r),r)}function qr(e,t=48){let r=new ut;for(let n of e)r.append(n);return new ut(Uint8Array.from([t]),Bo(r),r)}var vf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),_f=Uint8Array.from([6,5,43,129,4,0,34]),Af=Uint8Array.from([6,5,43,129,4,0,35]),If={ext:!0,kty:"EC",crv:"P-256"},Bf={ext:!0,kty:"EC",crv:"P-384"},Tf={ext:!0,kty:"EC",crv:"P-521"},To=32,Lo=48,Do=66;function Ui(e){let t=Io(e);return Mi(t)}function Mi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===To*2+1)return n=it(t.subarray(r,r+To),"base64url"),o=it(t.subarray(r+To),"base64url"),new Oe({...If,key_ops:["verify"],x:n,y:o});if(t.byteLength===Lo*2+1)return n=it(t.subarray(r,r+Lo),"base64url"),o=it(t.subarray(r+Lo),"base64url"),new Oe({...Bf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Do*2+1)return n=it(t.subarray(r,r+Do),"base64url"),o=it(t.subarray(r+Do),"base64url"),new Oe({...Tf,key_ops:["verify"],x:n,y:o});throw new yt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function zi(e){return qr([Ni(Uint8Array.from([1])),qr([Lf(e.crv)],160),qr([Fi(new ut(Uint8Array.from([4]),Q(e.x??"","base64url"),Q(e.y??"","base64url")))],161)]).subarray()}function Lf(e){if(e==="P-256")return vf;if(e==="P-384")return _f;if(e==="P-521")return Af;throw new yt(`Invalid curve ${e}`)}var Oe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=zi(this.jwk)),this._raw}toMultihash(){return Lt.digest(Re(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,r,n){return Ii(this.jwk,r,t,n)}};var Hr=BigInt(4294967295),Ki=BigInt(32);function Df(e,t=!1){return t?{h:Number(e&Hr),l:Number(e>>Ki&Hr)}:{h:Number(e>>Ki&Hr)|0,l:Number(e&Hr)|0}}function qi(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}=Df(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Cf=e=>e/2**32|0,Of=e=>e>>>0;function Hi(e,t,r,n){let o=Cf(r),s=Of(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var Co=(e,t,r)=>e>>>r,Oo=(e,t,r)=>e<<32-r|t>>>r,le=(e,t,r)=>e>>>r|t<<32-r,de=(e,t,r)=>e<<32-r|t>>>r,lr=(e,t,r)=>e<<64-r|t>>>r-32,dr=(e,t,r)=>e>>>r-32|t<<64-r;function Ft(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Vi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),$i=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ji=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Zi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Yi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Gi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function Vr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Ro=e=>e?`"${e}" `:"";function zt(e,t=""){if(typeof e!="number")throw new TypeError(Ro(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Ro(t)+"expected integer >= 0, got "+e);return e}function Bt(e,t,r=""){if(Vr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&zt(t,"length");let n=Vr(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=Ro(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function $r(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(zt(e.outputLen),zt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Pf=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},Wi=(e,t)=>{Pf(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 Pe(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function jr(e,t){Bt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function he(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Zr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ct(e,t){return e<<32-t|e>>>t}var Qi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",kf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Yr(e){if(Bt(e),Qi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=kf[e[r]];return t}function Xi(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Gr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Qi)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=Xi(e.charCodeAt(s)),a=Xi(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 Po(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Bt(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 Nf(e,t,r="opts"){return Wi(e,"defaults"),t!==void 0&&Wi(t,r),Object.assign(Object.create(null),e,t)}function ko(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Nf({},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 Ji(e=32){zt(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 No=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ta(e,t,r){return e&t^~e&r}function ea(e,t,r){return e&t^e&r^t&r}var hr=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=Zr(this.buffer)}update(t){Pe(this),Bt(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=Zr(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){Pe(this),jr(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)),Hi(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:Zr(t),c=this.outputLen,u=c/4,l=this.get();if(c%4||u>l.length)throw new Error("invalid outputLen");for(let d=0;d<u;d++)a.setUint32(4*d,l[d],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()}},ra=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var na=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ff=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),Fo=class extends hr{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 d=0;d<16;d++,r+=4)Jt[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let f=Jt[d-15],p=Jt[d-2],v=Ct(f,7)^Ct(f,18)^f>>>3,E=Ct(p,17)^Ct(p,19)^p>>>10;Jt[d]=E+Jt[d-7]+v+Jt[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let d=0;d<64;d++){let f=Ct(a,6)^Ct(a,11)^Ct(a,25),p=l+f+ta(a,c,u)+Ff[d]+Jt[d]|0,E=(Ct(n,2)^Ct(n,13)^Ct(n,22))+ea(n,o,s)|0;l=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){he(Jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),he(this.buffer)}},Uo=class extends Fo{constructor(){super(32,ra)}};var oa=qi(["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))),Uf=oa[0],Mf=oa[1],te=new Uint32Array(80),ee=new Uint32Array(80),Mo=class extends hr{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:l,Fh:d,Fl:f,Gh:p,Gl:v,Hh:E,Hl:w}=this;return[t,r,n,o,s,i,a,c,u,l,d,f,p,v,E,w]}set(t,r,n,o,s,i,a,c,u,l,d,f,p,v,E,w){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=l|0,this.Fh=d|0,this.Fl=f|0,this.Gh=p|0,this.Gl=v|0,this.Hh=E|0,this.Hl=w|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let g=0;g<16;g++,r+=4)te[g]=t.getUint32(r),ee[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let b=te[g-15]|0,S=ee[g-15]|0,I=le(b,S,1)^le(b,S,8)^Co(b,S,7),k=de(b,S,1)^de(b,S,8)^Oo(b,S,7),N=te[g-2]|0,C=ee[g-2]|0,R=le(N,C,19)^lr(N,C,61)^Co(N,C,6),K=de(N,C,19)^dr(N,C,61)^Oo(N,C,6),z=ji(k,K,ee[g-7],ee[g-16]),Z=Zi(z,I,R,te[g-7],te[g-16]);te[g]=Z|0,ee[g]=z|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:d,El:f,Fh:p,Fl:v,Gh:E,Gl:w,Hh:h,Hl:y}=this;for(let g=0;g<80;g++){let b=le(d,f,14)^le(d,f,18)^lr(d,f,41),S=de(d,f,14)^de(d,f,18)^dr(d,f,41),I=d&p^~d&E,k=f&v^~f&w,N=Yi(y,S,k,Mf[g],ee[g]),C=Gi(N,h,b,I,Uf[g],te[g]),R=N|0,K=le(n,o,28)^lr(n,o,34)^lr(n,o,39),z=de(n,o,28)^dr(n,o,34)^dr(n,o,39),Z=n&s^n&a^s&a,T=o&i^o&c^i&c;h=E|0,y=w|0,E=p|0,w=v|0,p=d|0,v=f|0,{h:d,l:f}=Ft(u|0,l|0,C|0,R|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let U=Vi(R,z,T);n=$i(U,C,K,Z),o=U|0}({h:n,l:o}=Ft(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ft(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ft(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Ft(this.Dh|0,this.Dl|0,u|0,l|0),{h:d,l:f}=Ft(this.Eh|0,this.El|0,d|0,f|0),{h:p,l:v}=Ft(this.Fh|0,this.Fl|0,p|0,v|0),{h:E,l:w}=Ft(this.Gh|0,this.Gl|0,E|0,w|0),{h,l:y}=Ft(this.Hh|0,this.Hl|0,h|0,y|0),this.set(n,o,s,i,a,c,u,l,d,f,p,v,E,w,h,y)}roundClean(){he(te,ee)}destroy(){this.destroyed=!0,he(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},zo=class extends Mo{constructor(){super(64,na)}};var sa=ko(()=>new Uo,No(1));var Ko=ko(()=>new zo,No(3));function Xr(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 V=(e,t,r)=>Bt(e,t,r),qo=zt;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 pe(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var pr=Yr,Tt=(...e)=>Po(...e),ke=e=>Gr(e),oe=Vr,me=e=>Ji(e),Wr=BigInt(0),ia=BigInt(1),zf=e=>e?`"${e}" `:"";function wt(e,t=""){if(typeof e!="boolean")throw new TypeError(zf(t)+"expected boolean, got type="+typeof e);return e}function Qr(e){if(typeof e=="bigint"){if(!ne(e))throw new RangeError("positive bigint expected, got "+e)}else qo(e);return e}function Kt(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 mr(e){let t=Qr(e).toString(16);return t.length&1?"0"+t:t}function ca(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Wr:BigInt("0x"+e)}function Ut(e){return ca(Yr(e))}function ge(e){return ca(Yr(gr(Bt(e)).reverse()))}function Jr(e,t){if(zt(t),t===0)throw new Error("zero output length is invalid");e=Qr(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Gr(n.padStart(r,"0"))}function Ho(e,t){return Jr(e,t).reverse()}function gr(e){return Uint8Array.from(V(e))}function ne(e){return typeof e=="bigint"&&Wr<=e}function Vo(e,t,r){return ne(e)&&ne(t)&&ne(r)&&t<=e&&e<r}function Ne(e,t,r,n){if(!Vo(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Fe(e){if(e<Wr)throw new Error("expected non-negative bigint, got "+e);return e===Wr?0:e.toString(2).length}var yr=e=>(Kt(e,"n"),(ia<<BigInt(e))-ia);function ua(e,t,r){if(zt(e,"hashLen"),zt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),l=0,d=()=>{c.fill(1),u.fill(0),l=0},f=(...w)=>r(u,Tt(c,...w)),p=(w=o)=>{u=f(s,w),c=f(),w.length!==0&&(u=f(i,w),c=f())},v=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,h=[];for(;w<t;){c=f();let y=c.slice();h.push(y),w+=c.length}return Tt(...h)};return(w,h)=>{d(),p(w);let y;for(;(y=h(v()))===void 0;)p();return d(),y}}function xt(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)}"`,l=e[i];if(!Object.hasOwn(e,i)&&(c?l!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&l===void 0)return;let d=typeof l;if(d!==a||l===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${d}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var at=BigInt(0),$=BigInt(1),se=BigInt(2),da=BigInt(3),$o=BigInt(4),ha=BigInt(5),Kf=BigInt(7),pa=BigInt(8),qf=BigInt(9),Hf=BigInt(15),ma=BigInt(16),Vf=BigInt("0x10000000000000000");function et(e,t){if(t<=at)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=at?r:t+r}function ga(e,t,r){if(r<=$)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<at)throw new Error("invalid exponent, negatives unsupported");if(t===at)return $;if(t===$)return e;let n=e%r;if(n<at&&(n+=r),t<Vf){let a=$;for(;t>at;)t&$&&(a=a*n%r),n=n*n%r,t>>=$;return a}let o=[];for(;t>at;)o.push(Number(t&Hf)),t>>=$o;let s=new Array(16);s[0]=$,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 J(e,t,r){if(r<=$)throw new Error("pow2: expected modulus > 1, got "+r);if(t<at)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >at;)n*=n,n%=r;return n}function fa(e,t){if(e===at)throw new Error("invert: expected non-zero number");if(t<=$)throw new Error("invert: expected modulus > 1, got "+t);let r=et(e,t),n=t,o=at,s=$;for(;r!==at;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==$)throw new Error("invert: does not exist");return et(o,t)}function ya(e,t){if(t<=$)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=et(e,t);if(r===at)throw new Error("invertCt: expected non-zero number");let n=ga(r,t-se,t);if(et(r*n,t)!==$)throw new Error("invertCt: does not exist");return n}function jo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function Zo(e,t){if((e&$)===at)throw new Error(t+": expected odd modulus, got "+e)}function ba(e,t){let r=e,n=(r.ORDER+$)/$o,o=r.pow(t,n);return jo(r,o,t),o}function $f(e,t){let r=e,n=(r.ORDER-ha)/pa,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 jo(r,c,t),c}function jf(e){let t=Me(e),r=wa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Kf)/ma;return((a,c)=>{let u=a,l=u.pow(c,i),d=u.mul(l,n),f=u.mul(l,o),p=u.mul(l,s),v=u.eql(u.sqr(d),c),E=u.eql(u.sqr(f),c);l=u.cmov(l,d,v),d=u.cmov(p,f,E);let w=u.eql(u.sqr(d),c),h=u.cmov(l,d,w);return jo(u,h,c),h})}function wa(e){if(e<da)throw new Error("sqrt is not defined for small field");Zo(e,"tonelliShanks");let t=e-$,r=0;for(;t%se===at;)t/=se,r++;let n=se,o=Me(e);for(;br(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ba;let s=o.pow(n,t),i=(t+$)/se;return function(c,u){let l=c;if(l.is0(u))return u;if(br(l,u)!==1)throw new Error("Cannot find square root");let d=r,f=l.mul(l.ONE,s),p=l.pow(u,t),v=l.pow(u,i);for(;!l.eql(p,l.ONE);){if(l.is0(p))throw new Error("Cannot find square root: probably non-prime P");let E=1,w=l.sqr(p);for(;!l.eql(w,l.ONE);)if(E++,w=l.sqr(w),E===d)throw new Error("Cannot find square root");let h=$<<BigInt(d-E-1),y=l.pow(f,h);d=E,f=l.sqr(y),p=l.mul(p,f),v=l.mul(v,y)}return v}}function Zf(e){return Zo(e,"Fp.sqrt"),e%$o===da?ba:e%pa===ha?$f:e%ma===qf?jf(e):wa(e)}var xa=(e,t)=>(et(e,t)&$)===$,Yf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ue(e){if(re(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);Kt(e.BYTES,"BYTES"),Kt(e.BITS,"BITS");for(let t of Yf)pe(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=$)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function en(e,t,r=!1){Ue(e),Xr(t,"nums"),wt(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 br(e,t){Ue(e);let r=e;Zo(r.ORDER,"FpLegendre");let n=(r.ORDER-$)/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 Gf(e,t){if(t!==void 0&&qo(t),e<=at)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=Fe(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 la=new WeakMap,tn=class{ORDER;BITS;BYTES;isLE;ZERO=at;ONE=$;_lengths;_mod;constructor(t,r={}){if(t<=$)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}=Gf(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 et(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return at<=t&&t<this.ORDER}is0(t){return t===at}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&$)===$}neg(t){return et(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return et(t*t,this.ORDER)}add(t,r){return et(t+r,this.ORDER)}sub(t,r){return et(t-r,this.ORDER)}mul(t,r){return et(t*r,this.ORDER)}pow(t,r){return ga(t,r,this.ORDER)}div(t,r){return et(t*fa(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 fa(t,this.ORDER)}sqrt(t){let r=la.get(this);return r||la.set(this,r=Zf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Ho(t,this.BYTES):Jr(t,this.BYTES)}fromBytes(t,r=!1){V(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?ge(t):Ut(t);if(a&&(c=et(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return en(this,t,!0)}cmov(t,r,n){return wt(n,"condition"),n?r:t}};function Me(e,t={}){return Object.freeze(tn.prototype),new tn(e,t)}function Ea(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=$)throw new Error("field order must be greater than 1");let t=Fe(e-$);return Math.ceil(t/8)}function rn(e){let t=Ea(e);return t+Math.ceil(t/2)}function nn(e,t,r=!1){V(e);let n=e.length,o=Ea(t),s=Math.max(rn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ge(e):Ut(e),a=et(i,t-$)+$;return r?Ho(a,o):Jr(a,o)}var Wo=BigInt(0),wr=BigInt(1),Wf=BigInt(4),Yo=16,Sa=128,Xf=5,va=2**31;function ie(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);pe(t.fromAffine,"Point.fromAffine"),pe(t.fromBytes,"Point.fromBytes"),pe(t.fromHex,"Point.fromHex"),re(t.BASE,"Point.BASE"),re(t.ZERO,"Point.ZERO"),Ue(t.Fp),Ue(t.Fn)}function on(e,t){ie(e),Aa(t,e);let r=en(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Qf(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 Jf(e,t){let r=e*(4*t+128);if(r>va)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+va/2**20+" MiB")}function Xo(e,t){if(e!==void 0){pe(e,"randomBytes");try{let r=e(t);if(!oe(r)||r.length!==t)return}catch{return}return e}}function Aa(e,t){Xr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function tl(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 Ia=new WeakMap;function Go(e){return Ia.get(e)||1}function el(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 rl(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>Wo;){let i=0;e&wr&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=wr}return s}function nl(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+=wr),a.push(u)}if(e!==Wo)throw new Error("invalid wnaf");return a}function ol(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 ze=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){ie(t),this.randomBytes=Xo(r,Yo),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 l=0;l<s;l++)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=nl(r,n,o),c=this.ZERO,u=this.BASE;for(let l=0;l<o;l++){let d=a[l],f=l*i,p=Math.abs(d)-1,v=s[f];for(let w=1;w<i;w++)v=w===p?s[f+w]:v;let E=v.negate();d===0?u=u.add(s[f]):c=c.add(d<0?E:v)}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),!Vo(r,wr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=Go(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+Sa,s=this.randomBytes(Yo);if(!oe(s)||s.length!==Yo)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Ut(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,r,n){let o=Xf,s=1<<o,i=yr(o),a=new Array(s);a[0]=this.ZERO;for(let l=1;l<s;l++)a[l]=a[l-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let l=c-1;l>=0;l--){if(l!==c-1)for(let p=0;p<o;p++)u=u.double();let d=Number(r>>BigInt(l*o)&i),f=a[0];for(let p=1;p<s;p++)f=p===d?a[p]:f;u=u.add(f)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===wr?!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=Go(t);if(o===1||r>=this.Point.Fn.ORDER)return sn(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),Qf(r,this.bits);let n=Math.ceil((this.bits+Sa)/r)+1;Jf(n*2**(r-1),this.Point.Fp.BYTES),Ia.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return Go(t)!==1}};function sn(e,t,r,n=!1){if(ie(e),Aa(t,e),wt(n,"allowOversized"),tl(r,e.Fn,n?e.Fn.ORDER**Wf:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>el(i,4)),s=r.map(i=>rl(i,4));return ol(e.ZERO,o,s)}function _a(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ue(t),t}else return Me(e,{isLE:r})}function an(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`);xt(r);for(let c of["p","n","h"]){let u=t[c];if(!(ne(u)&&u!==Wo))throw new Error(`CURVE.${c} must be positive bigint`)}let o=_a(t.p,r.Fp,n),s=_a(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 cn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var un=BigInt(0),fn=BigInt(1),ln=BigInt(2),sl=BigInt(4),Ba=BigInt(8);function il(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 Ta(e,t={}){xt(t,{},{},"extraOpts");let r=t,n=an("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(br(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(br(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");xt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?me:r.randomBytes,u=ln<<BigInt(o.BYTES*8)-fn;function l(y){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(y)}let d=r.uvRatio===void 0?(y,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(y,g))}}catch{return{isValid:!1,value:un}}}:r.uvRatio;if(!il(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let f=o.eql(i.a,o.neg(o.ONE))?y=>o.neg(y):o.eql(i.a,o.ONE)?y=>y:y=>o.mul(i.a,y);function p(y,g,b=!1){let S=b?fn:un;return Ne("coordinate "+y,g,S,u),g}function v(y){if(!(y instanceof E))throw new Error("EdwardsPoint expected")}class E{static BASE=new E(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new E(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(g,b,S,I){this.X=p("x",g),this.Y=p("y",b),this.Z=p("z",S,!0),this.T=p("t",I),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof E)throw new Error("extended point not allowed");let{x:b,y:S}=g||{};return p("x",b),p("y",S),new E(b,S,o.ONE,o.mul(b,S))}static fromBytes(g,b=!1){let S=o.BYTES,{a:I,d:k}=i;g=gr(V(g,S,"point")),wt(b,"zip215");let N=gr(g),C=g[S-1];N[S-1]=C&-129;let R=ge(N),K=b?u:o.ORDER;Ne("point.y",R,un,K);let z=o.sqr(R),Z=o.sub(z,o.ONE),T=o.sub(o.mulN(k,z),I),{isValid:U,value:M}=d(Z,T);if(!U)throw new Error("bad point: invalid y coordinate");let O=l(M),G=(C&128)!==0;if(!b&&o.is0(M)&&G)throw new Error("bad point: x=0 and x_0=1");return G!==O&&(M=o.neg(M)),E.fromAffine({x:M,y:R})}static fromHex(g,b=!1){return E.fromBytes(ke(g),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,b=!0){return h.setWindowSize(this,g),b||this.multiply(ln),this}assertValidity(){let g=this,{a:b,d:S}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:I,Y:k,Z:N,T:C}=g,R=o.sqr(I),K=o.sqr(k),z=o.sqr(N),Z=o.sqr(z),T=o.mul(R,b),U=o.mul(o.add(T,K),z),M=o.add(Z,o.mul(S,o.mul(R,K)));if(!o.eql(U,M))throw new Error("bad point: equation left != right (1)");let O=o.mul(I,k),G=o.mul(N,C);if(!o.eql(O,G))throw new Error("bad point: equation left != right (2)")}equals(g){v(g);let{X:b,Y:S,Z:I}=this,{X:k,Y:N,Z:C}=g,R=o.mul(b,C),K=o.mul(k,I),z=o.mul(S,C),Z=o.mul(N,I);return o.eql(R,K)&&o.eql(z,Z)}is0(){return this.equals(E.ZERO)}negate(){return new E(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:b,Z:S}=this,I=o.sqr(g),k=o.sqr(b),N=o.mul(o.sqr(S),ln),C=f(I),R=o.addN(g,b),K=o.sub(o.subN(o.sqr(R),I),k),z=o.addN(C,k),Z=o.subN(z,N),T=o.subN(C,k),U=o.mul(K,Z),M=o.mul(z,T),O=o.mul(K,T),G=o.mul(Z,z);return new E(U,M,G,O)}add(g){v(g);let{d:b}=i,{X:S,Y:I,Z:k,T:N}=this,{X:C,Y:R,Z:K,T:z}=g,Z=o.mul(S,C),T=o.mul(I,R),U=o.mul(o.mulN(N,b),z),M=o.mul(k,K),O=o.sub(o.subN(o.mulN(o.addN(S,I),o.addN(C,R)),Z),T),G=o.subN(M,U),tt=o.addN(M,U),A=o.sub(T,f(Z)),m=o.mul(O,G),x=o.mul(tt,A),_=o.mul(O,A),B=o.mul(G,tt);return new E(m,x,B,_)}subtract(g){return v(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:S}=h.mulSecret(this,g,a,w);return w([b,S])[0]}multiplyUnsafe(g){if(!s.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===un?E.ZERO:this.is0()||g===fn?this:h.mulUnsafe(this,g,w)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return h.mulUnsafe(this,i.n).is0()}toAffine(g){let b=this,S=g;if(S!=null&&typeof S!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof S);let{X:I,Y:k,Z:N}=b,C=b.is0();S==null&&(S=C?o.create(Ba):o.inv(N));let R=o.mul(I,S),K=o.mul(k,S),z=o.mul(N,S);if(C)return{x:o.ZERO,y:o.ONE};if(!o.eql(z,o.ONE))throw new Error("invZ was invalid");return{x:R,y:K}}clearCofactor(){return a===fn?this:a===ln?this.double():a===sl?this.double().double():a===Ba?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:b}=this.toAffine(),S=o.toBytes(b);return S[S.length-1]|=l(g)?128:0,S}toHex(){return pr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let w=y=>on(E,y),h=new ze(E,c);return h.bits>=6&&E.BASE.precompute(6),Object.freeze(E.prototype),Object.freeze(E),E}function La(e,t,r={}){if(ie(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;xt(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,l=2*a.BYTES;if(u!==void 0&&(Kt(u,"hash.outputLen"),u!==l))throw new Error(`hash.outputLen must be ${l}, got ${u}`);let d=o.randomBytes===void 0?me:o.randomBytes,f=o.toMontgomery,p=o.toMontgomerySecret,v=o.adjustScalarBytes===void 0?T=>T:o.adjustScalarBytes,E=o.domain===void 0?(T,U,M)=>{if(wt(M,"phflag"),U.length||M)throw new Error("Contexts/pre-hash are not supported");return T}:o.domain;function w(T){return c.create(ge(T))}function h(T){let U=C.secretKey;V(T,C.secretKey,"secretKey");let M=V(n(T),2*U,"hashedSecretKey"),O=v(M.slice(0,U)),G=M.slice(U,2*U),tt=w(O);return{head:O,prefix:G,scalar:tt}}function y(T){let{head:U,prefix:M,scalar:O}=h(T),G=i.multiply(O),tt=G.toBytes();return{head:U,prefix:M,scalar:O,point:G,pointBytes:tt}}function g(T){return y(T).pointBytes}function b(T=Uint8Array.of(),...U){let M=Tt(...U);return w(n(E(M,V(T,void 0,"context"),!!s)))}function S(T,U,M={}){xt(M,{},{},"options"),T=gr(V(T,void 0,"message")),s&&(T=s(T));let{prefix:O,scalar:G,pointBytes:tt}=y(U),A=b(M.context,O,T),m=i.multiply(A).toBytes(),x=b(M.context,m,tt,T),_=c.create(A+x*G);if(!c.isValid(_))throw new Error("sign failed: invalid s");let B=Tt(m,c.toBytes(_));return V(B,C.signature,"result")}let I={zip215:o.zip215};function k(T,U,M,O=I){xt(O);let{context:G}=O,tt=O.zip215===void 0?!!I.zip215:O.zip215,A=C.signature;T=V(T,A,"signature"),U=V(U,void 0,"message"),M=V(M,C.publicKey,"publicKey"),tt!==void 0&&wt(tt,"zip215"),s&&(U=s(U));let m=A/2,x=T.subarray(0,m),_=ge(T.subarray(m,A)),B,L,D;try{B=e.fromBytes(M,tt),L=e.fromBytes(x,tt),D=i.multiplyUnsafe(_)}catch{return!1}if(!tt&&B.isSmallOrder())return!1;let P=b(G,x,M,U);return L.add(B.multiplyUnsafe(P)).subtract(D).clearCofactor().is0()}let N=a.BYTES,C={secretKey:N,publicKey:N,signature:2*N,seed:N};function R(T){return T=T===void 0?d(C.seed):T,V(T,C.seed,"seed")}function K(T){return oe(T)&&T.length===C.secretKey}function z(T,U){try{return!!e.fromBytes(T,U===void 0?I.zip215:U)}catch{return!1}}let Z={getExtendedPublicKey:y,randomSecretKey:R,isValidSecretKey:K,isValidPublicKey:z,toMontgomery(T){if(f===void 0)throw new Error("Montgomery conversion is not supported for this curve");return f(e.fromBytes(T))},toMontgomerySecret(T){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(T)}};return Object.freeze(C),Object.freeze(Z),Object.freeze({keygen:cn(R,g),getPublicKey:g,sign:S,verify:k,utils:Z,Point:e,lengths:C})}var Qo=BigInt(1),Da=BigInt(2);var al=BigInt(5),cl=BigInt(8),Jo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ul={p:Jo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:cl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function fl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Jo,a=e*e%s*e%s,c=J(a,Da,s)*a%s,u=J(c,Qo,s)*e%s,l=J(u,al,s)*u%s,d=J(l,t,s)*l%s,f=J(d,r,s)*d%s,p=J(f,n,s)*f%s,v=J(p,o,s)*p%s,E=J(v,o,s)*p%s,w=J(E,t,s)*l%s;return{pow_p_5_8:J(w,Da,s)*e%s,b2:a}}function Ra(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ca=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ll(e,t){let r=Jo,n=et(t*t*t,r),o=et(n*n*t,r),s=fl(e*o).pow_p_5_8,i=et(e*n*s,r),a=et(t*i*i,r),c=i,u=et(i*Ca,r),l=a===e,d=a===et(-e,r),f=a===et(-e*Ca,r);return l&&(i=c),(d||f)&&(i=u),xa(i,r)&&(i=et(-i,r)),{isValid:l||d,value:i}}var ts=Ta(ul,{uvRatio:ll}),Oa=ts.Fp;function dl(e){let{y:t}=e;return Oa.toBytes(Oa.div(Qo+t,Qo-t))}function hl(e){let t=ts.Fp.BYTES;return Bt(e,t),Ra(Ko(e.subarray(0,t))).subarray(0,t)}function pl(e){return La(ts,Ko,Object.assign({adjustScalarBytes:Ra,toMontgomery:dl,toMontgomerySecret:hl,zip215:!0},e))}var Pa=pl({});var xr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},dn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var hn={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new dn("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 pn=32;var es,ml=(async()=>{try{return await hn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function gl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await hn.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await hn.get().subtle.verify({name:"Ed25519"},n,Dt(t),Dt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function yl(e,t,r){return Pa.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ka(e,t,r){return es==null&&(es=await ml),es?gl(e,t,r):yl(e,t,r)}function mn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var gn=class{type="Ed25519";raw;constructor(t){this.raw=rs(t,pn)}toMultihash(){return Lt.digest(Re(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ka(this.raw,r,t);return mn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Fa(e){return e=rs(e,pn),new gn(e)}function rs(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 wl=Math.pow(2,7),xl=Math.pow(2,14),El=Math.pow(2,21),ns=Math.pow(2,28),os=Math.pow(2,35),ss=Math.pow(2,42),is=Math.pow(2,49),j=128,mt=127;function Et(e){if(e<wl)return 1;if(e<xl)return 2;if(e<El)return 3;if(e<ns)return 4;if(e<os)return 5;if(e<ss)return 6;if(e<is)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ke(e,t,r=0){switch(Et(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 Sl(e,t,r=0){switch(Et(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 as(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)*ns,r<j)||(r=e[t+5],n+=(r&mt)*os,r<j)||(r=e[t+6],n+=(r&mt)*ss,r<j)||(r=e[t+7],n+=(r&mt)*is,r<j))return n;throw new RangeError("Could not decode varint")}function vl(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)*ns,r<j)||(r=e.get(t+5),n+=(r&mt)*os,r<j)||(r=e.get(t+6),n+=(r&mt)*ss,r<j)||(r=e.get(t+7),n+=(r&mt)*is,r<j))return n;throw new RangeError("Could not decode varint")}function Ua(e,t,r=0){return t==null&&(t=pt(Et(e))),t instanceof Uint8Array?Ke(e,t,r):Sl(e,t,r)}function Er(e,t=0){return e instanceof Uint8Array?as(e,t):vl(e,t)}var cs=new Float32Array([-0]),ae=new Uint8Array(cs.buffer);function za(e,t,r){cs[0]=e,t[r]=ae[0],t[r+1]=ae[1],t[r+2]=ae[2],t[r+3]=ae[3]}function Ka(e,t){return ae[0]=e[t],ae[1]=e[t+1],ae[2]=e[t+2],ae[3]=e[t+3],cs[0]}var us=new Float64Array([-0]),gt=new Uint8Array(us.buffer);function qa(e,t,r){us[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 Ha(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],us[0]}var _l=BigInt(Number.MAX_SAFE_INTEGER),Al=BigInt(Number.MIN_SAFE_INTEGER),vt=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 ye;if(t<_l&&t>Al)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Va&&(o=0n,++n>Va&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ye;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):ye}},ye=new vt(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var Va=4294967296n;function $a(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 ja(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 fs(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 Ot(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function yn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ls=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Dt(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,Ot(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 Ot(this,4);return yn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ot(this,4);return yn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ot(this,4);let t=Ka(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ot(this,4);let t=Ha(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 Ot(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ja(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ot(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ot(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 vt(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 Ot(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 Ot(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 Ot(this,8);let t=yn(this.buf,this.pos+=4),r=yn(this.buf,this.pos+=4);return new vt(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=as(this.buf,this.pos);return this.pos+=Et(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 Sr(e){return new ls(e instanceof Uint8Array?e:e.subarray())}function qt(e,t,r){let n=Sr(e);return t.decode(n,void 0,r)}function ds(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 be=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function hs(){}var ms=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Il=ds();function Bl(e){return globalThis.Buffer!=null?pt(e):Il(e)}var _r=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(hs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new be(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new gs((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(bn,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(bn,r.length(),r)}uint64Number(t){return this._push(Ke,Et(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=vt.fromBigInt(t).zzEncode();return this._push(bn,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(bn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ps,1,t?1:0)}fixed32(t){return this._push(vr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(vr,4,r.lo)._push(vr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(vr,4,r.lo)._push(vr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(za,4,t)}double(t){return this._push(qa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ps,1,0):this.uint32(r)._push(Ll,r,t)}string(t){let r=$a(t);return r!==0?this.uint32(r)._push(fs,r,t):this._push(ps,1,0)}fork(){return this.states=new ms(this),this.head=this.tail=new be(hs,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 be(hs,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=Bl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ps(e,t,r){t[r]=e&255}function Tl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var gs=class extends be{next;constructor(t,r){super(Tl,t,r),this.next=void 0}};function bn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function vr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Ll(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(_r.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Dl,t,e),this},_r.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Cl,t,e),this});function Dl(e,t,r){t.set(e,r)}function Cl(e,t,r){e.length<40?fs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Q(e),r)}function ys(){return new _r}function Ht(e,t){let r=ys();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Vt(e,t,r){let n=Sr(e);yield*t.stream(n,void 0,".",r)}var wn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function xn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function qe(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 xn("enum",wn.VARINT,r,n,o)}function $t(e,t,r){return xn("message",wn.LENGTH_DELIMITED,e,t,r)}var Ar=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 bs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(bs||(bs={}));(function(e){e.codec=()=>qe(bs)})(bt||(bt={}));var Ir;(function(e){let t;e.codec=()=>(t==null&&(t=$t((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 l=s.uint32();switch(l>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>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(l&7);break}}}})),t);function r(s){return Ht(s,e.codec())}e.encode=r;function n(s,i){return qt(s,e.codec(),i)}e.decode=n;function o(s,i){return Vt(s,e.codec(),i)}e.stream=o})(Ir||(Ir={}));var ws;(function(e){let t;e.codec=()=>(t==null&&(t=$t((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 l=s.uint32();switch(l>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>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(l&7);break}}}})),t);function r(s){return Ht(s,e.codec())}e.encode=r;function n(s,i){return qt(s,e.codec(),i)}e.decode=n;function o(s,i){return Vt(s,e.codec(),i)}e.stream=o})(ws||(ws={}));var En=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if($r(t),Bt(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),he(o)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),jr(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()}},Ya=(()=>{let e=((t,r,n)=>new En(t,r).update(n).digest());return e.create=(t,r)=>new En(t,r),e})();var Rl=BigInt(0),xs=class extends Error{constructor(t=""){super(t)}},jt={Err:xs,_tlv:{encode:(e,t)=>{let{Err:r}=jt;if(Kt(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=mr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?mr(o.length/2|128):"";return mr(e)+s+o+t},decode(e,t){let{Err:r}=jt;t=V(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 l of u)i=i<<8|l;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}=jt;if(Qr(e),e<Rl)throw new t("integer: negative integers are not allowed");let r=mr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=jt;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 Ut(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:o}=jt;if(t!==void 0&&(Kt(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=V(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:l,l:d}=o.decode(2,u);if(d.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||l.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:r}=jt;xt(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)}},Sn=(Object.freeze(jt._tlv),Object.freeze(jt._int),Object.freeze(jt));var Ga=(e,t)=>(e+(e>=0?t:-t)/Wa)/t;function Pl(e,t,r){Ne("scalar",e,Zt,r);let[[n,o],[s,i]]=t,a=Ga(i*e,r),c=Ga(-o*e,r),u=e-a*n-c*s,l=-a*o-c*i,d=u<Zt,f=l<Zt;d&&(u=-u),f&&(l=-l);let p=yr(Math.ceil(Fe(r)/2))+we;if(u<Zt||u>=p||l<Zt||l>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:f,k2:l}}function vs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Es(e,t){xt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return wt(r.lowS,"lowS"),wt(r.prehash,"prehash"),r.format!==void 0&&vs(r.format),r}var Zt=BigInt(0),we=BigInt(1),Wa=BigInt(2),Ss=BigInt(3),kl=BigInt(4);function Xa(e,t={}){let r=an("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;xt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:l,isTorsionFree:d,fromBytes:f,toBytes:p}=t,v=t.randomBytes===void 0?me: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 E=c?{beta:c.beta,basises:c.basises.map(A=>[...A])}:void 0,w=Ja(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function y(A,m,x){if(m.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:_,y:B}=m.toAffine(),L=n.toBytes(_);if(wt(x,"isCompressed"),x){h();let D=!n.isOdd(B);return Tt(Qa(D),L)}else return Tt(Uint8Array.of(4),L,n.toBytes(B))}function g(A){V(A,void 0,"Point");let{publicKey:m,publicKeyUncompressed:x}=w,_=A.length,B=A[0],L=A.subarray(1);if(u&&_===1&&B===0)return{x:n.ZERO,y:n.ZERO};if(_===m&&(B===2||B===3)){let D=n.fromBytes(L);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let P=N(D),F;try{F=n.sqrt(P)}catch(nt){let W=nt instanceof Error?": "+nt.message:"";throw new Error("bad point: is not on curve, sqrt error"+W)}h();let H=n.isOdd(F);return(B&1)===1!==H&&(F=n.neg(F)),{x:D,y:F}}else if(_===x&&B===4){let D=n.BYTES,P=n.fromBytes(L.subarray(0,D)),F=n.fromBytes(L.subarray(D,D*2));if(!C(P,F))throw new Error("bad point: is not on curve");return{x:P,y:F}}else throw new Error(`bad point: got length ${_}, expected compressed=${m} or uncompressed=${x}`)}let b=p===void 0?y:p,S=f===void 0?g:f,I=n.mul(s.b,Ss),k=n.is0(s.a)?A=>n.ZERO:A=>n.mul(s.a,A);function N(A){let m=n.sqr(A),x=n.mul(m,A);return n.add(n.add(x,n.mul(A,s.a)),s.b)}function C(A,m){let x=n.sqr(m),_=N(A);return n.eql(x,_)}if(!C(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let R=n.mul(n.pow(s.a,Ss),kl),K=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(R,K)))throw new Error("bad curve params: a or b");function z(A,m,x=!1){if(!n.isValid(m)||x&&n.is0(m))throw new Error(`bad point coordinate ${A}`);return typeof m=="object"&&m!==null?n.create(m):m}function Z(A){if(!(A instanceof O))throw new Error("Weierstrass Point expected")}function T(A){if(!E||!E.basises)throw new Error("no endo");return Pl(A,E.basises,o.ORDER)}function U(A,m,x,_){if(!o.isValid(_))throw new RangeError("invalid scalar: out of range");if(E){let{k1neg:B,k1:L,k2neg:D,k2:P}=T(_),F=new O(n.mul(x.X,E.beta),x.Y,x.Z);A.push(B?x.negate():x,D?F.negate():F),m.push(L,P)}else A.push(x),m.push(_)}let M=new WeakSet;class O{static BASE=new O(s.Gx,s.Gy,n.ONE);static ZERO=new O(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,x,_){this.X=z("x",m),this.Y=z("y",x,!0),this.Z=z("z",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x,y:_}=m||{};if(!m||!n.isValid(x)||!n.isValid(_))throw new Error("invalid affine point");if(m instanceof O)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(_)?O.ZERO:new O(x,_,n.ONE)}static fromBytes(m){let x=O.fromAffine(S(V(m,void 0,"point")));return x.assertValidity(),x}static fromHex(m){return O.fromBytes(ke(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=6,x=!0){return tt.setWindowSize(this,m),x||this.multiply(Ss),this}assertValidity(){let m=this;if(m.is0()){if(u&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}if(M.has(m))return;let{x,y:_}=m.toAffine();if(!n.isValid(x)||!n.isValid(_))throw new Error("bad point: x or y not field elements");if(!C(x,_))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");M.add(m)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){Z(m);let{X:x,Y:_,Z:B}=this,{X:L,Y:D,Z:P}=m,F=n.eql(n.mul(x,P),n.mul(L,B)),H=n.eql(n.mul(_,P),n.mul(D,B));return F&&H}negate(){return new O(this.X,n.neg(this.Y),this.Z)}double(){let{X:m,Y:x,Z:_}=this,B=n.ZERO,L=n.ZERO,D=n.ZERO,P=n.mul(m,m),F=n.mul(x,x),H=n.mul(_,_),q=n.mul(m,x);return q=n.add(q,q),D=n.mul(m,_),D=n.add(D,D),B=k(D),L=n.mul(I,H),L=n.add(B,L),B=n.sub(F,L),L=n.add(F,L),L=n.mul(B,L),B=n.mul(q,B),D=n.mul(I,D),H=k(H),q=n.sub(P,H),q=k(q),q=n.add(q,D),D=n.add(P,P),P=n.add(D,P),P=n.add(P,H),P=n.mul(P,q),L=n.add(L,P),H=n.mul(x,_),H=n.add(H,H),P=n.mul(H,q),B=n.sub(B,P),D=n.mul(H,F),D=n.add(D,D),D=n.add(D,D),new O(B,L,D)}add(m){Z(m);let{X:x,Y:_,Z:B}=this,{X:L,Y:D,Z:P}=m,F=n.ZERO,H=n.ZERO,q=n.ZERO,nt=n.mul(x,L),W=n.mul(_,D),ct=n.mul(B,P),_t=n.add(x,_),X=n.add(L,D);_t=n.mul(_t,X),X=n.add(nt,W),_t=n.sub(_t,X),X=n.add(x,B);let ot=n.add(L,P);return X=n.mul(X,ot),ot=n.add(nt,ct),X=n.sub(X,ot),ot=n.add(_,B),F=n.add(D,P),ot=n.mul(ot,F),F=n.add(W,ct),ot=n.sub(ot,F),q=k(X),F=n.mul(I,ct),q=n.add(F,q),F=n.sub(W,q),q=n.add(W,q),H=n.mul(F,q),W=n.add(nt,nt),W=n.add(W,nt),ct=k(ct),X=n.mul(I,X),W=n.add(W,ct),ct=n.sub(nt,ct),ct=k(ct),X=n.add(X,ct),nt=n.mul(W,X),H=n.add(H,nt),nt=n.mul(ot,X),F=n.mul(_t,F),F=n.sub(F,nt),nt=n.mul(_t,W),q=n.mul(ot,q),q=n.add(q,nt),new O(F,H,q)}subtract(m){return Z(m),this.add(m.negate())}is0(){return this.equals(O.ZERO)}multiply(m){if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let{p:x,f:_}=tt.mulSecret(this,m,i,G);return G([x,_])[0]}multiplyUnsafe(m){let x=this,_=m;if(!o.isValid(_))throw new RangeError("invalid scalar: out of range");if(_===Zt||x.is0())return O.ZERO;if(_===we)return x;if(tt.hasWindowSize(this))return tt.mulUnsafe(x,_,G);let B=[],L=[];return U(B,L,x,_),sn(O,B,L)}mulAddUnsafe(m,x,_){Z(x);let B=[],L=[];return U(B,L,this,m),U(B,L,x,_),sn(O,B,L)}toAffine(m){let x=this,_=m;if(_!=null&&!n.isValid(_))throw new RangeError('"invertedZ" expected valid field element');let{X:B,Y:L,Z:D}=x;if(n.eql(D,n.ONE))return{x:B,y:L};let P=x.is0();_==null&&(_=P?n.ONE:n.inv(D));let F=n.mul(B,_),H=n.mul(L,_),q=n.mul(D,_);if(P)return{x:n.ZERO,y:n.ZERO};if(!n.eql(q,n.ONE))throw new Error("invZ was invalid");return{x:F,y:H}}isTorsionFree(){return i===we?!0:d?d(O,this):tt.mulUnsafe(this,a).is0()}clearCofactor(){return i===we?this:l?l(O,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===we?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return wt(m,"isCompressed"),this.assertValidity(),b(O,this,m)}toHex(m=!0){return pr(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let G=A=>on(O,A),tt=new ze(O,v);return tt.bits>=6&&O.BASE.precompute(6),Object.freeze(O.prototype),Object.freeze(O),O}function Qa(e){return Uint8Array.of(e?2:3)}function Ja(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Nl(e,t={}){ie(e);let{Fn:r}=e,n=t.randomBytes===void 0?me:t.randomBytes,o=Object.assign(Ja(e.Fp,r),{seed:Math.max(rn(r.ORDER),16)});function s(p){try{let v=r.fromBytes(p);return r.isValidNot0(v)}catch{return!1}}function i(p,v){let{publicKey:E,publicKeyUncompressed:w}=o;try{let h=p.length;return v===!0&&h!==E||v===!1&&h!==w?!1:!e.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,nn(V(p,o.seed,"seed"),r.ORDER)}function c(p,v=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(v)}function u(p){let{secretKey:v,publicKey:E,publicKeyUncompressed:w}=o,h=r._lengths;if(!oe(p))return;let y=V(p,void 0,"key").length,g=y===E||y===w,b=y===v||!!h?.includes(y);if(!(g&&b))return g}function l(p,v,E=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(v)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(p),h=e.fromBytes(v);if(h.is0())throw new Error("invalid public key: point at infinity");return h.multiply(w).toBytes(E)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},f=cn(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:f,Point:e,utils:d,lengths:o})}function tc(e,t,r={}){ie(e);let n=t;$r(n),xt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?me:o.randomBytes,i=o.hmac===void 0?(A,m)=>Ya(n,A,m):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:l}=c,d=rn(u),f=Xo(s,d),{keygen:p,getPublicKey:v,getSharedSecret:E,utils:w,lengths:h}=Nl(e,o),y={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*Wa+we<a.ORDER;function b(A){let m=u>>we;return A>m}function S(A,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${A}: out of range 1..Point.Fn.ORDER`);return m}function I(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function k(A,m,x){return I(),(A===x?0:2)|Number(a.isOdd(m))}function N(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(A,m){vs(m);let x=h.signature,_=m==="compact"?x:m==="recovered"?x+1:void 0;return V(A,_)}class R{r;s;recovery;constructor(m,x,_){if(this.r=S("r",m),this.s=S("s",x),_!=null){if(N(),![0,1,2,3].includes(_))throw new Error("invalid recovery id");this.recovery=_}Object.freeze(this)}static fromBytes(m,x=y.format){C(m,x);let _;if(x==="der"){if(m.length>2*c.BYTES+16)throw new Sn.Err("invalid signature: DER signature too long");let{r:P,s:F}=Sn.toSig(V(m),c.BYTES+1);return new R(P,F)}x==="recovered"&&(_=m[0],x="compact",m=m.subarray(1));let B=h.signature/2,L=m.subarray(0,B),D=m.subarray(B,B*2);return new R(c.fromBytes(L),c.fromBytes(D),_)}static fromHex(m,x){return this.fromBytes(ke(m),x)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new R(this.r,this.s,m)}recoverPublicKey(m){let{r:x,s:_}=this,B=this.assertRecovery(),L=B===2||B===3?x+u:x;if(!a.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=a.toBytes(L),P=e.fromBytes(Tt(Qa((B&1)===0),D)),F=c.inv(L),H=z(V(m,void 0,"msgHash")),q=c.create(-H*F),nt=c.create(_*F),W=e.BASE.mulAddUnsafe(q,P,nt);if(W.is0())throw new Error("invalid recovery: point at infinify");return W.assertValidity(),W}hasHighS(){return b(this.s)}toBytes(m=y.format){if(vs(m),m==="der")return ke(Sn.hexFromSig(this));let{r:x,s:_}=this,B=c.toBytes(x),L=c.toBytes(_);return m==="recovered"?(N(),Tt(Uint8Array.of(this.assertRecovery()),B,L)):Tt(B,L)}toHex(m){return pr(this.toBytes(m))}}Object.freeze(R.prototype),Object.freeze(R);let K=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let x=Ut(m),_=m.length*8-l;return _>0?x>>BigInt(_):x}:o.bits2int,z=o.bits2int_modN===void 0?function(m){return c.create(K(m))}:o.bits2int_modN,Z=yr(l);function T(A){return Ne("num < 2^"+l,A,Zt,Z),c.toBytes(A)}function U(A,m){return V(A,void 0,"message"),m?V(n(A),void 0,"prehashed message"):A}function M(A,m,x){let{lowS:_,prehash:B,extraEntropy:L}=Es(x,y);A=U(A,B);let D=z(A),P=c.fromBytes(m);if(!c.isValidNot0(P))throw new Error("invalid private key");let F=[T(P),T(D)];if(L!=null&&L!==!1){let W=L===!0?s(h.secretKey):L;F.push(V(W,void 0,"extraEntropy"))}let H=Tt(...F),q=D;function nt(W){let ct=K(W);if(!c.isValidNot0(ct))return;let _t=e.BASE.multiply(ct).toAffine(),X=c.create(_t.x);if(X===Zt)return;let ot;if(f!==void 0){let tr=Ut(nn(f(d),u)),jc=c.inv(c.mul(tr,ct)),Zc=c.mul(tr,q),Yc=c.mul(tr,P);ot=c.create(jc*c.create(Zc+Yc*X))}else{let tr=ya(ct,u);ot=c.create(tr*c.create(q+X*P))}if(ot===Zt)return;let Xn=k(_t.x,_t.y,X),si=ot;return _&&b(ot)&&(si=c.neg(ot),Xn^=1),new R(X,si,g?void 0:Xn)}return{seed:H,k2sig:nt}}function O(A,m,x={}){let{seed:_,k2sig:B}=M(A,m,x);return ua(n.outputLen,c.BYTES,i)(_,B).toBytes(x.format)}function G(A,m,x,_={}){let{lowS:B,prehash:L,format:D}=Es(_,y);if(x=V(x,void 0,"publicKey"),m=U(m,L),!oe(A)){let P=A instanceof R?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}C(A,D);try{let P=R.fromBytes(A,D),F=e.fromBytes(x);if(F.is0()||B&&P.hasHighS())return!1;let{r:H,s:q}=P,nt=z(m),W=c.inv(q),ct=c.create(nt*W),_t=c.create(H*W),X=e.BASE.mulAddUnsafe(ct,F,_t);if(X.is0())return!1;let ot=X.toAffine();return!(c.create(ot.x)!==H||D==="recovered"&&P.recovery!==k(ot.x,ot.y,H))}catch{return!1}}function tt(A,m,x={}){let{prehash:_}=Es(x,y);return m=U(m,_),R.fromBytes(A,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:p,getPublicKey:v,getSharedSecret:E,utils:w,lengths:h,Point:e,sign:O,verify:G,recoverPublicKey:tt,Signature:R,hash:n})}var As={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Fl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ec=BigInt(2);function Ul(e){let t=As.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,l=u*u*e%t,d=J(l,r,t)*l%t,f=J(d,r,t)*l%t,p=J(f,ec,t)*u%t,v=J(p,o,t)*p%t,E=J(v,s,t)*v%t,w=J(E,a,t)*E%t,h=J(w,c,t)*w%t,y=J(h,a,t)*E%t,g=J(y,r,t)*l%t,b=J(g,i,t)*v%t,S=J(b,n,t)*u%t,I=J(S,ec,t);if(!_s.eql(_s.sqr(I),e))throw new Error("Cannot find square root");return I}var _s=Me(As.p,{sqrt:Ul}),Ml=Xa(As,{Fp:_s,endo:Fl}),He=tc(Ml,sa);function rc(e,t,r,n){let o=ar.digest(r instanceof Uint8Array?r:r.subarray());if(mn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),He.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new xr(String(s))});try{return n?.signal?.throwIfAborted(),He.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new xr(String(s))}}var vn=class{type="secp256k1";raw;_key;constructor(t){this._key=oc(t),this.raw=nc(this._key)}toMultihash(){return Lt.digest(Re(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){return rc(this._key,r,t,n)}};function sc(e){return new vn(e)}function nc(e){return He.Point.fromBytes(e).toBytes()}function oc(e){try{return He.Point.fromBytes(e),e}catch(t){throw new er(String(t))}}function ic(e){let{Type:t,Data:r}=Ir.decode(e.digest),n=r??new Uint8Array;switch(t){case bt.Ed25519:return Fa(n);case bt.secp256k1:return sc(n);case bt.ECDSA:return Ui(n);default:throw new rr}}function Re(e){return Ir.encode({Type:bt[e.type],Data:e.raw})}var ac=Symbol.for("nodejs.util.inspect.custom"),zl=114,Br=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Jn]=!0;toString(){return this.string==null&&(this.string=st.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ht.createV1(zl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ac](){return`PeerId(${this.toString()})`}},_n=class extends Br{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},An=class extends Br{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},In=class extends Br{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Kl=2336,Bn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Lt.digest(Q(this.url))}[ac](){return`PeerId(${this.url})`}[Jn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ht.createV1(Kl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=it(t)),t.toString()===this.toString())}};function Tn(e){if(Hl(e))return new _n({multihash:e});if(ql(e))try{let t=ic(e);if(t.type==="Ed25519")return new An({multihash:e,publicKey:t});if(t.type==="secp256k1")return new In({multihash:e,publicKey:t})}catch{let r=it(e.digest);return new Bn(new URL(r))}throw new Fr("Supplied PeerID Multihash is invalid")}function ql(e){return e.code===Lt.code}function Hl(e){return e.code===ar.code}function Is(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 Ln(e){let t=fe(st.decode(`z${e}`));return Tn(t)}var Dn=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 Is(this.set.entries(),t=>{let r=Ln(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=Ln(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Is(this.set.values(),t=>Ln(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 Bs(){return new Dn}var Ts={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},cc={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},uc=new globalThis.TextEncoder;function Vl(e,t){let r=Ts[t],n=cc[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function $l(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Ts[t],o=cc[t],s=e;for(;s.length>0;){let i=uc.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 Ls(e,{size:t=32,utf8Buffer:r}={}){if(!Ts[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 $l(e,t,r);e=uc.encode(e)}return Vl(e,t)}var Tr={hash:e=>Number(Ls(e,{size:32})),hashV:(e,t)=>jl(Tr.hash(e,t))};function jl(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),Q(t,"base16")}var Ds=64,Rt=class{fp;h;seed;constructor(t,r,n,o=2){if(o>Ds)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=It(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?lt(this.fp,t.fp):!1}};function xe(e,t){return Math.floor(Math.random()*(t-e))+e}var Ee=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Rt))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Rt))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 Rt))throw new TypeError("Invalid Fingerprint");let r=xe(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=t,n}remove(t){if(!(t instanceof Rt))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var Zl=500,Lr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Tr,this.seed=t.seed??xe(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=Q(t));let r=new Rt(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 Ee(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Ee(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[xe(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Ee(this.bucketSize));for(let a=0;a<Zl;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 Ee(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=Q(t));let r=new Rt(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=Q(t));let r=new Rt(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}},Yl={1:.5,2:.84,4:.95,8:.98};function Gl(e=.001){return e>.002?2:e>1e-5?4:8}function fc(e,t=.001){let r=Gl(t),n=Yl[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),Ds);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var Cn=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??Tr,this.seed=t.seed??xe(0,Math.pow(2,10)),this.filterSeries=[new Lr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=Q(t)),this.has(t))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new Lr({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=Q(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=Q(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 Cs(e,t=.001,r){return new Cn({...fc(e,t),...r??{}})}function Wl(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 Pt(e){let t=Wl(e);if(t==null)throw new yt(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var On=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 l=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let f=Number.parseInt(d,t);if(!Number.isNaN(f))return f});if(l===void 0)break;if(s*=t,s+=l,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 lc=45,Xl=15,Ve=new On;function Rn(e){if(!(e.length>Xl))return Ve.new(e).parseWith(()=>Ve.readIPv4Addr())}function Pn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>lc))return Ve.new(e).parseWith(()=>Ve.readIPv6Addr())}function $e(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>lc)return;let r=Ve.new(e).parseWith(()=>Ve.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 dc(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 hc(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 Os(e){switch(e.length){case Se:return e.join(".");case ve:{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 pc(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 mc(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var Se=4,ve=16,bb=parseInt("0xFFFF",16),Ql=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Dr(e,t){t.length===ve&&e.length===Se&&dc(t,0,11)&&(t=t.slice(12)),t.length===Se&&e.length===ve&&hc(e,Ql,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 gc(e,t){if(typeof t=="string"&&(t=$e(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 Rs(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=Se,o=Rn(t);if(o==null&&(n=ve,o=Pn(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=Ps(s,8*n);return{network:Dr(o,i),mask:i}}function Ps(e,t){if(t!==8*Se&&t!==8*ve)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 Cr=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=Rs(t));else{let n=$e(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=$e(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ps(o,8*n.length);this.network=Dr(n,this.mask)}}contains(t){return gc({network:this.network,mask:this.mask},t)}toString(){let t=pc(this.mask),r=t!==-1?String(t):mc(this.mask);return Os(this.network)+"/"+r}};function yc(e,t){return new Cr(e).contains(t)}function bc(e){try{let t=Pt(e);return t.type==="ip6"?yc("2000::/3",t.host):!1}catch{return!1}}function je(e){return!!Rn(e)}function kn(e){return!!Pn(e)}var Sc=tu(Ec(),1),sd=["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"],id=sd.map(e=>new Sc.Netmask(e));function Ks(e){for(let t of id)if(t.contains(e))return!0;return!1}function ad(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 Ks(o)}function ud(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function fd(e){let t=e.split(":"),r=t[t.length-1];return Ks(r)}function ld(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 vc(e){if(je(e))return Ks(e);if(ad(e))return cd(e);if(ud(e))return fd(e);if(kn(e))return ld(e)}function qs(e){try{let t=Pt(e);switch(t.type){case"ip4":case"ip6":return vc(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var dt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Yt=class extends Error{static name="ValidationError";name="ValidationError"},Fn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Un=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Vs(e){return t=>it(t,e)}function $s(e){return t=>Q(t,e)}function We(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Ae(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}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!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=Q(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=Ae(n);return Nt([r,o],r.length+o.length)}function Ac(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=Xt.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=Ae(n);return Nt([r,o],r.length+o.length)}function js(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=it(t,"base32"),o=We(r);return`${n}:${o}`}var Zs=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 dt("Invalid byte value in IP address");t[n]=o}),t},Ic=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=je(r[n]),i;s&&(i=Zs(r[n]),r[n]=it(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,it(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 dt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Bc=function(e){if(e.byteLength!==4)throw new dt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Tc=function(e){if(e.byteLength!==16)throw new dt("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 dt(`Invalid IPv6 address "${r}"`)}};function Lc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new dt(`Invalid IPv6 address "${e}"`)}}var Hs=Object.values(cr).map(e=>e.decoder),dd=(function(){let e=Hs[0].or(Hs[1]);return Hs.slice(2).forEach(t=>e=e.or(t)),e})();function Dc(e){return dd.decode(e)}function Cc(e){return t=>e.encoder.encode(t)}function hd(e){if(parseInt(e).toString()!==e)throw new Yt("Value must be an integer")}function pd(e){if(e<0)throw new Yt("Value must be a positive integer, or zero")}function md(e){return t=>{if(t>e)throw new Yt(`Value must be smaller than or equal to ${e}`)}}function gd(...e){return t=>{for(let r of e)r(t)}}var Or=gd(hd,pd,md(65535));var ft=-1,Ys=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 Un(`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)}))}},Gt=new Ys,rh=[{code:4,name:"ip4",size:32,valueToBytes:Zs,bytesToValue:Bc,validate:e=>{if(!je(e))throw new Yt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ae,bytesToValue:We,validate:Or},{code:273,name:"udp",size:16,valueToBytes:Ae,bytesToValue:We,validate:Or},{code:33,name:"dccp",size:16,valueToBytes:Ae,bytesToValue:We,validate:Or},{code:41,name:"ip6",size:128,valueToBytes:Ic,bytesToValue:Tc,stringToValue:Lc,validate:e=>{if(!kn(e))throw new Yt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ft},{code:43,name:"ipcidr",size:8,bytesToValue:Vs("base10"),valueToBytes:$s("base10")},{code:53,name:"dns",size:ft},{code:54,name:"dns4",size:ft},{code:55,name:"dns6",size:ft},{code:56,name:"dnsaddr",size:ft},{code:132,name:"sctp",size:16,valueToBytes:Ae,bytesToValue:We,validate:Or},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ft,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ft,bytesToValue:Vs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?$s("base58btc")(e):ht.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:js,valueToBytes:_c},{code:445,name:"onion3",size:296,bytesToValue:js,valueToBytes:Ac},{code:446,name:"garlic64",size:ft},{code:447,name:"garlic32",size:ft},{code:448,name:"tls"},{code:449,name:"sni",size:ft},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ft,bytesToValue:Cc(yo),valueToBytes:Dc},{code:480,name:"http"},{code:481,name:"http-path",size:ft,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:ft}];rh.forEach(e=>{Gt.addProtocol(e)});function Oc(e){let t=[],r=0;for(;r<e.length;){let n=Er(e,r),o=Gt.getProtocol(n),s=Et(n),i=nh(o,e,r+s),a=0;i>0&&o.size===ft&&(a=Et(i));let c=s+a+i,u={code:n,name:o.name,bytes:Dt(e.subarray(r,r+c))};if(i>0){let l=r+s+a,d=e.subarray(l,l+i);u.value=o.bytesToValue?.(d)??it(d)}t.push(u),r+=c}return t}function Rc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Gt.getProtocol(n.code),s=Et(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Q(n.value),a=i.byteLength,o.size===ft&&(c=Et(a)));let u=new Uint8Array(s+c+a),l=0;Ke(n.code,u,l),l+=s,i!=null&&(o.size===ft&&(Ke(a,u,l),l+=c),u.set(i,l)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Nt(r,t)}function Pc(e){if(e.charAt(0)!=="/")throw new dt('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=Gt.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 dt(`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 dt(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new dt("Incomplete multiaddr");return t}function kc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Gt.getProtocol(t.code);if(r==null)throw new dt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function nh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Er(t,r)}var oh=Symbol.for("nodejs.util.inspect.custom"),Gs=Symbol.for("@multiformats/multiaddr");function sh(e){if(e==null&&(e="/"),Nc(e))return e.getComponents();if(e instanceof Uint8Array)return Oc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Pc(e);if(Array.isArray(e))return e;throw new dt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var zn=class e{[Gs]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=sh(t),r.validate!==!1&&ih(this)}get bytes(){return this.#r==null&&(this.#r=Rc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=kc(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 Fn(`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 lt(this.bytes,t.bytes)}[oh](){return`Multiaddr(${this.toString()})`}};function ih(e){e.getComponents().forEach(t=>{let r=Gt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Nc(e){return!!e?.[Gs]}function Fc(e){return new zn(e)}function Xe(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Kn=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}},Qe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Kn(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 Kn(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 Ws=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function qn(e={}){return ah(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 ah(e,t){t=t??{};let r=t.onEnd,n=new Qe,o,s,i,a=Xe(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((w,h)=>{s=y=>{s=null,n.push(y);try{w(e(n))}catch(g){h(g)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Xe()})}},u=w=>s!=null?s(w):(n.push(w),o),l=w=>(n=new Qe,s!=null?s({error:w}):(n.push({error:w}),o)),d=w=>{if(i)return o;if(t?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:w})},f=w=>i?o:(i=!0,w!=null?l(w):u({done:!0})),p=()=>(n=new Qe,f(),{done:!0}),v=w=>(f(w),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:v,push:d,end:f,get readableLength(){return n.size},onEmpty:async w=>{let h=w?.signal;if(h?.throwIfAborted(),n.isEmpty())return;let y,g;h!=null&&(y=new Promise((b,S)=>{g=()=>{S(new Ws)},h.addEventListener("abort",g)}));try{await Promise.race([a.promise,y])}finally{g!=null&&h!=null&&h?.removeEventListener("abort",g)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(w){return E.throw(w),r!=null&&(r(w),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(w){return E.end(w),r!=null&&(r(w),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:w=>E.onEmpty(w)},o}var Xs=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Uc=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Qs(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,l=new Promise((d,f)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){f(Uc(i)),e.then(d,f);return}if(i&&(c=()=>{f(Uc(i))},i.addEventListener("abort",c,{once:!0})),e.then(d,f),r===Number.POSITIVE_INFINITY)return;let p=new Xs;a=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(v){f(v)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?d():o instanceof Error?f(o):(p.message=o??`Promise timed out after ${r} milliseconds`,f(p))},r)}).finally(()=>{l.clear(),c&&i&&i.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},l}var Mc=e=>typeof e=="function"?{filter:e}:{...e},ch=e=>e===1/0||Number.isSafeInteger(e)&&e>=0,uh=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],fh=e=>{for(let[t,r]of uh){let n=e?.[t],o=e?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(e),removeListener:o.bind(e)}}throw new TypeError("Emitter is not compatible")},lh=e=>{let t=new Map;for(let[r,n]of e)for(let o of Array.isArray(r)?r:[r])t.has(o)||t.set(o,n);return t},dh=({addListener:e,removeListener:t,handlers:r,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of r)if(e(i,a),s()){t(i,a);return}},hh=({removeListener:e,handlers:t,signal:r,abortHandler:n})=>{for(let[o,s]of t)e(o,s);r?.removeEventListener("abort",n)},ph=(e,t,r)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(t())return;let i;try{i=e?await e(o):!0}catch(a){t()||r(a);return}t()||s(i)})}};function mh(e,t,r){let n=()=>{},o=!1,s,i=new Promise((a,c)=>{r=Mc(r);let{filter:u}=r;if(!ch(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:l,removeListener:d}=fh(e);if(r.count===0){a([]);return}let f=[],p=b=>{n(),c(b)},v=ph(u,()=>o,p),E=b=>{f.push(b),r.count===f.length&&(n(),a(f))},w=(...b)=>{if(o)return;let S=r.multiArgs?b:b[0];if(!u){E(S);return}v(S,I=>{I&&E(S)})},h=(...b)=>{p(r.rejectionMultiArgs?b:b[0])},y=()=>{p(r.signal.reason)},g={addListener:l,removeListener:d,handlers:lh([[t,w],[r.rejectionEvents??["error"],h]]),signal:r.signal,abortHandler:y,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),hh(g)},dh(g),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&(s=setTimeout(n,r.timeout)),a(f))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=Qs(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function Je(e,t,r){let n=mh(e,t,{...Mc(r),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Rr(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 Hn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Ie=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function gh(e){return e.reason}function Pr(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??gh;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 Vn=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=Xe(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new kt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function yh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var zc=new WeakMap,$n=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,r){this.id=yh(),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 kt),this.cleanup())}async join(t){let r=new Vn(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 Pr(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=zc.get(r);if(n==null&&(n=new WeakSet,zc.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 kt),t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var jn=class extends Ur{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=Rr(this.emitEmpty.bind(this),1),this.emitIdle=Rr(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 Hn;let n=new $n(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 kt)}),this.clear()}async onEmpty(t){this.size!==0&&await Je(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await Je(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Je(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=qn({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 kt("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 Zn(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 bh=4194304,Yn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ti=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ei=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ri=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function wh(e){return typeof e?.closeRead=="function"}function xh(e){return typeof e?.close=="function"}function Js(e){return wh(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:xh(e)?e.status!=="open":!1}function Eh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Sh(e,t){let r=t?.maxBufferSize??bh,n=new ut,o,s=!1,i;if(!Eh(e))throw new yt("Argument should be a Stream or a Multiaddr");let a=d=>{if(!s&&i==null){if(n.append(d.data),n.byteLength>r){let f=n.byteLength;n.consume(f);let p=new Nr(`Read buffer overflow - ${f} > ${r}`);i=p,o?.reject(p),queueMicrotask(()=>{e.abort(p)});return}o?.resolve()}};e.addEventListener("message",a);let c=d=>{d.error!=null?o?.reject(d.error):o?.resolve()};e.addEventListener("close",c);let u=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",u);let l={readBuffer:n,async read(d){if(s===!0)throw new Yn("Stream was unwrapped");if(i!=null)throw i;if(Js(e)){if(n.byteLength===0&&d?.bytes==null)return null;if(d?.bytes!=null&&n.byteLength<d.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new Ie(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let f=d?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await Pr(o.promise,d?.signal),Js(e)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let p=d?.bytes??n.byteLength;if(n.byteLength<p){if(Js(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Ie(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return l.read(d)}let v=n.sublist(0,p);return n.consume(p),v},async write(d,f){if(s===!0)throw new Yn("Stream was unwrapped");e.send(d)||await Je(e,"drain",{signal:f?.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 l}function vh(e,t={}){let r=Sh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Et(t.maxDataLength));let n=t?.lengthDecoder??Er,o=t?.lengthEncoder??Ua;return{async read(i){let a=-1,c=new ut;for(;;){let l=await r.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(d){if(d instanceof RangeError)continue;throw d}if(a<0)throw new ti("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ri(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ei(`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 Ie(`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 Ie(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new ut(o(i.byteLength),i),a)},async writeV(i,a){let c=new ut(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function ni(e,t){let r=vh(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 Gn=class extends jn{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function Kc(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal},l;r?.timeout!=null&&(l=Zn([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=l),s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{l!=null&&(l.aborted?l.clear():l.addEventListener("abort",()=>{l.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Rr(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 oi=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 qc(e){let{name:t,metrics:r}=e,n;return r!=null?n=new oi({name:t,metrics:r}):n=new Map,n}var Hc="libp2p",Vc="autonat",$c="1.0.0";var Y;(function(e){let t;(function(f){f.DIAL="DIAL",f.DIAL_RESPONSE="DIAL_RESPONSE"})(t=e.MessageType||(e.MessageType={}));let r;(function(f){f[f.DIAL=0]="DIAL",f[f.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(r||(r={})),(function(f){f.codec=()=>qe(r)})(t=e.MessageType||(e.MessageType={}));let n;(function(f){f.OK="OK",f.E_DIAL_ERROR="E_DIAL_ERROR",f.E_DIAL_REFUSED="E_DIAL_REFUSED",f.E_BAD_REQUEST="E_BAD_REQUEST",f.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=e.ResponseStatus||(e.ResponseStatus={}));let o;(function(f){f[f.OK=0]="OK",f[f.E_DIAL_ERROR=100]="E_DIAL_ERROR",f[f.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",f[f.E_BAD_REQUEST=200]="E_BAD_REQUEST",f[f.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(f){f.codec=()=>qe(o)})(n=e.ResponseStatus||(e.ResponseStatus={}));let s;(function(f){let p;f.codec=()=>(p==null&&(p=$t((h,y,g={})=>{if(g.lengthDelimited!==!1&&y.fork(),h.id!=null&&(y.uint32(10),y.bytes(h.id)),h.addrs!=null&&h.addrs.length>0)for(let b of h.addrs)y.uint32(18),y.bytes(b);g.lengthDelimited!==!1&&y.ldelim()},(h,y,g={})=>{let b={addrs:[]},S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();switch(I>>>3){case 1:{b.id=h.bytes();break}case 2:{if(g.limits?.addrs!=null&&b.addrs.length===g.limits.addrs)throw new Ar('Decode error - repeated field "addrs" had too many elements');b.addrs.push(h.bytes());break}default:{h.skipType(I&7);break}}}return b},function*(h,y,g,b={}){let S={addrs:0},I=y==null?h.len:h.pos+y;for(;h.pos<I;){let k=h.uint32();switch(k>>>3){case 1:{yield{field:`${g}.id`,value:h.bytes()};break}case 2:{if(b.limits?.addrs!=null&&S.addrs===b.limits.addrs)throw new Ar('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${g}.addrs[]`,index:S.addrs,value:h.bytes()},S.addrs++;break}default:{h.skipType(k&7);break}}}})),p);function v(h){return Ht(h,f.codec())}f.encode=v;function E(h,y){return qt(h,f.codec(),y)}f.decode=E;function w(h,y){return Vt(h,f.codec(),y)}f.stream=w})(s=e.PeerInfo||(e.PeerInfo={}));let i;(function(f){let p;f.codec=()=>(p==null&&(p=$t((h,y,g={})=>{g.lengthDelimited!==!1&&y.fork(),h.peer!=null&&(y.uint32(10),e.PeerInfo.codec().encode(h.peer,y)),g.lengthDelimited!==!1&&y.ldelim()},(h,y,g={})=>{let b={},S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();I>>>3===1?b.peer=e.PeerInfo.codec().decode(h,h.uint32(),{limits:g.limits?.peer}):h.skipType(I&7)}return b},function*(h,y,g,b={}){let S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();I>>>3===1?yield*e.PeerInfo.codec().stream(h,h.uint32(),`${g}.peer`,{limits:b.limits?.peer}):h.skipType(I&7)}})),p);function v(h){return Ht(h,f.codec())}f.encode=v;function E(h,y){return qt(h,f.codec(),y)}f.decode=E;function w(h,y){return Vt(h,f.codec(),y)}f.stream=w})(i=e.Dial||(e.Dial={}));let a;(function(f){let p;f.codec=()=>(p==null&&(p=$t((h,y,g={})=>{g.lengthDelimited!==!1&&y.fork(),h.status!=null&&(y.uint32(8),e.ResponseStatus.codec().encode(h.status,y)),h.statusText!=null&&(y.uint32(18),y.string(h.statusText)),h.addr!=null&&(y.uint32(26),y.bytes(h.addr)),g.lengthDelimited!==!1&&y.ldelim()},(h,y,g={})=>{let b={},S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();switch(I>>>3){case 1:{b.status=e.ResponseStatus.codec().decode(h);break}case 2:{b.statusText=h.string();break}case 3:{b.addr=h.bytes();break}default:{h.skipType(I&7);break}}}return b},function*(h,y,g,b={}){let S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();switch(I>>>3){case 1:{yield{field:`${g}.status`,value:e.ResponseStatus.codec().decode(h)};break}case 2:{yield{field:`${g}.statusText`,value:h.string()};break}case 3:{yield{field:`${g}.addr`,value:h.bytes()};break}default:{h.skipType(I&7);break}}}})),p);function v(h){return Ht(h,f.codec())}f.encode=v;function E(h,y){return qt(h,f.codec(),y)}f.decode=E;function w(h,y){return Vt(h,f.codec(),y)}f.stream=w})(a=e.DialResponse||(e.DialResponse={}));let c;e.codec=()=>(c==null&&(c=$t((f,p,v={})=>{v.lengthDelimited!==!1&&p.fork(),f.type!=null&&(p.uint32(8),e.MessageType.codec().encode(f.type,p)),f.dial!=null&&(p.uint32(18),e.Dial.codec().encode(f.dial,p)),f.dialResponse!=null&&(p.uint32(26),e.DialResponse.codec().encode(f.dialResponse,p)),v.lengthDelimited!==!1&&p.ldelim()},(f,p,v={})=>{let E={},w=p==null?f.len:f.pos+p;for(;f.pos<w;){let h=f.uint32();switch(h>>>3){case 1:{E.type=e.MessageType.codec().decode(f);break}case 2:{E.dial=e.Dial.codec().decode(f,f.uint32(),{limits:v.limits?.dial});break}case 3:{E.dialResponse=e.DialResponse.codec().decode(f,f.uint32(),{limits:v.limits?.dialResponse});break}default:{f.skipType(h&7);break}}}return E},function*(f,p,v,E={}){let w=p==null?f.len:f.pos+p;for(;f.pos<w;){let h=f.uint32();switch(h>>>3){case 1:{yield{field:`${v}.type`,value:e.MessageType.codec().decode(f)};break}case 2:{yield*e.Dial.codec().stream(f,f.uint32(),`${v}.dial`,{limits:E.limits?.dial});break}case 3:{yield*e.DialResponse.codec().stream(f,f.uint32(),`${v}.dialResponse`,{limits:E.limits?.dialResponse});break}default:{f.skipType(h&7);break}}}})),c);function u(f){return Ht(f,e.codec())}e.encode=u;function l(f,p){return qt(f,e.codec(),p)}e.decode=l;function d(f,p){return Vt(f,e.codec(),p)}e.stream=d})(Y||(Y={}));var Lh=4,Dh=8,Wn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${r.protocolPrefix??Hc}/${Vc}/${$c}`,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=qc({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=Kc(this.findRandomPeers.bind(this),6e4),this.addressFilter=Cs(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ci]=["@libp2p/autonat"];get[ui](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,r)=>{this.handleIncomingAutonatStream(t,r).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,r)=>{this.verifyExternalAddresses(r).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let r=Zn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:r})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:r})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,r){let n=AbortSignal.timeout(this.timeout);try{let o=ni(t,{maxDataLength:this.maxMessageSize}).pb(Y),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,r,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,r,n){let o=this.components.addressManager.getAddresses().map(d=>Pt(d).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("peerId missing from message"),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let d=fe(a.id);i=Tn(d)}catch(d){return this.log.error("invalid PeerId - %e",d),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!r.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,r.remotePeer),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(d=>Fc(d)).filter(d=>{try{let f=Pt(d);return qs(d)?!1:f.host!==Pt(r.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",d,r.remoteAddr),!1):o.includes(f.host)?!1:this.components.transportManager.dialTransportForMultiaddr(d)==null?(this.log.trace("not dialing %a - transport unsupported",d),!1):!0}catch{return!1}}).map(d=>(d.getComponents().find(f=>f.code===421)?.value==null&&(d=d.encapsulate(`/p2p/${i.toString()}`)),d));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(d=>d.toString()).join(", "),i);let u="",l=c[0];for(let d of c){let f;l=d;try{if(f=await this.components.connectionManager.openConnection(d,n),!f.remoteAddr.equals(d))throw this.log.error("tried to dial %a but dialed %a",d,f.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,d),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.OK,addr:f.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),u=p.message}finally{f!=null&&await f.close()}}return{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:l.bytes}}}getFirstUnverifiedMultiaddr(t,r){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||Pt(o.multiaddr).type==="ip6"&&(!r||!bc(o.multiaddr))||qs(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:Bs(),queue:new Gn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>Pt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,r,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=ni(i).pb(Y),[,c]=await Promise.all([a.write({type:Y.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==Y.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let u=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==Y.ResponseStatus.OK&&u!==Y.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(r)){this.log.trace("%a results included network segment %s",n.multiaddr,r);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(r),u===Y.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===Y.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Lh&&this.confirmAddress(o),o.failure===Dh&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}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,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let r=Pt(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`)}}};function Ch(e={}){return t=>new Wn(t,e)}return eu(Oh);})();
|
|
2
|
+
"use strict";var Libp2PAutonat=(()=>{var jn=Object.defineProperty;var Cc=Object.getOwnPropertyDescriptor;var Rc=Object.getOwnPropertyNames;var Oc=Object.prototype.hasOwnProperty;var St=(r,t)=>{for(var e in t)jn(r,e,{get:t[e],enumerable:!0})},Pc=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Rc(t))!Oc.call(r,o)&&o!==e&&jn(r,o,{get:()=>t[o],enumerable:!(n=Cc(t,o))||n.enumerable});return r};var Nc=r=>Pc(jn({},"__esModule",{value:!0}),r);var rh={};St(rh,{autoNAT:()=>eh});var Nt=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"}},We=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Dr=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Lr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Xe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var $n=Symbol.for("@libp2p/peer-id");function kc(r){return typeof r?.handleEvent=="function"}function Uc(r){return r===!0||r===!1}function Fc(r){return Uc(r)?r:r?.capture??!1}function Zn(r){let t={capture:Fc(r),once:!!r?.once};return r?.passive!=null&&(t.passive=r?.passive),r?.signal!=null&&(t.signal=r?.signal),t}function Ys(r,t){return Zn(r).capture===Zn(t).capture}var Cr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){let o=Zn(n);if(o?.signal?.aborted===!0)return;let s=u=>{o.once&&this.removeEventListener(t,e,o),kc(e)?e.handleEvent(u):e(u)},i=this.#t.get(t);if(i==null&&(i=[],this.#t.set(t,i)),i.some(u=>u.callback!==e?!1:Ys(u.options,o)))return;super.addEventListener(t,s,o);let c=()=>{this.removeEventListener(t,e,o)};o.signal?.addEventListener("abort",c),i.push({callback:e,wrapper:s,options:o,onAbort:c})}removeEventListener(t,e,n){let o=this.#t.get(t);if(o==null){super.removeEventListener(t,e??null,n);return}this.#t.set(t,o.filter(s=>s.callback===e&&Ys(s.options,n)?(super.removeEventListener(t,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Gs=Symbol.for("@libp2p/service-capabilities"),Ws=Symbol.for("@libp2p/service-dependencies");function lt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Qn={};St(Qn,{base58btc:()=>st,base58flickr:()=>$c});var Oh=new Uint8Array(0);function Qs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function At(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ce(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ce(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Js(r){let t=new Uint8Array(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}var Xs=4096;function ti(r){let t=r.length;if(t<=Xs)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.subarray(n,n+=Xs));return e}function Mc(r){return r?.buffer instanceof ArrayBuffer}function ce(r){return Mc(r)?r:r.slice()}function Kc(r,t,e){if(r.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<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,e){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var l=r.length,d=r.charAt(0),f=Math.log(l)/Math.log(256),p=Math.log(256)/Math.log(l);function v(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var y=0,g=0,w=0,S=h.length;w!==S&&h[w]===0;)w++,y++;for(var I=(S-w)*p+1>>>0,U=new Uint8Array(I);w!==S;){for(var R=h[w],C=0,P=I-1;(R!==0||C<g)&&P!==-1;P--,C++)R+=256*U[P]>>>0,U[P]=R%l>>>0,R=R/l>>>0;if(R!==0)throw new Error("Non-zero carry");g=C,w++}for(var M=I-g;M!==I&&U[M]===0;)M++;for(var z=d.repeat(y);M<I;++M)z+=r.charAt(U[M]);return z}function x(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var y=0;if(h[y]!==" "){for(var g=0,w=0;h[y]===d;)g++,y++;for(var S=(h.length-y)*f+1>>>0,I=new Uint8Array(S);h[y];){var U=h.charCodeAt(y);if(U>255)return;var R=n[U];if(R===255)return;for(var C=0,P=S-1;(R!==0||C<w)&&P!==-1;P--,C++)R+=l*I[P]>>>0,I[P]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");w=C,y++}if(h[y]!==" "){for(var M=S-w;M!==S&&I[M]===0;)M++;for(var z=new Uint8Array(g+(S-M)),Z=g;M!==S;)z[Z++]=I[M++];return z}}}function b(h){var y=x(h);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:v,decodeUnsafe:x,decode:b}}var zc=Kc,qc=zc,ri=qc;var Yn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Gn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ni(this,t)}},Wn=class{decoders;constructor(t){this.decoders=t}or(t){return ni(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ni(r,t){return new Wn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Xn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Yn(t,e,n),this.decoder=new Gn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ie({name:r,prefix:t,encode:e,decode:n}){return new Xn(r,t,e,n)}function Gt({name:r,prefix:t,alphabet:e,caseInsensitive:n=!1}){let{encode:o,decode:s}=ri(e,r,n);return Ie({prefix:t,name:r,encode:o,decode:i=>At(s(i))})}function Hc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Vc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function jc(r,t){let e={};for(let n=0;n<r.length;++n)if(e[r[n]]=n,t){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(e[o]=n),s!==r[n]&&(e[s]=n)}return e}function rt({name:r,prefix:t,bitsPerChar:e,alphabet:n,caseInsensitive:o=!1}){let s=jc(n,o);return Ie({prefix:t,name:r,encode(i){return Vc(i,n,e)},decode(i){return Hc(i,s,e,r)}})}var st=Gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$c=Gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Jn={};St(Jn,{base32:()=>Wt,base32hex:()=>Wc,base32hexpad:()=>Qc,base32hexpadupper:()=>Jc,base32hexupper:()=>Xc,base32pad:()=>Yc,base32padupper:()=>Gc,base32upper:()=>Zc,base32z:()=>tu});var Wt=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Zc=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Yc=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Gc=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Wc=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Xc=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Qc=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Jc=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),tu=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var to={};St(to,{base36:()=>Qe,base36upper:()=>eu});var Qe=Gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),eu=Gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var ru=ii,oi=128,nu=127,ou=~nu,su=Math.pow(2,31);function ii(r,t,e){t=t||[],e=e||0;for(var n=e;r>=su;)t[e++]=r&255|oi,r/=128;for(;r&ou;)t[e++]=r&255|oi,r>>>=7;return t[e]=r|0,ii.bytes=e-n+1,t}var iu=eo,au=128,si=127;function eo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw eo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&si)<<o:(i&si)*Math.pow(2,o),o+=7}while(i>=au);return eo.bytes=s-n,e}var cu=Math.pow(2,7),uu=Math.pow(2,14),fu=Math.pow(2,21),lu=Math.pow(2,28),du=Math.pow(2,35),hu=Math.pow(2,42),pu=Math.pow(2,49),mu=Math.pow(2,56),gu=Math.pow(2,63),yu=function(r){return r<cu?1:r<uu?2:r<fu?3:r<lu?4:r<du?5:r<hu?6:r<pu?7:r<mu?8:r<gu?9:10},bu={encode:ru,decode:iu,encodingLength:yu},wu=bu,Je=wu;function tr(r,t=0){let e=Je.decode(r,t),n=Je.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[e,n]}function Be(r,t,e=0){return Je.encode(r,t,e),t}function Te(r){return Je.encodingLength(r)}function Le(r,t){let e=t.byteLength,n=Te(r),o=n+Te(e),s=new Uint8Array(o+e);return Be(r,s,0),Be(e,s,n),s.set(t,o),new De(r,e,t,s)}function ue(r){let t=At(r),[e,n]=tr(t),[o,s]=tr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new De(e,o,i,t)}function ai(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Qs(r.bytes,e.bytes)}}var De=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=ce(n),this.bytes=ce(o)}};function ci(r,t){let{bytes:e,version:n}=r;return n===0?Eu(e,ro(r),t??st.encoder):Su(e,ro(r),t??Wt.encoder)}var ui=new WeakMap;function ro(r){let t=ui.get(r);if(t==null){let e=new Map;return ui.set(r,e),e}return t}var ht=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=ce(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:e}=this;if(t!==er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==vu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Le(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ai(t.multihash,n.multihash)}toString(t){return ci(this,t)}toJSON(){return{"/":ci(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??fi(n,o,s.bytes))}else if(e[_u]===!0){let{version:n,multihash:o,code:s}=e,i=ue(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==er)throw new Error(`Version 0 CID must use dag-pb (code: ${er}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=fi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,er,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=At(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new De(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[d,f]=tr(t.subarray(e));return e+=f,d},o=n(),s=er;if(o===18)o=0,e=0;else if(o===1)s=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=xu(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ro(s).set(n,t),s}};function xu(r,t){switch(r[0]){case"Q":{let e=t??st;return[st.prefix,e.decode(`${st.prefix}${r}`)]}case st.prefix:{let e=t??st;return[st.prefix,e.decode(r)]}case Wt.prefix:{let e=t??Wt;return[Wt.prefix,e.decode(r)]}case Qe.prefix:{let e=t??Qe;return[Qe.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Eu(r,t,e){let{prefix:n}=e;if(n!==st.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Su(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var er=112,vu=18;function fi(r,t,e){let n=Te(r),o=n+Te(t),s=new Uint8Array(o+e.byteLength);return Be(r,s,0),Be(t,s,n),s.set(e,o),s}var _u=Symbol.for("@ipld/js-cid/CID");var no={};St(no,{identity:()=>Dt});var li=0,Au="identity",di=At;function Iu(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Le(li,di(r))}var Dt={code:li,name:Au,encode:di,digest:Iu};function Bu(r){return r.buffer instanceof ArrayBuffer}function Lt(r){return Bu(r)?r:r.slice()}async function hi(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Lt(t),Lt(e.subarray()));return n?.signal?.throwIfAborted(),s}function It(r=0){return new Uint8Array(r)}function pt(r=0){return new Uint8Array(r)}function Tu(r){return r?.buffer instanceof ArrayBuffer}function oo(r){if(Tu(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function kt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=pt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return oo(e)}var mi=Symbol.for("@achingbrain/uint8arraylist");function pi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Or(r){return!!r?.[mi]}var ut=class r{bufs;length;[mi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Or(n)){e+=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+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Or(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=pi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=pi(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Or(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return kt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:kt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let d=t-a;n.push(i.subarray(d,d+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Or(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=e;d<=c;d+=l){l=0;for(let f=u;f>=0;f--){let p=this.get(d+f);if(n[f]!==p){l=Math.max(1,f-a[p]);break}}if(l===0)return d}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=It(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=It(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=It(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=It(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=It(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=It(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!lt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var so={};St(so,{base10:()=>Du});var Du=Gt({prefix:"9",name:"base10",alphabet:"0123456789"});var io={};St(io,{base16:()=>Lu,base16upper:()=>Cu});var Lu=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Cu=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ao={};St(ao,{base2:()=>Ru});var Ru=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var co={};St(co,{base256emoji:()=>Uu});var gi=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}"),Ou=gi.reduce((r,t,e)=>(r[e]=t,r),[]),Pu=gi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Nu(r){return r.reduce((t,e)=>(t+=Ou[e],t),"")}function ku(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Pu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Uu=Ie({prefix:"\u{1F680}",name:"base256emoji",encode:Nu,decode:ku});var fo={};St(fo,{base64:()=>Fu,base64pad:()=>Mu,base64url:()=>uo,base64urlpad:()=>Ku});var Fu=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mu=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),uo=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ku=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var lo={};St(lo,{base8:()=>zu});var zu=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ho={};St(ho,{identity:()=>qu});var qu=Ie({prefix:"\0",name:"identity",encode:r=>ti(At(r)),decode:r=>At(Js(r))});var yp=new TextEncoder,bp=new TextDecoder;var go={};St(go,{sha256:()=>rr,sha512:()=>$u});var ju=20;function mo({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new po(r,t,e,n,o)}var po=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??ju,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?yi(n,this.code,e?.truncate):n.then(o=>yi(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function yi(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Le(t,r)}function wi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var rr=mo({name:"sha2-256",code:18,encode:wi("SHA-256")}),$u=mo({name:"sha2-512",code:19,encode:wi("SHA-512")});var nr={...ho,...ao,...lo,...so,...io,...Jn,...to,...Qn,...fo,...co},Lp={...go,...no};function Ei(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var xi=Ei("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),yo=Ei("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=pt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Zu={utf8:xi,"utf-8":xi,hex:nr.base16,latin1:yo,ascii:yo,binary:yo,...nr},Pr=Zu;function Q(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function it(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Yu=parseInt("11111",2),bo=parseInt("10000000",2),Gu=parseInt("01111111",2),Si={0:or,1:or,2:Wu,3:Ju,4:tf,5:Qu,6:Xu,16:or,22:or,48:or};function wo(r,t={offset:0}){let e=r[t.offset]&Yu;if(t.offset++,Si[e]!=null)return Si[e](r,t);throw new Error("No decoder for tag "+e)}function sr(r,t){let e=0;if((r[t.offset]&bo)===bo){let n=r[t.offset]&Gu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=r.byteLength)throw new Error("invalid DER element length");o+=r[t.offset].toString(16).padStart(2,"0")}e=parseInt(o,16)}else e=r[t.offset],t.offset++;if(!Number.isInteger(e)||e<0||e>r.byteLength-t.offset)throw new Error("invalid DER element length");return e}function or(r,t){sr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=wo(r,t);if(n===null)break;e.push(n)}return e}function Wu(r,t){let e=sr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Xu(r,t){let e=sr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let d=0;d<c.length;d++)l+=c[d]<<d*7;a+=`.${l}`,c=[]}}return a}function Qu(r,t){return t.offset++,null}function Ju(r,t){let e=sr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function tf(r,t){let e=sr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function ef(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ut;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function xo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=ef(r.byteLength);return new ut(Uint8Array.from([t.byteLength|bo]),t)}function vi(r){let t=new ut,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ut(Uint8Array.from([2]),xo(t),t)}function _i(r){let t=Uint8Array.from([0]),e=new ut(t,r);return new ut(Uint8Array.from([3]),xo(e),e)}function Nr(r,t=48){let e=new ut;for(let n of r)e.append(n);return new ut(Uint8Array.from([t]),xo(e),e)}var rf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),nf=Uint8Array.from([6,5,43,129,4,0,34]),of=Uint8Array.from([6,5,43,129,4,0,35]),sf={ext:!0,kty:"EC",crv:"P-256"},af={ext:!0,kty:"EC",crv:"P-384"},cf={ext:!0,kty:"EC",crv:"P-521"},Eo=32,So=48,vo=66;function Ai(r){let t=wo(r);return Ii(t)}function Ii(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Eo*2+1)return n=it(t.subarray(e,e+Eo),"base64url"),o=it(t.subarray(e+Eo),"base64url"),new Ce({...sf,key_ops:["verify"],x:n,y:o});if(t.byteLength===So*2+1)return n=it(t.subarray(e,e+So),"base64url"),o=it(t.subarray(e+So),"base64url"),new Ce({...af,key_ops:["verify"],x:n,y:o});if(t.byteLength===vo*2+1)return n=it(t.subarray(e,e+vo),"base64url"),o=it(t.subarray(e+vo),"base64url"),new Ce({...cf,key_ops:["verify"],x:n,y:o});throw new yt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Bi(r){return Nr([vi(Uint8Array.from([1])),Nr([uf(r.crv)],160),Nr([_i(new ut(Uint8Array.from([4]),Q(r.x??"","base64url"),Q(r.y??"","base64url")))],161)]).subarray()}function uf(r){if(r==="P-256")return rf;if(r==="P-384")return nf;if(r==="P-521")return of;throw new yt(`Invalid curve ${r}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Bi(this.jwk)),this._raw}toMultihash(){return Dt.digest(Re(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,e,n){return hi(this.jwk,e,t,n)}};var kr=BigInt(4294967295),Ti=BigInt(32);function ff(r,t=!1){return t?{h:Number(r&kr),l:Number(r>>Ti&kr)}:{h:Number(r>>Ti&kr)|0,l:Number(r&kr)|0}}function Di(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=ff(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var lf=r=>r/2**32|0,df=r=>r>>>0;function Li(r,t,e,n){let o=lf(e),s=df(e);r.setUint32(t,n?s:o,n),r.setUint32(t+4,n?o:s,n)}var _o=(r,t,e)=>r>>>e,Ao=(r,t,e)=>r<<32-e|t>>>e,fe=(r,t,e)=>r>>>e|t<<32-e,le=(r,t,e)=>r<<32-e|t>>>e,ir=(r,t,e)=>r<<64-e|t>>>e-32,ar=(r,t,e)=>r>>>e-32|t<<64-e;function Ut(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ci=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ri=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Oi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Pi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ni=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ki=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;function Ur(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}var Io=r=>r?`"${r}" `:"";function Mt(r,t=""){if(typeof r!="number")throw new TypeError(Io(t)+"expected number, got "+typeof r);if(!Number.isSafeInteger(r)||r<0)throw new RangeError(Io(t)+"expected integer >= 0, got "+r);return r}function Bt(r,t,e=""){if(Ur(r)&&(t===void 0||r.length===t))return r;t!==void 0&&Mt(t,"length");let n=Ur(r),o=t!==void 0?` of length ${t}`:"",s=n?`length=${r.length}`:`type=${typeof r}`,i=Io(e)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function Fr(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Mt(r.outputLen),Mt(r.blockLen),r.outputLen<1||r.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var pf=(r,t)=>{if(r===null||typeof r!="object"||Array.isArray(r))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof r)},Ui=(r,t)=>{pf(r,t);let e=Object.getPrototypeOf(r);if(e!==Object.prototype&&e!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(r,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function Oe(r,t=!0){if(r.destroyed)throw new Error("hash was destroyed");if(t&&r.finished)throw new Error("digest() was already called")}function Mr(r,t){Bt(r,void 0,"output");let e=t.outputLen;if(!(r.length>=e))throw new RangeError('"output" expected length >= '+e)}function de(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Kr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ct(r,t){return r<<32-t|r>>>t}var Mi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",mf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function zr(r){if(Bt(r),Mi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=mf[r[e]];return t}function Fi(r){return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void 0}function qr(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(Mi)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Fi(r.charCodeAt(s)),a=Fi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Bo(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Bt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function gf(r,t,e="opts"){return Ui(r,"defaults"),t!==void 0&&Ui(t,e),Object.assign(Object.create(null),r,t)}function To(r,t={}){if(typeof r!="function")throw new TypeError('"hashCons" expected function, got type='+typeof r);t=gf({},t,"info");let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function Ki(r=32){Mt(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var Do=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function zi(r,t,e){return r&t^~r&e}function qi(r,t,e){return r&t^r&e^t&e}var cr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Kr(this.buffer)}update(t){Oe(this),Bt(t);let{view:e,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=Kr(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(e,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){Oe(this),Mr(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,e.fill(0,i),this.padOffset>o-i&&(this.process(n,0),e.fill(0)),Li(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===e?n:Kr(t),c=this.outputLen,u=c/4,l=this.get();if(c%4||u>l.length)throw new Error("invalid outputLen");for(let d=0;d<u;d++)a.setUint32(4*d,l[d],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:e,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(e),t}clone(){return this._cloneInto()}},Hi=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Vi=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var yf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Qt=new Uint32Array(64),Lo=class extends cr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,e){super(64,t,8,!1),this.A=e[0]|0,this.B=e[1]|0,this.C=e[2]|0,this.D=e[3]|0,this.E=e[4]|0,this.F=e[5]|0,this.G=e[6]|0,this.H=e[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,e){for(let d=0;d<16;d++,e+=4)Qt[d]=t.getUint32(e,!1);for(let d=16;d<64;d++){let f=Qt[d-15],p=Qt[d-2],v=Ct(f,7)^Ct(f,18)^f>>>3,x=Ct(p,17)^Ct(p,19)^p>>>10;Qt[d]=x+Qt[d-7]+v+Qt[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let d=0;d<64;d++){let f=Ct(a,6)^Ct(a,11)^Ct(a,25),p=l+f+zi(a,c,u)+yf[d]+Qt[d]|0,x=(Ct(n,2)^Ct(n,13)^Ct(n,22))+qi(n,o,s)|0;l=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){de(Qt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),de(this.buffer)}},Co=class extends Lo{constructor(){super(32,Hi)}};var ji=Di(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),bf=ji[0],wf=ji[1],Jt=new Uint32Array(80),te=new Uint32Array(80),Ro=class extends cr{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,e){super(128,t,16,!1),this.Ah=e[0]|0,this.Al=e[1]|0,this.Bh=e[2]|0,this.Bl=e[3]|0,this.Ch=e[4]|0,this.Cl=e[5]|0,this.Dh=e[6]|0,this.Dl=e[7]|0,this.Eh=e[8]|0,this.El=e[9]|0,this.Fh=e[10]|0,this.Fl=e[11]|0,this.Gh=e[12]|0,this.Gl=e[13]|0,this.Hh=e[14]|0,this.Hl=e[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:d,Fl:f,Gh:p,Gl:v,Hh:x,Hl:b}=this;return[t,e,n,o,s,i,a,c,u,l,d,f,p,v,x,b]}set(t,e,n,o,s,i,a,c,u,l,d,f,p,v,x,b){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=d|0,this.Fl=f|0,this.Gh=p|0,this.Gl=v|0,this.Hh=x|0,this.Hl=b|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,e){for(let g=0;g<16;g++,e+=4)Jt[g]=t.getUint32(e),te[g]=t.getUint32(e+=4);for(let g=16;g<80;g++){let w=Jt[g-15]|0,S=te[g-15]|0,I=fe(w,S,1)^fe(w,S,8)^_o(w,S,7),U=le(w,S,1)^le(w,S,8)^Ao(w,S,7),R=Jt[g-2]|0,C=te[g-2]|0,P=fe(R,C,19)^ir(R,C,61)^_o(R,C,6),M=le(R,C,19)^ar(R,C,61)^Ao(R,C,6),z=Oi(U,M,te[g-7],te[g-16]),Z=Pi(z,I,P,Jt[g-7],Jt[g-16]);Jt[g]=Z|0,te[g]=z|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:d,El:f,Fh:p,Fl:v,Gh:x,Gl:b,Hh:h,Hl:y}=this;for(let g=0;g<80;g++){let w=fe(d,f,14)^fe(d,f,18)^ir(d,f,41),S=le(d,f,14)^le(d,f,18)^ar(d,f,41),I=d&p^~d&x,U=f&v^~f&b,R=Ni(y,S,U,wf[g],te[g]),C=ki(R,h,w,I,bf[g],Jt[g]),P=R|0,M=fe(n,o,28)^ir(n,o,34)^ir(n,o,39),z=le(n,o,28)^ar(n,o,34)^ar(n,o,39),Z=n&s^n&a^s&a,T=o&i^o&c^i&c;h=x|0,y=b|0,x=p|0,b=v|0,p=d|0,v=f|0,{h:d,l:f}=Ut(u|0,l|0,C|0,P|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let F=Ci(P,z,T);n=Ri(F,C,M,Z),o=F|0}({h:n,l:o}=Ut(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ut(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ut(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Ut(this.Dh|0,this.Dl|0,u|0,l|0),{h:d,l:f}=Ut(this.Eh|0,this.El|0,d|0,f|0),{h:p,l:v}=Ut(this.Fh|0,this.Fl|0,p|0,v|0),{h:x,l:b}=Ut(this.Gh|0,this.Gl|0,x|0,b|0),{h,l:y}=Ut(this.Hh|0,this.Hl|0,h|0,y|0),this.set(n,o,s,i,a,c,u,l,d,f,p,v,x,b,h,y)}roundClean(){de(Jt,te)}destroy(){this.destroyed=!0,de(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Oo=class extends Ro{constructor(){super(64,Vi)}};var $i=To(()=>new Co,Do(1));var Po=To(()=>new Oo,Do(3));function Vr(r,t,e=()=>{}){if(!Array.isArray(r))throw new TypeError(`"${t}" expected array, got type=${typeof r}`);for(let n=0;n<r.length;n++)e(r[n],`${t}[${n}]`);return r}var V=(r,t,e)=>Bt(r,t,e),No=Mt;function Yi(r,t=""){if(typeof r!="string"){let e=t&&`"${t}" `;throw new TypeError(e+"expected string, got type="+typeof r)}return r}function ee(r,t="object"){if(r===null||typeof r!="object"||Array.isArray(r))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof r}`);return r}function he(r,t){if(typeof r!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof r}`);return r}var ur=zr,Tt=(...r)=>Bo(...r),Pe=r=>qr(r),ne=Ur,pe=r=>Ki(r),Hr=BigInt(0),Zi=BigInt(1),xf=r=>r?`"${r}" `:"";function wt(r,t=""){if(typeof r!="boolean")throw new TypeError(xf(t)+"expected boolean, got type="+typeof r);return r}function jr(r){if(typeof r=="bigint"){if(!re(r))throw new RangeError("positive bigint expected, got "+r)}else No(r);return r}function Kt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+r)}}function fr(r){let t=jr(r).toString(16);return t.length&1?"0"+t:t}function Gi(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?Hr:BigInt("0x"+r)}function Ft(r){return Gi(zr(r))}function me(r){return Gi(zr(lr(Bt(r)).reverse()))}function $r(r,t){if(Mt(t),t===0)throw new Error("zero output length is invalid");r=jr(r);let e=t*2,n=r.toString(16);if(n.length>e)throw new RangeError("number is too large");return qr(n.padStart(e,"0"))}function ko(r,t){return $r(r,t).reverse()}function lr(r){return Uint8Array.from(V(r))}function re(r){return typeof r=="bigint"&&Hr<=r}function Uo(r,t,e){return re(r)&&re(t)&&re(e)&&t<=r&&r<e}function Ne(r,t,e,n){if(!Uo(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ke(r){if(r<Hr)throw new Error("expected non-negative bigint, got "+r);return r===Hr?0:r.toString(2).length}var dr=r=>(Kt(r,"n"),(Zi<<BigInt(r))-Zi);function Wi(r,t,e){if(Mt(r,"hashLen"),Mt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),l=0,d=()=>{c.fill(1),u.fill(0),l=0},f=(...b)=>e(u,Tt(c,...b)),p=(b=o)=>{u=f(s,b),c=f(),b.length!==0&&(u=f(i,b),c=f())},v=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let b=0,h=[];for(;b<t;){c=f();let y=c.slice();h.push(y),b+=c.length}return Tt(...h)};return(b,h)=>{d(),p(b);let y;for(;(y=h(v()))===void 0;)p();return d(),y}}function xt(r,t={},e={},n="object"){ee(r,n),ee(t,"fields"),ee(e,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,l=r[i];if(!Object.hasOwn(r,i)&&(c?l!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&l===void 0)return;let d=typeof l;if(d!==a||l===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${d}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(e,!0)}var at=BigInt(0),j=BigInt(1),oe=BigInt(2),Ji=BigInt(3),Fo=BigInt(4),ta=BigInt(5),Ef=BigInt(7),ea=BigInt(8),Sf=BigInt(9),vf=BigInt(15),ra=BigInt(16),_f=BigInt("0x10000000000000000");function et(r,t){if(t<=at)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=at?e:t+e}function na(r,t,e){if(e<=j)throw new Error("pow: expected modulus > 1, got "+e);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<at)throw new Error("invalid exponent, negatives unsupported");if(t===at)return j;if(t===j)return r;let n=r%e;if(n<at&&(n+=e),t<_f){let a=j;for(;t>at;)t&j&&(a=a*n%e),n=n*n%e,t>>=j;return a}let o=[];for(;t>at;)o.push(Number(t&vf)),t>>=Fo;let s=new Array(16);s[0]=j,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%e;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%e,i=i*i%e,i=i*i%e,i=i*i%e;let c=o[a];c!==0&&(i=i*s[c]%e)}return i}function J(r,t,e){if(e<=j)throw new Error("pow2: expected modulus > 1, got "+e);if(t<at)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >at;)n*=n,n%=e;return n}function Xi(r,t){if(r===at)throw new Error("invert: expected non-zero number");if(t<=j)throw new Error("invert: expected modulus > 1, got "+t);let e=et(r,t),n=t,o=at,s=j;for(;e!==at;){let a=n/e,c=n-e*a,u=o-s*a;n=e,e=c,o=s,s=u}if(n!==j)throw new Error("invert: does not exist");return et(o,t)}function oa(r,t){if(t<=j)throw new Error("invertCt: expected prime modulus > 1, got "+t);let e=et(r,t);if(e===at)throw new Error("invertCt: expected non-zero number");let n=na(e,t-oe,t);if(et(e*n,t)!==j)throw new Error("invertCt: does not exist");return n}function Mo(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Ko(r,t){if((r&j)===at)throw new Error(t+": expected odd modulus, got "+r)}function sa(r,t){let e=r,n=(e.ORDER+j)/Fo,o=e.pow(t,n);return Mo(e,o,t),o}function Af(r,t){let e=r,n=(e.ORDER-ta)/ea,o=e.mul(t,oe),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,oe),s),c=e.mul(i,e.sub(a,e.ONE));return Mo(e,c,t),c}function If(r){let t=Fe(r),e=ia(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Ef)/ra;return((a,c)=>{let u=a,l=u.pow(c,i),d=u.mul(l,n),f=u.mul(l,o),p=u.mul(l,s),v=u.eql(u.sqr(d),c),x=u.eql(u.sqr(f),c);l=u.cmov(l,d,v),d=u.cmov(p,f,x);let b=u.eql(u.sqr(d),c),h=u.cmov(l,d,b);return Mo(u,h,c),h})}function ia(r){if(r<Ji)throw new Error("sqrt is not defined for small field");Ko(r,"tonelliShanks");let t=r-j,e=0;for(;t%oe===at;)t/=oe,e++;let n=oe,o=Fe(r);for(;hr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return sa;let s=o.pow(n,t),i=(t+j)/oe;return function(c,u){let l=c;if(l.is0(u))return u;if(hr(l,u)!==1)throw new Error("Cannot find square root");let d=e,f=l.mul(l.ONE,s),p=l.pow(u,t),v=l.pow(u,i);for(;!l.eql(p,l.ONE);){if(l.is0(p))throw new Error("Cannot find square root: probably non-prime P");let x=1,b=l.sqr(p);for(;!l.eql(b,l.ONE);)if(x++,b=l.sqr(b),x===d)throw new Error("Cannot find square root");let h=j<<BigInt(d-x-1),y=l.pow(f,h);d=x,f=l.sqr(y),p=l.mul(p,f),v=l.mul(v,y)}return v}}function Bf(r){return Ko(r,"Fp.sqrt"),r%Fo===Ji?sa:r%ea===ta?Af:r%ra===Sf?If(r):ia(r)}var aa=(r,t)=>(et(r,t)&j)===j,Tf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ue(r){if(ee(r,"field"),typeof r.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof r.ORDER);Kt(r.BYTES,"BYTES"),Kt(r.BITS,"BITS");for(let t of Tf)he(r[t],"field."+t);if(r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=j)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function Yr(r,t,e=!1){Ue(r),Vr(t,"nums"),wt(e,"passZero");let n=r,o=new Array(t.length).fill(e?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 hr(r,t){Ue(r);let e=r;Ko(e.ORDER,"FpLegendre");let n=(e.ORDER-j)/oe,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),a=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Df(r,t){if(t!==void 0&&No(t),r<=at)throw new Error("invalid n length: expected positive n, got "+r);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=ke(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${e})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Qi=new WeakMap,Zr=class{ORDER;BITS;BYTES;isLE;ZERO=at;ONE=j;_lengths;_mod;constructor(t,e={}){if(t<=j)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=Df(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 et(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return at<=t&&t<this.ORDER}is0(t){return t===at}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&j)===j}neg(t){return et(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return et(t*t,this.ORDER)}add(t,e){return et(t+e,this.ORDER)}sub(t,e){return et(t-e,this.ORDER)}mul(t,e){return et(t*e,this.ORDER)}pow(t,e){return na(t,e,this.ORDER)}div(t,e){return et(t*Xi(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Xi(t,this.ORDER)}sqrt(t){let e=Qi.get(this);return e||Qi.set(this,e=Bf(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?ko(t,this.BYTES):$r(t,this.BYTES)}fromBytes(t,e=!1){V(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?me(t):Ft(t);if(a&&(c=et(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Yr(this,t,!0)}cmov(t,e,n){return wt(n,"condition"),n?e:t}};function Fe(r,t={}){return Object.freeze(Zr.prototype),new Zr(r,t)}function ca(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=j)throw new Error("field order must be greater than 1");let t=ke(r-j);return Math.ceil(t/8)}function Gr(r){let t=ca(r);return t+Math.ceil(t/2)}function Wr(r,t,e=!1){V(r);let n=r.length,o=ca(t),s=Math.max(Gr(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?me(r):Ft(r),a=et(i,t-j)+j;return e?ko(a,o):$r(a,o)}var Ho=BigInt(0),pr=BigInt(1),Lf=BigInt(4),zo=16,ua=128,Cf=5,fa=2**31;function se(r){let t=r;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof r);he(t.fromAffine,"Point.fromAffine"),he(t.fromBytes,"Point.fromBytes"),he(t.fromHex,"Point.fromHex"),ee(t.BASE,"Point.BASE"),ee(t.ZERO,"Point.ZERO"),Ue(t.Fp),Ue(t.Fn)}function Xr(r,t){se(r),da(t,r);let e=Yr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Rf(r,t,e=1){if(!Number.isSafeInteger(r)||r<e||r>t)throw new Error("invalid window size, expected ["+e+".."+t+"], got W="+r)}function Of(r,t){let e=r*(4*t+128);if(e>fa)throw new Error("invalid window size: table would need ~"+Math.ceil(e/2**20)+" MiB, max "+fa/2**20+" MiB")}function Vo(r,t){if(r!==void 0){he(r,"randomBytes");try{let e=r(t);if(!ne(e)||e.length!==t)return}catch{return}return r}}function da(r,t){Vr(r,"points"),r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Pf(r,t,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((n,o)=>{if(!(e===void 0?t.isValid(n):re(n)&&n<e))throw new Error("invalid scalar at index "+o)})}var ha=new WeakMap;function qo(r){return ha.get(r)||1}function Nf(r,t){let e=r.double(),n=[r];for(let o=1;o<t;o++)n.push(n[o-1].add(e));return n}function kf(r,t){let e=2**t,n=e/2,o=BigInt(e-1),s=[];for(;r>Ho;){let i=0;r&pr&&(i=Number(r&o),i>=n&&(i-=e),r-=BigInt(i)),s.push(i),r>>=pr}return s}function Uf(r,t,e){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),a=[];for(let c=0;c<e;c++){let u=Number(r&s);r>>=i,u>o&&(u-=n,r+=pr),a.push(u)}if(r!==Ho)throw new Error("invalid wnaf");return a}function Ff(r,t,e){let n=0;for(let s of e)n=Math.max(n,s.length);let o=r;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<e.length;i++){let a=e[i][s];if(a){let c=t[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Me=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,e){se(t),this.randomBytes=Vo(e,zo),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,e,n){let o=Math.ceil(n/e)+1,s=2**(e-1),i=[],a=t;for(let c=0;c<o;c++){let u=a;for(let l=0;l<s;l++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:e,bits:n,windows:o,comp:i}}wnafCachedCT(t,e){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=Uf(e,n,o),c=this.ZERO,u=this.BASE;for(let l=0;l<o;l++){let d=a[l],f=l*i,p=Math.abs(d)-1,v=s[f];for(let b=1;b<i;b++)v=b===p?s[f+b]:v;let x=v.negate();d===0?u=u.add(s[f]):c=c.add(d<0?x:v)}return{p:c,f:u}}getWnafPrecomputes(t,e,n,o){let s=this.wnafPrecomputes.get(e),i=s?.find(a=>a.W===t&&a.bits===n);return i||(i=this.buildWnafTable(e,t,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(e,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,e){if(this.assertPoint(t),!Uo(e,pr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,e,n,o){let s=qo(t);return s===1?this.fixedWindowCT(t,e,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),e)}mulCT(t,e,n){return this.validateMulInput(t,e),this.runCT(t,e,this.bits,n)}mulCTBlinded(t,e,n){if(this.validateMulInput(t,e),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+ua,s=this.randomBytes(zo);if(!ne(s)||s.length!==zo)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=e+Ft(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,e,n){let o=Cf,s=1<<o,i=dr(o),a=new Array(s);a[0]=this.ZERO;for(let l=1;l<s;l++)a[l]=a[l-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let l=c-1;l>=0;l--){if(l!==c-1)for(let p=0;p<o;p++)u=u.double();let d=Number(e>>BigInt(l*o)&i),f=a[0];for(let p=1;p<s;p++)f=p===d?a[p]:f;u=u.add(f)}return{p:u,f:u}}shouldBlind(t,e){return this.randomBytes===void 0?!1:e===pr?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,e,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,e,o):this.mulCT(t,e,o)}mulUnsafe(t,e,n){if(this.assertPoint(t),!re(e))throw new Error("invalid scalar");let o=qo(t);if(o===1||e>=this.Point.Fn.ORDER)return Qr(this.Point,[t],[e],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,e).p}setWindowSize(t,e){this.assertPoint(t),Rf(e,this.bits);let n=Math.ceil((this.bits+ua)/e)+1;Of(n*2**(e-1),this.Point.Fp.BYTES),ha.set(t,e),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return qo(t)!==1}};function Qr(r,t,e,n=!1){if(se(r),da(t,r),wt(n,"allowOversized"),Pf(e,r.Fn,n?r.Fn.ORDER**Lf:void 0),t.length!==e.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>Nf(i,4)),s=e.map(i=>kf(i,4));return Ff(r.ZERO,o,s)}function la(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ue(t),t}else return Fe(r,{isLE:e})}function Jr(r,t,e={},n){if(r!=="weierstrass"&&r!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);xt(e);for(let c of["p","n","h"]){let u=t[c];if(!(re(u)&&u!==Ho))throw new Error(`CURVE.${c} must be positive bigint`)}let o=la(t.p,e.Fp,n),s=la(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function tn(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var en=BigInt(0),rn=BigInt(1),nn=BigInt(2),Mf=BigInt(4),pa=BigInt(8);function Kf(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function ma(r,t={}){xt(t,{},{},"extraOpts");let e=t,n=Jr("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(hr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(hr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");xt(e,{},{uvRatio:"function",randomBytes:"function"});let c=e.randomBytes===void 0?pe:e.randomBytes,u=nn<<BigInt(o.BYTES*8)-rn;function l(y){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(y)}let d=e.uvRatio===void 0?(y,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(y,g))}}catch{return{isValid:!1,value:en}}}:e.uvRatio;if(!Kf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let f=o.eql(i.a,o.neg(o.ONE))?y=>o.neg(y):o.eql(i.a,o.ONE)?y=>y:y=>o.mul(i.a,y);function p(y,g,w=!1){let S=w?rn:en;return Ne("coordinate "+y,g,S,u),g}function v(y){if(!(y instanceof x))throw new Error("EdwardsPoint expected")}class x{static BASE=new x(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new x(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(g,w,S,I){this.X=p("x",g),this.Y=p("y",w),this.Z=p("z",S,!0),this.T=p("t",I),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof x)throw new Error("extended point not allowed");let{x:w,y:S}=g||{};return p("x",w),p("y",S),new x(w,S,o.ONE,o.mul(w,S))}static fromBytes(g,w=!1){let S=o.BYTES,{a:I,d:U}=i;g=lr(V(g,S,"point")),wt(w,"zip215");let R=lr(g),C=g[S-1];R[S-1]=C&-129;let P=me(R),M=w?u:o.ORDER;Ne("point.y",P,en,M);let z=o.sqr(P),Z=o.sub(z,o.ONE),T=o.sub(o.mulN(U,z),I),{isValid:F,value:K}=d(Z,T);if(!F)throw new Error("bad point: invalid y coordinate");let O=l(K),G=(C&128)!==0;if(!w&&o.is0(K)&&G)throw new Error("bad point: x=0 and x_0=1");return G!==O&&(K=o.neg(K)),x.fromAffine({x:K,y:P})}static fromHex(g,w=!1){return x.fromBytes(Pe(g),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,w=!0){return h.setWindowSize(this,g),w||this.multiply(nn),this}assertValidity(){let g=this,{a:w,d:S}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:I,Y:U,Z:R,T:C}=g,P=o.sqr(I),M=o.sqr(U),z=o.sqr(R),Z=o.sqr(z),T=o.mul(P,w),F=o.mul(o.add(T,M),z),K=o.add(Z,o.mul(S,o.mul(P,M)));if(!o.eql(F,K))throw new Error("bad point: equation left != right (1)");let O=o.mul(I,U),G=o.mul(R,C);if(!o.eql(O,G))throw new Error("bad point: equation left != right (2)")}equals(g){v(g);let{X:w,Y:S,Z:I}=this,{X:U,Y:R,Z:C}=g,P=o.mul(w,C),M=o.mul(U,I),z=o.mul(S,C),Z=o.mul(R,I);return o.eql(P,M)&&o.eql(z,Z)}is0(){return this.equals(x.ZERO)}negate(){return new x(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:w,Z:S}=this,I=o.sqr(g),U=o.sqr(w),R=o.mul(o.sqr(S),nn),C=f(I),P=o.addN(g,w),M=o.sub(o.subN(o.sqr(P),I),U),z=o.addN(C,U),Z=o.subN(z,R),T=o.subN(C,U),F=o.mul(M,Z),K=o.mul(z,T),O=o.mul(M,T),G=o.mul(Z,z);return new x(F,K,G,O)}add(g){v(g);let{d:w}=i,{X:S,Y:I,Z:U,T:R}=this,{X:C,Y:P,Z:M,T:z}=g,Z=o.mul(S,C),T=o.mul(I,P),F=o.mul(o.mulN(R,w),z),K=o.mul(U,M),O=o.sub(o.subN(o.mulN(o.addN(S,I),o.addN(C,P)),Z),T),G=o.subN(K,F),tt=o.addN(K,F),A=o.sub(T,f(Z)),m=o.mul(O,G),E=o.mul(tt,A),_=o.mul(O,A),B=o.mul(G,tt);return new x(m,E,B,_)}subtract(g){return v(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:w,f:S}=h.mulSecret(this,g,a,b);return b([w,S])[0]}multiplyUnsafe(g){if(!s.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===en?x.ZERO:this.is0()||g===rn?this:h.mulUnsafe(this,g,b)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return h.mulUnsafe(this,i.n).is0()}toAffine(g){let w=this,S=g;if(S!=null&&typeof S!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof S);let{X:I,Y:U,Z:R}=w,C=w.is0();S==null&&(S=C?o.create(pa):o.inv(R));let P=o.mul(I,S),M=o.mul(U,S),z=o.mul(R,S);if(C)return{x:o.ZERO,y:o.ONE};if(!o.eql(z,o.ONE))throw new Error("invZ was invalid");return{x:P,y:M}}clearCofactor(){return a===rn?this:a===nn?this.double():a===Mf?this.double().double():a===pa?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:w}=this.toAffine(),S=o.toBytes(w);return S[S.length-1]|=l(g)?128:0,S}toHex(){return ur(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=y=>Xr(x,y),h=new Me(x,c);return h.bits>=6&&x.BASE.precompute(6),Object.freeze(x.prototype),Object.freeze(x),x}function ga(r,t,e={}){if(se(r),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;xt(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}=r,u=n.outputLen,l=2*a.BYTES;if(u!==void 0&&(Kt(u,"hash.outputLen"),u!==l))throw new Error(`hash.outputLen must be ${l}, got ${u}`);let d=o.randomBytes===void 0?pe:o.randomBytes,f=o.toMontgomery,p=o.toMontgomerySecret,v=o.adjustScalarBytes===void 0?T=>T:o.adjustScalarBytes,x=o.domain===void 0?(T,F,K)=>{if(wt(K,"phflag"),F.length||K)throw new Error("Contexts/pre-hash are not supported");return T}:o.domain;function b(T){return c.create(me(T))}function h(T){let F=C.secretKey;V(T,C.secretKey,"secretKey");let K=V(n(T),2*F,"hashedSecretKey"),O=v(K.slice(0,F)),G=K.slice(F,2*F),tt=b(O);return{head:O,prefix:G,scalar:tt}}function y(T){let{head:F,prefix:K,scalar:O}=h(T),G=i.multiply(O),tt=G.toBytes();return{head:F,prefix:K,scalar:O,point:G,pointBytes:tt}}function g(T){return y(T).pointBytes}function w(T=Uint8Array.of(),...F){let K=Tt(...F);return b(n(x(K,V(T,void 0,"context"),!!s)))}function S(T,F,K={}){xt(K,{},{},"options"),T=lr(V(T,void 0,"message")),s&&(T=s(T));let{prefix:O,scalar:G,pointBytes:tt}=y(F),A=w(K.context,O,T),m=i.multiply(A).toBytes(),E=w(K.context,m,tt,T),_=c.create(A+E*G);if(!c.isValid(_))throw new Error("sign failed: invalid s");let B=Tt(m,c.toBytes(_));return V(B,C.signature,"result")}let I={zip215:o.zip215};function U(T,F,K,O=I){xt(O);let{context:G}=O,tt=O.zip215===void 0?!!I.zip215:O.zip215,A=C.signature;T=V(T,A,"signature"),F=V(F,void 0,"message"),K=V(K,C.publicKey,"publicKey"),tt!==void 0&&wt(tt,"zip215"),s&&(F=s(F));let m=A/2,E=T.subarray(0,m),_=me(T.subarray(m,A)),B,D,L;try{B=r.fromBytes(K,tt),D=r.fromBytes(E,tt),L=i.multiplyUnsafe(_)}catch{return!1}if(!tt&&B.isSmallOrder())return!1;let N=w(G,E,K,F);return D.add(B.multiplyUnsafe(N)).subtract(L).clearCofactor().is0()}let R=a.BYTES,C={secretKey:R,publicKey:R,signature:2*R,seed:R};function P(T){return T=T===void 0?d(C.seed):T,V(T,C.seed,"seed")}function M(T){return ne(T)&&T.length===C.secretKey}function z(T,F){try{return!!r.fromBytes(T,F===void 0?I.zip215:F)}catch{return!1}}let Z={getExtendedPublicKey:y,randomSecretKey:P,isValidSecretKey:M,isValidPublicKey:z,toMontgomery(T){if(f===void 0)throw new Error("Montgomery conversion is not supported for this curve");return f(r.fromBytes(T))},toMontgomerySecret(T){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(T)}};return Object.freeze(C),Object.freeze(Z),Object.freeze({keygen:tn(P,g),getPublicKey:g,sign:S,verify:U,utils:Z,Point:r,lengths:C})}var jo=BigInt(1),ya=BigInt(2);var zf=BigInt(5),qf=BigInt(8),$o=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Hf={p:$o,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:qf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Vf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=$o,a=r*r%s*r%s,c=J(a,ya,s)*a%s,u=J(c,jo,s)*r%s,l=J(u,zf,s)*u%s,d=J(l,t,s)*l%s,f=J(d,e,s)*d%s,p=J(f,n,s)*f%s,v=J(p,o,s)*p%s,x=J(v,o,s)*p%s,b=J(x,t,s)*l%s;return{pow_p_5_8:J(b,ya,s)*r%s,b2:a}}function xa(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ba=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function jf(r,t){let e=$o,n=et(t*t*t,e),o=et(n*n*t,e),s=Vf(r*o).pow_p_5_8,i=et(r*n*s,e),a=et(t*i*i,e),c=i,u=et(i*ba,e),l=a===r,d=a===et(-r,e),f=a===et(-r*ba,e);return l&&(i=c),(d||f)&&(i=u),aa(i,e)&&(i=et(-i,e)),{isValid:l||d,value:i}}var Zo=ma(Hf,{uvRatio:jf}),wa=Zo.Fp;function $f(r){let{y:t}=r;return wa.toBytes(wa.div(jo+t,jo-t))}function Zf(r){let t=Zo.Fp.BYTES;return Bt(r,t),xa(Po(r.subarray(0,t))).subarray(0,t)}function Yf(r){return ga(Zo,Po,Object.assign({adjustScalarBytes:xa,toMontgomery:$f,toMontgomerySecret:Zf,zip215:!0},r))}var Ea=Yf({});var mr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},on=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var sn={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new on("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 an=32;var Yo,Gf=(async()=>{try{return await sn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Wf(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await sn.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await sn.get().subtle.verify({name:"Ed25519"},n,Lt(t),Lt(e instanceof Uint8Array?e:e.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Xf(r,t,e){return Ea.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Sa(r,t,e){return Yo==null&&(Yo=await Gf),Yo?Wf(r,t,e):Xf(r,t,e)}function cn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var un=class{type="Ed25519";raw;constructor(t){this.raw=Go(t,an)}toMultihash(){return Dt.digest(Re(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Sa(this.raw,e,t);return cn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function _a(r){return r=Go(r,an),new un(r)}function Go(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new yt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Jf=Math.pow(2,7),tl=Math.pow(2,14),el=Math.pow(2,21),Wo=Math.pow(2,28),Xo=Math.pow(2,35),Qo=Math.pow(2,42),Jo=Math.pow(2,49),$=128,mt=127;function Et(r){if(r<Jf)return 1;if(r<tl)return 2;if(r<el)return 3;if(r<Wo)return 4;if(r<Xo)return 5;if(r<Qo)return 6;if(r<Jo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ke(r,t,e=0){switch(Et(r)){case 8:t[e++]=r&255|$,r/=128;case 7:t[e++]=r&255|$,r/=128;case 6:t[e++]=r&255|$,r/=128;case 5:t[e++]=r&255|$,r/=128;case 4:t[e++]=r&255|$,r>>>=7;case 3:t[e++]=r&255|$,r>>>=7;case 2:t[e++]=r&255|$,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function rl(r,t,e=0){switch(Et(r)){case 8:t.set(e++,r&255|$),r/=128;case 7:t.set(e++,r&255|$),r/=128;case 6:t.set(e++,r&255|$),r/=128;case 5:t.set(e++,r&255|$),r/=128;case 4:t.set(e++,r&255|$),r>>>=7;case 3:t.set(e++,r&255|$),r>>>=7;case 2:t.set(e++,r&255|$),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ts(r,t){let e=r[t],n=0;if(n+=e&mt,e<$||(e=r[t+1],n+=(e&mt)<<7,e<$)||(e=r[t+2],n+=(e&mt)<<14,e<$)||(e=r[t+3],n+=(e&mt)<<21,e<$)||(e=r[t+4],n+=(e&mt)*Wo,e<$)||(e=r[t+5],n+=(e&mt)*Xo,e<$)||(e=r[t+6],n+=(e&mt)*Qo,e<$)||(e=r[t+7],n+=(e&mt)*Jo,e<$))return n;throw new RangeError("Could not decode varint")}function nl(r,t){let e=r.get(t),n=0;if(n+=e&mt,e<$||(e=r.get(t+1),n+=(e&mt)<<7,e<$)||(e=r.get(t+2),n+=(e&mt)<<14,e<$)||(e=r.get(t+3),n+=(e&mt)<<21,e<$)||(e=r.get(t+4),n+=(e&mt)*Wo,e<$)||(e=r.get(t+5),n+=(e&mt)*Xo,e<$)||(e=r.get(t+6),n+=(e&mt)*Qo,e<$)||(e=r.get(t+7),n+=(e&mt)*Jo,e<$))return n;throw new RangeError("Could not decode varint")}function Aa(r,t,e=0){return t==null&&(t=pt(Et(r))),t instanceof Uint8Array?Ke(r,t,e):rl(r,t,e)}function gr(r,t=0){return r instanceof Uint8Array?ts(r,t):nl(r,t)}var es=new Float32Array([-0]),ie=new Uint8Array(es.buffer);function Ba(r,t,e){es[0]=r,t[e]=ie[0],t[e+1]=ie[1],t[e+2]=ie[2],t[e+3]=ie[3]}function Ta(r,t){return ie[0]=r[t],ie[1]=r[t+1],ie[2]=r[t+2],ie[3]=r[t+3],es[0]}var rs=new Float64Array([-0]),gt=new Uint8Array(rs.buffer);function Da(r,t,e){rs[0]=r,t[e]=gt[0],t[e+1]=gt[1],t[e+2]=gt[2],t[e+3]=gt[3],t[e+4]=gt[4],t[e+5]=gt[5],t[e+6]=gt[6],t[e+7]=gt[7]}function La(r,t){return gt[0]=r[t],gt[1]=r[t+1],gt[2]=r[t+2],gt[3]=r[t+3],gt[4]=r[t+4],gt[5]=r[t+5],gt[6]=r[t+6],gt[7]=r[t+7],rs[0]}var ol=BigInt(Number.MAX_SAFE_INTEGER),sl=BigInt(Number.MIN_SAFE_INTEGER),vt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<ol&&t>sl)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ca&&(o=0n,++n>Ca&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ge}},ge=new vt(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var Ca=4294967296n;function Ra(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Oa(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function ns(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Rt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function fn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var os=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Lt(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,Rt(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 Rt(this,4);return fn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return fn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=Ta(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=La(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Rt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Oa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Rt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Rt(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 vt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Rt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Rt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Rt(this,8);let t=fn(this.buf,this.pos+=4),e=fn(this.buf,this.pos+=4);return new vt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ts(this.buf,this.pos);return this.pos+=Et(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 yr(r){return new os(r instanceof Uint8Array?r:r.subarray())}function zt(r,t,e){let n=yr(r);return t.decode(n,void 0,e)}function ss(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return pt(i);o+i>t&&(n=pt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ye=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function is(){}var cs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},il=ss();function al(r){return globalThis.Buffer!=null?pt(r):il(r)}var wr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye(is,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ye(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new us((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,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=vt.fromBigInt(t);return this._push(ln,e.length(),e)}uint64Number(t){return this._push(Ke,Et(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=vt.fromBigInt(t).zzEncode();return this._push(ln,e.length(),e)}sint64Number(t){let e=vt.fromNumber(t).zzEncode();return this._push(ln,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(as,1,t?1:0)}fixed32(t){return this._push(br,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=vt.fromBigInt(t);return this._push(br,4,e.lo)._push(br,4,e.hi)}fixed64Number(t){let e=vt.fromNumber(t);return this._push(br,4,e.lo)._push(br,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ba,4,t)}double(t){return this._push(Da,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(as,1,0):this.uint32(e)._push(ul,e,t)}string(t){let e=Ra(t);return e!==0?this.uint32(e)._push(ns,e,t):this._push(as,1,0)}fork(){return this.states=new cs(this),this.head=this.tail=new ye(is,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ye(is,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=al(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function as(r,t,e){t[e]=r&255}function cl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var us=class extends ye{next;constructor(t,e){super(cl,t,e),this.next=void 0}};function ln(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function br(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function ul(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(wr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(fl,t,r),this},wr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ll,t,r),this});function fl(r,t,e){t.set(r,e)}function ll(r,t,e){r.length<40?ns(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Q(r),e)}function fs(){return new wr}function qt(r,t){let e=fs();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*Ht(r,t,e){let n=yr(r);yield*t.stream(n,void 0,".",e)}var dn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function hn(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function ze(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i,a){};return hn("enum",dn.VARINT,e,n,o)}function Vt(r,t,e){return hn("message",dn.LENGTH_DELIMITED,r,t,e)}var xr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var bt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(bt||(bt={}));var ls;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ls||(ls={}));(function(r){r.codec=()=>ze(ls)})(bt||(bt={}));var Er;(function(r){let t;r.codec=()=>(t==null&&(t=Vt((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 l=s.uint32();switch(l>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>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(l&7);break}}}})),t);function e(s){return qt(s,r.codec())}r.encode=e;function n(s,i){return zt(s,r.codec(),i)}r.decode=n;function o(s,i){return Ht(s,r.codec(),i)}r.stream=o})(Er||(Er={}));var ds;(function(r){let t;r.codec=()=>(t==null&&(t=Vt((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 l=s.uint32();switch(l>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>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(l&7);break}}}})),t);function e(s){return qt(s,r.codec())}r.encode=e;function n(s,i){return zt(s,r.codec(),i)}r.decode=n;function o(s,i){return Ht(s,r.codec(),i)}r.stream=o})(ds||(ds={}));var pn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(Fr(t),Bt(e,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(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),de(o)}update(t){return Oe(this),this.iHash.update(t),this}digestInto(t){Oe(this),Mr(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.canXOF=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Na=(()=>{let r=((t,e,n)=>new pn(t,e).update(n).digest());return r.create=(t,e)=>new pn(t,e),r})();var hl=BigInt(0),hs=class extends Error{constructor(t=""){super(t)}},jt={Err:hs,_tlv:{encode:(r,t)=>{let{Err:e}=jt;if(Kt(r,"tag"),r<0||r>255)throw new e("tlv.encode: wrong tag");if(Yi(t,"data"),t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=fr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?fr(o.length/2|128):"";return fr(r)+s+o+t},decode(r,t){let{Err:e}=jt;t=V(t,void 0,"DER data");let n=0;if(r<0||r>255)throw new e("tlv.decode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=jt;if(jr(r),r<hl)throw new t("integer: negative integers are not allowed");let e=fr(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=jt;if(r.length<1)throw new t("invalid signature integer: empty");if(r[0]&128)throw new t("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ft(r)}},toSig(r,t){let{Err:e,_int:n,_tlv:o}=jt;if(t!==void 0&&(Kt(t,"maxScalarBytes"),t<1))throw new e("invalid signature: maxScalarBytes must be positive");let s=V(r,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:l,l:d}=o.decode(2,u);if(d.length)throw new e("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||l.length>t))throw new e("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=jt;xt(r,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},mn=(Object.freeze(jt._tlv),Object.freeze(jt._int),Object.freeze(jt));var ka=(r,t)=>(r+(r>=0?t:-t)/Ua)/t;function pl(r,t,e){Ne("scalar",r,$t,e);let[[n,o],[s,i]]=t,a=ka(i*r,e),c=ka(-o*r,e),u=r-a*n-c*s,l=-a*o-c*i,d=u<$t,f=l<$t;d&&(u=-u),f&&(l=-l);let p=dr(Math.ceil(ke(e)/2))+be;if(u<$t||u>=p||l<$t||l>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:f,k2:l}}function gs(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ps(r,t){xt(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return wt(e.lowS,"lowS"),wt(e.prehash,"prehash"),e.format!==void 0&&gs(e.format),e}var $t=BigInt(0),be=BigInt(1),Ua=BigInt(2),ms=BigInt(3),ml=BigInt(4);function Fa(r,t={}){let e=Jr("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;xt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:l,isTorsionFree:d,fromBytes:f,toBytes:p}=t,v=t.randomBytes===void 0?pe: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 x=c?{beta:c.beta,basises:c.basises.map(A=>[...A])}:void 0,b=Ka(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function y(A,m,E){if(m.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:_,y:B}=m.toAffine(),D=n.toBytes(_);if(wt(E,"isCompressed"),E){h();let L=!n.isOdd(B);return Tt(Ma(L),D)}else return Tt(Uint8Array.of(4),D,n.toBytes(B))}function g(A){V(A,void 0,"Point");let{publicKey:m,publicKeyUncompressed:E}=b,_=A.length,B=A[0],D=A.subarray(1);if(u&&_===1&&B===0)return{x:n.ZERO,y:n.ZERO};if(_===m&&(B===2||B===3)){let L=n.fromBytes(D);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let N=R(L),k;try{k=n.sqrt(N)}catch(nt){let W=nt instanceof Error?": "+nt.message:"";throw new Error("bad point: is not on curve, sqrt error"+W)}h();let H=n.isOdd(k);return(B&1)===1!==H&&(k=n.neg(k)),{x:L,y:k}}else if(_===E&&B===4){let L=n.BYTES,N=n.fromBytes(D.subarray(0,L)),k=n.fromBytes(D.subarray(L,L*2));if(!C(N,k))throw new Error("bad point: is not on curve");return{x:N,y:k}}else throw new Error(`bad point: got length ${_}, expected compressed=${m} or uncompressed=${E}`)}let w=p===void 0?y:p,S=f===void 0?g:f,I=n.mul(s.b,ms),U=n.is0(s.a)?A=>n.ZERO:A=>n.mul(s.a,A);function R(A){let m=n.sqr(A),E=n.mul(m,A);return n.add(n.add(E,n.mul(A,s.a)),s.b)}function C(A,m){let E=n.sqr(m),_=R(A);return n.eql(E,_)}if(!C(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let P=n.mul(n.pow(s.a,ms),ml),M=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(P,M)))throw new Error("bad curve params: a or b");function z(A,m,E=!1){if(!n.isValid(m)||E&&n.is0(m))throw new Error(`bad point coordinate ${A}`);return typeof m=="object"&&m!==null?n.create(m):m}function Z(A){if(!(A instanceof O))throw new Error("Weierstrass Point expected")}function T(A){if(!x||!x.basises)throw new Error("no endo");return pl(A,x.basises,o.ORDER)}function F(A,m,E,_){if(!o.isValid(_))throw new RangeError("invalid scalar: out of range");if(x){let{k1neg:B,k1:D,k2neg:L,k2:N}=T(_),k=new O(n.mul(E.X,x.beta),E.Y,E.Z);A.push(B?E.negate():E,L?k.negate():k),m.push(D,N)}else A.push(E),m.push(_)}let K=new WeakSet;class O{static BASE=new O(s.Gx,s.Gy,n.ONE);static ZERO=new O(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,E,_){this.X=z("x",m),this.Y=z("y",E,!0),this.Z=z("z",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:E,y:_}=m||{};if(!m||!n.isValid(E)||!n.isValid(_))throw new Error("invalid affine point");if(m instanceof O)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(_)?O.ZERO:new O(E,_,n.ONE)}static fromBytes(m){let E=O.fromAffine(S(V(m,void 0,"point")));return E.assertValidity(),E}static fromHex(m){return O.fromBytes(Pe(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=6,E=!0){return tt.setWindowSize(this,m),E||this.multiply(ms),this}assertValidity(){let m=this;if(m.is0()){if(u&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}if(K.has(m))return;let{x:E,y:_}=m.toAffine();if(!n.isValid(E)||!n.isValid(_))throw new Error("bad point: x or y not field elements");if(!C(E,_))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");K.add(m)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){Z(m);let{X:E,Y:_,Z:B}=this,{X:D,Y:L,Z:N}=m,k=n.eql(n.mul(E,N),n.mul(D,B)),H=n.eql(n.mul(_,N),n.mul(L,B));return k&&H}negate(){return new O(this.X,n.neg(this.Y),this.Z)}double(){let{X:m,Y:E,Z:_}=this,B=n.ZERO,D=n.ZERO,L=n.ZERO,N=n.mul(m,m),k=n.mul(E,E),H=n.mul(_,_),q=n.mul(m,E);return q=n.add(q,q),L=n.mul(m,_),L=n.add(L,L),B=U(L),D=n.mul(I,H),D=n.add(B,D),B=n.sub(k,D),D=n.add(k,D),D=n.mul(B,D),B=n.mul(q,B),L=n.mul(I,L),H=U(H),q=n.sub(N,H),q=U(q),q=n.add(q,L),L=n.add(N,N),N=n.add(L,N),N=n.add(N,H),N=n.mul(N,q),D=n.add(D,N),H=n.mul(E,_),H=n.add(H,H),N=n.mul(H,q),B=n.sub(B,N),L=n.mul(H,k),L=n.add(L,L),L=n.add(L,L),new O(B,D,L)}add(m){Z(m);let{X:E,Y:_,Z:B}=this,{X:D,Y:L,Z:N}=m,k=n.ZERO,H=n.ZERO,q=n.ZERO,nt=n.mul(E,D),W=n.mul(_,L),ct=n.mul(B,N),_t=n.add(E,_),X=n.add(D,L);_t=n.mul(_t,X),X=n.add(nt,W),_t=n.sub(_t,X),X=n.add(E,B);let ot=n.add(D,N);return X=n.mul(X,ot),ot=n.add(nt,ct),X=n.sub(X,ot),ot=n.add(_,B),k=n.add(L,N),ot=n.mul(ot,k),k=n.add(W,ct),ot=n.sub(ot,k),q=U(X),k=n.mul(I,ct),q=n.add(k,q),k=n.sub(W,q),q=n.add(W,q),H=n.mul(k,q),W=n.add(nt,nt),W=n.add(W,nt),ct=U(ct),X=n.mul(I,X),W=n.add(W,ct),ct=n.sub(nt,ct),ct=U(ct),X=n.add(X,ct),nt=n.mul(W,X),H=n.add(H,nt),nt=n.mul(ot,X),k=n.mul(_t,k),k=n.sub(k,nt),nt=n.mul(_t,W),q=n.mul(ot,q),q=n.add(q,nt),new O(k,H,q)}subtract(m){return Z(m),this.add(m.negate())}is0(){return this.equals(O.ZERO)}multiply(m){if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let{p:E,f:_}=tt.mulSecret(this,m,i,G);return G([E,_])[0]}multiplyUnsafe(m){let E=this,_=m;if(!o.isValid(_))throw new RangeError("invalid scalar: out of range");if(_===$t||E.is0())return O.ZERO;if(_===be)return E;if(tt.hasWindowSize(this))return tt.mulUnsafe(E,_,G);let B=[],D=[];return F(B,D,E,_),Qr(O,B,D)}mulAddUnsafe(m,E,_){Z(E);let B=[],D=[];return F(B,D,this,m),F(B,D,E,_),Qr(O,B,D)}toAffine(m){let E=this,_=m;if(_!=null&&!n.isValid(_))throw new RangeError('"invertedZ" expected valid field element');let{X:B,Y:D,Z:L}=E;if(n.eql(L,n.ONE))return{x:B,y:D};let N=E.is0();_==null&&(_=N?n.ONE:n.inv(L));let k=n.mul(B,_),H=n.mul(D,_),q=n.mul(L,_);if(N)return{x:n.ZERO,y:n.ZERO};if(!n.eql(q,n.ONE))throw new Error("invZ was invalid");return{x:k,y:H}}isTorsionFree(){return i===be?!0:d?d(O,this):tt.mulUnsafe(this,a).is0()}clearCofactor(){return i===be?this:l?l(O,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===be?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return wt(m,"isCompressed"),this.assertValidity(),w(O,this,m)}toHex(m=!0){return ur(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let G=A=>Xr(O,A),tt=new Me(O,v);return tt.bits>=6&&O.BASE.precompute(6),Object.freeze(O.prototype),Object.freeze(O),O}function Ma(r){return Uint8Array.of(r?2:3)}function Ka(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function gl(r,t={}){se(r);let{Fn:e}=r,n=t.randomBytes===void 0?pe:t.randomBytes,o=Object.assign(Ka(r.Fp,e),{seed:Math.max(Gr(e.ORDER),16)});function s(p){try{let v=e.fromBytes(p);return e.isValidNot0(v)}catch{return!1}}function i(p,v){let{publicKey:x,publicKeyUncompressed:b}=o;try{let h=p.length;return v===!0&&h!==x||v===!1&&h!==b?!1:!r.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Wr(V(p,o.seed,"seed"),e.ORDER)}function c(p,v=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(v)}function u(p){let{secretKey:v,publicKey:x,publicKeyUncompressed:b}=o,h=e._lengths;if(!ne(p))return;let y=V(p,void 0,"key").length,g=y===x||y===b,w=y===v||!!h?.includes(y);if(!(g&&w))return g}function l(p,v,x=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(v)===!1)throw new Error("second arg must be public key");let b=e.fromBytes(p),h=r.fromBytes(v);if(h.is0())throw new Error("invalid public key: point at infinity");return h.multiply(b).toBytes(x)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},f=tn(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:f,Point:r,utils:d,lengths:o})}function za(r,t,e={}){se(r);let n=t;Fr(n),xt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},e),s=o.randomBytes===void 0?pe:o.randomBytes,i=o.hmac===void 0?(A,m)=>Na(n,A,m):o.hmac,{Fp:a,Fn:c}=r,{ORDER:u,BITS:l}=c,d=Gr(u),f=Vo(s,d),{keygen:p,getPublicKey:v,getSharedSecret:x,utils:b,lengths:h}=gl(r,o),y={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*Ua+be<a.ORDER;function w(A){let m=u>>be;return A>m}function S(A,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${A}: out of range 1..Point.Fn.ORDER`);return m}function I(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function U(A,m,E){return I(),(A===E?0:2)|Number(a.isOdd(m))}function R(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(A,m){gs(m);let E=h.signature,_=m==="compact"?E:m==="recovered"?E+1:void 0;return V(A,_)}class P{r;s;recovery;constructor(m,E,_){if(this.r=S("r",m),this.s=S("s",E),_!=null){if(R(),![0,1,2,3].includes(_))throw new Error("invalid recovery id");this.recovery=_}Object.freeze(this)}static fromBytes(m,E=y.format){C(m,E);let _;if(E==="der"){if(m.length>2*c.BYTES+16)throw new mn.Err("invalid signature: DER signature too long");let{r:N,s:k}=mn.toSig(V(m),c.BYTES+1);return new P(N,k)}E==="recovered"&&(_=m[0],E="compact",m=m.subarray(1));let B=h.signature/2,D=m.subarray(0,B),L=m.subarray(B,B*2);return new P(c.fromBytes(D),c.fromBytes(L),_)}static fromHex(m,E){return this.fromBytes(Pe(m),E)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new P(this.r,this.s,m)}recoverPublicKey(m){let{r:E,s:_}=this,B=this.assertRecovery(),D=B===2||B===3?E+u:E;if(!a.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let L=a.toBytes(D),N=r.fromBytes(Tt(Ma((B&1)===0),L)),k=c.inv(D),H=z(V(m,void 0,"msgHash")),q=c.create(-H*k),nt=c.create(_*k),W=r.BASE.mulAddUnsafe(q,N,nt);if(W.is0())throw new Error("invalid recovery: point at infinify");return W.assertValidity(),W}hasHighS(){return w(this.s)}toBytes(m=y.format){if(gs(m),m==="der")return Pe(mn.hexFromSig(this));let{r:E,s:_}=this,B=c.toBytes(E),D=c.toBytes(_);return m==="recovered"?(R(),Tt(Uint8Array.of(this.assertRecovery()),B,D)):Tt(B,D)}toHex(m){return ur(this.toBytes(m))}}Object.freeze(P.prototype),Object.freeze(P);let M=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let E=Ft(m),_=m.length*8-l;return _>0?E>>BigInt(_):E}:o.bits2int,z=o.bits2int_modN===void 0?function(m){return c.create(M(m))}:o.bits2int_modN,Z=dr(l);function T(A){return Ne("num < 2^"+l,A,$t,Z),c.toBytes(A)}function F(A,m){return V(A,void 0,"message"),m?V(n(A),void 0,"prehashed message"):A}function K(A,m,E){let{lowS:_,prehash:B,extraEntropy:D}=ps(E,y);A=F(A,B);let L=z(A),N=c.fromBytes(m);if(!c.isValidNot0(N))throw new Error("invalid private key");let k=[T(N),T(L)];if(D!=null&&D!==!1){let W=D===!0?s(h.secretKey):D;k.push(V(W,void 0,"extraEntropy"))}let H=Tt(...k),q=L;function nt(W){let ct=M(W);if(!c.isValidNot0(ct))return;let _t=r.BASE.multiply(ct).toAffine(),X=c.create(_t.x);if(X===$t)return;let ot;if(f!==void 0){let Ge=Ft(Wr(f(d),u)),Tc=c.inv(c.mul(Ge,ct)),Dc=c.mul(Ge,q),Lc=c.mul(Ge,N);ot=c.create(Tc*c.create(Dc+Lc*X))}else{let Ge=oa(ct,u);ot=c.create(Ge*c.create(q+X*N))}if(ot===$t)return;let Vn=U(_t.x,_t.y,X),Zs=ot;return _&&w(ot)&&(Zs=c.neg(ot),Vn^=1),new P(X,Zs,g?void 0:Vn)}return{seed:H,k2sig:nt}}function O(A,m,E={}){let{seed:_,k2sig:B}=K(A,m,E);return Wi(n.outputLen,c.BYTES,i)(_,B).toBytes(E.format)}function G(A,m,E,_={}){let{lowS:B,prehash:D,format:L}=ps(_,y);if(E=V(E,void 0,"publicKey"),m=F(m,D),!ne(A)){let N=A instanceof P?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+N)}C(A,L);try{let N=P.fromBytes(A,L),k=r.fromBytes(E);if(k.is0()||B&&N.hasHighS())return!1;let{r:H,s:q}=N,nt=z(m),W=c.inv(q),ct=c.create(nt*W),_t=c.create(H*W),X=r.BASE.mulAddUnsafe(ct,k,_t);if(X.is0())return!1;let ot=X.toAffine();return!(c.create(ot.x)!==H||L==="recovered"&&N.recovery!==U(ot.x,ot.y,H))}catch{return!1}}function tt(A,m,E={}){let{prehash:_}=ps(E,y);return m=F(m,_),P.fromBytes(A,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:p,getPublicKey:v,getSharedSecret:x,utils:b,lengths:h,Point:r,sign:O,verify:G,recoverPublicKey:tt,Signature:P,hash:n})}var bs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},yl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var qa=BigInt(2);function bl(r){let t=bs.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,d=J(l,e,t)*l%t,f=J(d,e,t)*l%t,p=J(f,qa,t)*u%t,v=J(p,o,t)*p%t,x=J(v,s,t)*v%t,b=J(x,a,t)*x%t,h=J(b,c,t)*b%t,y=J(h,a,t)*x%t,g=J(y,e,t)*l%t,w=J(g,i,t)*v%t,S=J(w,n,t)*u%t,I=J(S,qa,t);if(!ys.eql(ys.sqr(I),r))throw new Error("Cannot find square root");return I}var ys=Fe(bs.p,{sqrt:bl}),wl=Fa(bs,{Fp:ys,endo:yl}),qe=za(wl,$i);function Ha(r,t,e,n){let o=rr.digest(e instanceof Uint8Array?e:e.subarray());if(cn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),qe.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new mr(String(s))});try{return n?.signal?.throwIfAborted(),qe.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new mr(String(s))}}var gn=class{type="secp256k1";raw;_key;constructor(t){this._key=ja(t),this.raw=Va(this._key)}toMultihash(){return Dt.digest(Re(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){return Ha(this._key,e,t,n)}};function $a(r){return new gn(r)}function Va(r){return qe.Point.fromBytes(r).toBytes()}function ja(r){try{return qe.Point.fromBytes(r),r}catch(t){throw new We(String(t))}}function Za(r){let{Type:t,Data:e}=Er.decode(r.digest),n=e??new Uint8Array;switch(t){case bt.Ed25519:return _a(n);case bt.secp256k1:return $a(n);case bt.ECDSA:return Ai(n);default:throw new Xe}}function Re(r){return Er.encode({Type:bt[r.type],Data:r.raw})}var Ya=Symbol.for("nodejs.util.inspect.custom"),xl=114,Sr=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()})`}[$n]=!0;toString(){return this.string==null&&(this.string=st.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ht.createV1(xl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ya](){return`PeerId(${this.toString()})`}},yn=class extends Sr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},bn=class extends Sr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},wn=class extends Sr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},El=2336,xn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Dt.digest(Q(this.url))}[Ya](){return`PeerId(${this.url})`}[$n]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ht.createV1(El,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=it(t)),t.toString()===this.toString())}};function En(r){if(vl(r))return new yn({multihash:r});if(Sl(r))try{let t=Za(r);if(t.type==="Ed25519")return new bn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new wn({multihash:r,publicKey:t})}catch{let e=it(r.digest);return new xn(new URL(e))}throw new Lr("Supplied PeerID Multihash is invalid")}function Sl(r){return r.code===Dt.code}function vl(r){return r.code===rr.code}function ws(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Sn(r){let t=ue(st.decode(`z${r}`));return En(t)}var vn=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return ws(this.set.entries(),t=>{let e=Sn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Sn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return ws(this.set.values(),t=>Sn(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function xs(){return new vn}var Es={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ga={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Wa=new globalThis.TextEncoder;function _l(r,t){let e=Es[t],n=Ga[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Al(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Es[t],o=Ga[t],s=r;for(;s.length>0;){let i=Wa.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function Ss(r,{size:t=32,utf8Buffer:e}={}){if(!Es[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return Al(r,t,e);r=Wa.encode(r)}return _l(r,t)}var vr={hash:r=>Number(Ss(r,{size:32})),hashV:(r,t)=>Il(vr.hash(r,t))};function Il(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),Q(t,"base16")}var vs=64,Ot=class{fp;h;seed;constructor(t,e,n,o=2){if(o>vs)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=It(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?lt(this.fp,t.fp):!1}};function we(r,t){return Math.floor(Math.random()*(t-r))+r}var xe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Ot))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Ot))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof Ot))throw new TypeError("Invalid Fingerprint");let e=we(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Ot))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Bl=500,_r=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??vr,this.seed=t.seed??we(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=Q(t));let e=new Ot(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new xe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new xe(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[we(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize));for(let a=0;a<Bl;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=Q(t));let e=new Ot(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=Q(t));let e=new Ot(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Tl={1:.5,2:.84,4:.95,8:.98};function Dl(r=.001){return r>.002?2:r>1e-5?4:8}function Xa(r,t=.001){let e=Dl(t),n=Tl[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),vs);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var _n=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??vr,this.seed=t.seed??we(0,Math.pow(2,10)),this.filterSeries=[new _r({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=Q(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new _r({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=Q(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=Q(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function _s(r,t=.001,e){return new _n({...Xa(r,t),...e??{}})}function Ll(r){let t=r.getComponents(),e={},n=0;return t[n]?.name==="ip6zone"&&(e.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(e.type=t[n].name,e.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(e.type=t[n].name,e.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(e.protocol=t[n].name==="tcp"?"tcp":"udp",e.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(e.type==="ip4"?e.cidr=parseInt(`${t[n].value}`):e.type==="ip6"&&(e.cidr=`${t[n].value}`),n++),e.type==null||e.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e)}function Pt(r){let t=Ll(r);if(t==null)throw new yt(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var An=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let f=Number.parseInt(d,t);if(!Number.isNaN(f))return f});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Qa=45,Cl=15,He=new An;function In(r){if(!(r.length>Cl))return He.new(r).parseWith(()=>He.readIPv4Addr())}function Bn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Qa))return He.new(r).parseWith(()=>He.readIPv6Addr())}function ae(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Qa)return;let e=He.new(r).parseWith(()=>He.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function Ja(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function As(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Is(r){switch(r.length){case Ee:return r.join(".");case Se:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function tc(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function ec(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Ee=4,Se=16,qy=parseInt("0xFFFF",16),rc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ar(r,t){t.length===Se&&r.length===Ee&&Ja(t,0,11)&&(t=t.slice(12)),t.length===Ee&&r.length===Se&&As(r,rc,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function nc(r,t){if(typeof t=="string"&&(t=ae(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Bs(r){if(!Tn(r))throw new Error("Must have 0xffff prefix");return r.slice(12)}function Tn(r){return As(r,rc,0,11)}function Ts(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Ee,o=In(t);if(o==null&&(n=Se,o=Bn(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=Ds(s,8*n);return{network:Ar(o,i),mask:i}}function Ds(r,t){if(t!==8*Ee&&t!==8*Se)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var ve=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Ts(t));else{let n=ae(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=ae(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ds(o,8*n.length);this.network=Ar(n,this.mask)}}contains(t){return nc({network:this.network,mask:this.mask},t)}toString(){let t=tc(this.mask),e=t!==-1?String(t):ec(this.mask);return Is(this.network)+"/"+e}};function oc(r,t){return new ve(r).contains(t)}function sc(r){try{let t=Pt(r);return t.type==="ip6"?oc("2000::/3",t.host):!1}catch{return!1}}function Ve(r){return!!In(r)}function Dn(r){return!!Bn(r)}var Rl=["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","::/128","::1/128","64:ff9b::/96","100::/64","2001::/32","2001:20::/28","2001:db8::/32","2002::/16","fc00::/7","fe80::/10","ff00::/8"].map(r=>new ve(r));function ic(r){if(!Ve(r)&&!Dn(r))return;let t=ae(r);if(t==null)return;let e=t.length===16&&Tn(t)?Bs(t):t;return Rl.some(n=>n.contains(e))}function Ls(r){try{let t=Pt(r);switch(t.type){case"ip4":case"ip6":return ic(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var dt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Zt=class extends Error{static name="ValidationError";name="ValidationError"},Ln=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Cn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Rs(r){return t=>it(t,r)}function Os(r){return t=>Q(t,r)}function je(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function _e(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function ac(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Q(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=_e(n);return kt([e,o],e.length+o.length)}function cc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Wt.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=_e(n);return kt([e,o],e.length+o.length)}function Ps(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=it(t,"base32"),o=je(e);return`${n}:${o}`}var Ns=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new dt("Invalid byte value in IP address");t[n]=o}),t},uc=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Ve(e[n]),i;s&&(i=Ns(e[n]),e[n]=it(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,it(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new dt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},fc=function(r){if(r.byteLength!==4)throw new dt("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},lc=function(r){if(r.byteLength!==16)throw new dt("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new dt(`Invalid IPv6 address "${e}"`)}};function dc(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new dt(`Invalid IPv6 address "${r}"`)}}var Cs=Object.values(nr).map(r=>r.decoder),Ol=(function(){let r=Cs[0].or(Cs[1]);return Cs.slice(2).forEach(t=>r=r.or(t)),r})();function hc(r){return Ol.decode(r)}function pc(r){return t=>r.encoder.encode(t)}function Pl(r){if(parseInt(r).toString()!==r)throw new Zt("Value must be an integer")}function Nl(r){if(r<0)throw new Zt("Value must be a positive integer, or zero")}function kl(r){return t=>{if(t>r)throw new Zt(`Value must be smaller than or equal to ${r}`)}}function Ul(...r){return t=>{for(let e of r)e(t)}}var Ir=Ul(Pl,Nl,kl(65535));var ft=-1,ks=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new Cn(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Yt=new ks,vd=[{code:4,name:"ip4",size:32,valueToBytes:Ns,bytesToValue:fc,validate:r=>{if(!Ve(r))throw new Zt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:_e,bytesToValue:je,validate:Ir},{code:273,name:"udp",size:16,valueToBytes:_e,bytesToValue:je,validate:Ir},{code:33,name:"dccp",size:16,valueToBytes:_e,bytesToValue:je,validate:Ir},{code:41,name:"ip6",size:128,valueToBytes:uc,bytesToValue:lc,stringToValue:dc,validate:r=>{if(!Dn(r))throw new Zt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ft},{code:43,name:"ipcidr",size:8,bytesToValue:Rs("base10"),valueToBytes:Os("base10")},{code:53,name:"dns",size:ft},{code:54,name:"dns4",size:ft},{code:55,name:"dns6",size:ft},{code:56,name:"dnsaddr",size:ft},{code:132,name:"sctp",size:16,valueToBytes:_e,bytesToValue:je,validate:Ir},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ft,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ft,bytesToValue:Rs("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Os("base58btc")(r):ht.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ps,valueToBytes:ac},{code:445,name:"onion3",size:296,bytesToValue:Ps,valueToBytes:cc},{code:446,name:"garlic64",size:ft},{code:447,name:"garlic32",size:ft},{code:448,name:"tls"},{code:449,name:"sni",size:ft},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ft,bytesToValue:pc(uo),valueToBytes:hc},{code:480,name:"http"},{code:481,name:"http-path",size:ft,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ft}];vd.forEach(r=>{Yt.addProtocol(r)});function mc(r){let t=[],e=0;for(;e<r.length;){let n=gr(r,e),o=Yt.getProtocol(n),s=Et(n),i=_d(o,r,e+s),a=0;i>0&&o.size===ft&&(a=Et(i));let c=s+a+i,u={code:n,name:o.name,bytes:Lt(r.subarray(e,e+c))};if(i>0){let l=e+s+a,d=r.subarray(l,l+i);u.value=o.bytesToValue?.(d)??it(d)}t.push(u),e+=c}return t}function gc(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Yt.getProtocol(n.code),s=Et(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Q(n.value),a=i.byteLength,o.size===ft&&(c=Et(a)));let u=new Uint8Array(s+c+a),l=0;Ke(n.code,u,l),l+=s,i!=null&&(o.size===ft&&(Ke(a,u,l),l+=c),u.set(i,l)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return kt(e,t)}function yc(r){if(r.charAt(0)!=="/")throw new dt('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=Yt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new dt(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new dt(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new dt("Incomplete multiaddr");return t}function bc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Yt.getProtocol(t.code);if(e==null)throw new dt(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function _d(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:gr(t,e)}var Ad=Symbol.for("nodejs.util.inspect.custom"),Us=Symbol.for("@multiformats/multiaddr");function Id(r){if(r==null&&(r="/"),wc(r))return r.getComponents();if(r instanceof Uint8Array)return mc(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),yc(r);if(Array.isArray(r))return r;throw new dt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var On=class r{[Us]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Id(t),e.validate!==!1&&Bd(this)}get bytes(){return this.#r==null&&(this.#r=gc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=bc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Ln(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return lt(this.bytes,t.bytes)}[Ad](){return`Multiaddr(${this.toString()})`}};function Bd(r){r.getComponents().forEach(t=>{let e=Yt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function wc(r){return!!r?.[Us]}function xc(r){return new On(r)}function $e(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Pn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Pn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Pn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Fs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Nn(r={}){return Td(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Td(r,t){t=t??{};let e=t.onEnd,n=new Ze,o,s,i,a=$e(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,h)=>{s=y=>{s=null,n.push(y);try{b(r(n))}catch(g){h(g)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=$e()})}},u=b=>s!=null?s(b):(n.push(b),o),l=b=>(n=new Ze,s!=null?s({error:b}):(n.push({error:b}),o)),d=b=>{if(i)return o;if(t?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:b})},f=b=>i?o:(i=!0,b!=null?l(b):u({done:!0})),p=()=>(n=new Ze,f(),{done:!0}),v=b=>(f(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:v,push:d,end:f,get readableLength(){return n.size},onEmpty:async b=>{let h=b?.signal;if(h?.throwIfAborted(),n.isEmpty())return;let y,g;h!=null&&(y=new Promise((w,S)=>{g=()=>{S(new Fs)},h.addEventListener("abort",g)}));try{await Promise.race([a.promise,y])}finally{g!=null&&h!=null&&h?.removeEventListener("abort",g)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(b){return x.throw(b),e!=null&&(e(b),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:d,end(b){return x.end(b),e!=null&&(e(b),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:b=>x.onEmpty(b)},o}var Ms=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Dd=r=>"reason"in r?r.reason:new DOMException("This operation was aborted.","AbortError"),Ld=2**31-1,Cd=(r,t)=>{if(typeof r!="number"||Math.sign(r)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(typeof t?.setTimeout!="function"||typeof t?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function Ks(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,u=()=>{try{r.cancel?.()}catch{}},d=new Promise((f,p)=>{let v=()=>{p(Dd(i)),u()},x=Cd(e,s);try{x?p(x):i?.aborted?v():i&&(c=v,i.addEventListener("abort",c,{once:!0}))}finally{r.then(f,p)}if(x||i?.aborted||e>Ld)return;let b=n||o===!1||o instanceof Error?void 0:new Ms(o??`Promise timed out after ${e} milliseconds`);a=s.setTimeout.call(void 0,()=>{if(n)try{f(n())}catch(h){p(h)}else o===!1?f():p(o instanceof Error?o:b);u()},e)}).finally(()=>{try{d.clear()}catch{}try{c&&i.removeEventListener("abort",c)}catch{}});return d.clear=()=>{a!==void 0&&(s.clearTimeout.call(void 0,a),a=void 0)},d}var Ec=r=>typeof r=="function"?{filter:r}:{...r},Rd=r=>r===1/0||Number.isSafeInteger(r)&&r>=0,Od=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],Pd=r=>{for(let[t,e]of Od){let n=r?.[t],o=r?.[e];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(r),removeListener:o.bind(r)}}throw new TypeError("Emitter is not compatible")},Nd=r=>{let t=new Map;for(let[e,n]of r)for(let o of Array.isArray(e)?e:[e])t.has(o)||t.set(o,n);return t},kd=({addListener:r,removeListener:t,handlers:e,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of e)if(r(i,a),s()){t(i,a);return}},Ud=({removeListener:r,handlers:t,signal:e,abortHandler:n})=>{for(let[o,s]of t)r(o,s);e?.removeEventListener("abort",n)},Fd=(r,t,e)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(t())return;let i;try{i=r?await r(o):!0}catch(a){t()||e(a);return}t()||s(i)})}};function Md(r,t,e){let n=()=>{},o=!1,s,i=new Promise((a,c)=>{e=Ec(e);let{filter:u}=e;if(!Rd(e.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof e.timeout=="number"&&!(e.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${e.timeout}\``);e.signal?.throwIfAborted();let{addListener:l,removeListener:d}=Pd(r);if(e.count===0){a([]);return}let f=[],p=w=>{n(),c(w)},v=Fd(u,()=>o,p),x=w=>{f.push(w),e.count===f.length&&(n(),a(f))},b=(...w)=>{if(o)return;let S=e.multiArgs?w:w[0];if(!u){x(S);return}v(S,I=>{I&&x(S)})},h=(...w)=>{p(e.rejectionMultiArgs?w:w[0])},y=()=>{p(e.signal.reason)},g={addListener:l,removeListener:d,handlers:Nd([[t,b],[e.rejectionEvents??["error"],h]]),signal:e.signal,abortHandler:y,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),Ud(g)},kd(g),!(o||!e.resolveImmediately)&&(Number.isFinite(e.timeout)&&e.timeout<=2**31-1&&(s=setTimeout(n,e.timeout)),a(f))});if(i.cancel=n,typeof e.timeout=="number"&&e.timeout>0&&!e.resolveImmediately){let a=Ks(i,{milliseconds:e.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function Ye(r,t,e){let n=Md(r,t,{...Ec(e),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Br(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var kn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Ae=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Kd(r){return r.reason}function Tr(r,t,e){if(t==null||r==null)return r;let n=e?.translateError??Kd;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;return Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})]).finally(()=>{o!=null&&t.removeEventListener("abort",o)})}var Un=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=$e(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Nt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function zd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Sc=new WeakMap,Fn=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,e){this.id=zd(),this.status="queued",this.fn=t,this.options=e,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((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Nt),this.cleanup())}async join(t){let e=new Un(t);return this.recipients.push(e),t?.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Tr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:e=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof e=="object"&&e!==null){let n=Sc.get(e);if(n==null&&(n=new WeakSet,Sc.set(e,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(e)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.deferred.reject(t.signal?.reason??new Nt),t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var Mn=class extends Cr{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=Br(this.emitEmpty.bind(this),1),this.emitIdle=Br(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new kn;let n=new Fn(t,e);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(e).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 Nt)}),this.clear()}async onEmpty(t){this.size!==0&&await Ye(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await Ye(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Ye(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=Nn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Nt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function Kn(r){let t=new globalThis.AbortController;function e(){let s=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}var qd=4194304,zn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},qs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Hs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Vs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Hd(r){return typeof r?.closeRead=="function"}function Vd(r){return typeof r?.close=="function"}function zs(r){return Hd(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:Vd(r)?r.status!=="open":!1}function jd(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function $d(r,t){let e=t?.maxBufferSize??qd,n=new ut,o,s=!1,i;if(!jd(r))throw new yt("Argument should be a Stream or a Multiaddr");let a=d=>{if(!s&&i==null){if(n.append(d.data),n.byteLength>e){let f=n.byteLength;n.consume(f);let p=new Dr(`Read buffer overflow - ${f} > ${e}`);i=p,o?.reject(p),queueMicrotask(()=>{r.abort(p)});return}o?.resolve()}};r.addEventListener("message",a);let c=d=>{d.error!=null?o?.reject(d.error):o?.resolve()};r.addEventListener("close",c);let u=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",u);let l={readBuffer:n,async read(d){if(s===!0)throw new zn("Stream was unwrapped");if(i!=null)throw i;if(zs(r)){if(n.byteLength===0&&d?.bytes==null)return null;if(d?.bytes!=null&&n.byteLength<d.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new Ae(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let f=d?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await Tr(o.promise,d?.signal),zs(r)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let p=d?.bytes??n.byteLength;if(n.byteLength<p){if(zs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Ae(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return l.read(d)}let v=n.sublist(0,p);return n.consume(p),v},async write(d,f){if(s===!0)throw new zn("Stream was unwrapped");r.send(d)||await Ye(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",a),r.removeEventListener("close",c),r.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n),n.consume(n.byteLength))),r}};return l}function Zd(r,t={}){let e=$d(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Et(t.maxDataLength));let n=t?.lengthDecoder??gr,o=t?.lengthEncoder??Aa;return{async read(i){let a=-1,c=new ut;for(;;){let l=await e.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(d){if(d instanceof RangeError)continue;throw d}if(a<0)throw new qs("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Vs(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Hs(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await e.read({...i,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new Ae(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Ae(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new ut(o(i.byteLength),i),a)},async writeV(i,a){let c=new ut(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function js(r,t){let e=Zd(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var qn=class extends Mn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function vc(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal},l;e?.timeout!=null&&(l=Kn([o.signal,AbortSignal.timeout(e.timeout)]),u.signal=l),s=!0,Promise.resolve().then(async()=>{await r(u)}).catch(()=>{}).finally(()=>{l!=null&&(l.aborted?l.clear():l.addEventListener("abort",()=>{l.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Br(i,e?.debounce??100),c=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{e??={},e.timeout=u},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var $s=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function _c(r){let{name:t,metrics:e}=r,n;return e!=null?n=new $s({name:t,metrics:e}):n=new Map,n}var Ac="libp2p",Ic="autonat",Bc="1.0.0";var Y;(function(r){let t;(function(f){f.DIAL="DIAL",f.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(f){f[f.DIAL=0]="DIAL",f[f.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),(function(f){f.codec=()=>ze(e)})(t=r.MessageType||(r.MessageType={}));let n;(function(f){f.OK="OK",f.E_DIAL_ERROR="E_DIAL_ERROR",f.E_DIAL_REFUSED="E_DIAL_REFUSED",f.E_BAD_REQUEST="E_BAD_REQUEST",f.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(f){f[f.OK=0]="OK",f[f.E_DIAL_ERROR=100]="E_DIAL_ERROR",f[f.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",f[f.E_BAD_REQUEST=200]="E_BAD_REQUEST",f[f.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(f){f.codec=()=>ze(o)})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(f){let p;f.codec=()=>(p==null&&(p=Vt((h,y,g={})=>{if(g.lengthDelimited!==!1&&y.fork(),h.id!=null&&(y.uint32(10),y.bytes(h.id)),h.addrs!=null&&h.addrs.length>0)for(let w of h.addrs)y.uint32(18),y.bytes(w);g.lengthDelimited!==!1&&y.ldelim()},(h,y,g={})=>{let w={addrs:[]},S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();switch(I>>>3){case 1:{w.id=h.bytes();break}case 2:{if(g.limits?.addrs!=null&&w.addrs.length===g.limits.addrs)throw new xr('Decode error - repeated field "addrs" had too many elements');w.addrs.push(h.bytes());break}default:{h.skipType(I&7);break}}}return w},function*(h,y,g,w={}){let S={addrs:0},I=y==null?h.len:h.pos+y;for(;h.pos<I;){let U=h.uint32();switch(U>>>3){case 1:{yield{field:`${g}.id`,value:h.bytes()};break}case 2:{if(w.limits?.addrs!=null&&S.addrs===w.limits.addrs)throw new xr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${g}.addrs[]`,index:S.addrs,value:h.bytes()},S.addrs++;break}default:{h.skipType(U&7);break}}}})),p);function v(h){return qt(h,f.codec())}f.encode=v;function x(h,y){return zt(h,f.codec(),y)}f.decode=x;function b(h,y){return Ht(h,f.codec(),y)}f.stream=b})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(f){let p;f.codec=()=>(p==null&&(p=Vt((h,y,g={})=>{g.lengthDelimited!==!1&&y.fork(),h.peer!=null&&(y.uint32(10),r.PeerInfo.codec().encode(h.peer,y)),g.lengthDelimited!==!1&&y.ldelim()},(h,y,g={})=>{let w={},S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();I>>>3===1?w.peer=r.PeerInfo.codec().decode(h,h.uint32(),{limits:g.limits?.peer}):h.skipType(I&7)}return w},function*(h,y,g,w={}){let S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();I>>>3===1?yield*r.PeerInfo.codec().stream(h,h.uint32(),`${g}.peer`,{limits:w.limits?.peer}):h.skipType(I&7)}})),p);function v(h){return qt(h,f.codec())}f.encode=v;function x(h,y){return zt(h,f.codec(),y)}f.decode=x;function b(h,y){return Ht(h,f.codec(),y)}f.stream=b})(i=r.Dial||(r.Dial={}));let a;(function(f){let p;f.codec=()=>(p==null&&(p=Vt((h,y,g={})=>{g.lengthDelimited!==!1&&y.fork(),h.status!=null&&(y.uint32(8),r.ResponseStatus.codec().encode(h.status,y)),h.statusText!=null&&(y.uint32(18),y.string(h.statusText)),h.addr!=null&&(y.uint32(26),y.bytes(h.addr)),g.lengthDelimited!==!1&&y.ldelim()},(h,y,g={})=>{let w={},S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();switch(I>>>3){case 1:{w.status=r.ResponseStatus.codec().decode(h);break}case 2:{w.statusText=h.string();break}case 3:{w.addr=h.bytes();break}default:{h.skipType(I&7);break}}}return w},function*(h,y,g,w={}){let S=y==null?h.len:h.pos+y;for(;h.pos<S;){let I=h.uint32();switch(I>>>3){case 1:{yield{field:`${g}.status`,value:r.ResponseStatus.codec().decode(h)};break}case 2:{yield{field:`${g}.statusText`,value:h.string()};break}case 3:{yield{field:`${g}.addr`,value:h.bytes()};break}default:{h.skipType(I&7);break}}}})),p);function v(h){return qt(h,f.codec())}f.encode=v;function x(h,y){return zt(h,f.codec(),y)}f.decode=x;function b(h,y){return Ht(h,f.codec(),y)}f.stream=b})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=Vt((f,p,v={})=>{v.lengthDelimited!==!1&&p.fork(),f.type!=null&&(p.uint32(8),r.MessageType.codec().encode(f.type,p)),f.dial!=null&&(p.uint32(18),r.Dial.codec().encode(f.dial,p)),f.dialResponse!=null&&(p.uint32(26),r.DialResponse.codec().encode(f.dialResponse,p)),v.lengthDelimited!==!1&&p.ldelim()},(f,p,v={})=>{let x={},b=p==null?f.len:f.pos+p;for(;f.pos<b;){let h=f.uint32();switch(h>>>3){case 1:{x.type=r.MessageType.codec().decode(f);break}case 2:{x.dial=r.Dial.codec().decode(f,f.uint32(),{limits:v.limits?.dial});break}case 3:{x.dialResponse=r.DialResponse.codec().decode(f,f.uint32(),{limits:v.limits?.dialResponse});break}default:{f.skipType(h&7);break}}}return x},function*(f,p,v,x={}){let b=p==null?f.len:f.pos+p;for(;f.pos<b;){let h=f.uint32();switch(h>>>3){case 1:{yield{field:`${v}.type`,value:r.MessageType.codec().decode(f)};break}case 2:{yield*r.Dial.codec().stream(f,f.uint32(),`${v}.dial`,{limits:x.limits?.dial});break}case 3:{yield*r.DialResponse.codec().stream(f,f.uint32(),`${v}.dialResponse`,{limits:x.limits?.dialResponse});break}default:{f.skipType(h&7);break}}}})),c);function u(f){return qt(f,r.codec())}r.encode=u;function l(f,p){return zt(f,r.codec(),p)}r.decode=l;function d(f,p){return Ht(f,r.codec(),p)}r.stream=d})(Y||(Y={}));var Jd=4,th=8,Hn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${e.protocolPrefix??Ac}/${Ic}/${Bc}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.connectionThreshold=e.connectionThreshold??80,this.maxMessageSize=e.maxMessageSize??8192,this.dialResults=_c({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=vc(this.findRandomPeers.bind(this),6e4),this.addressFilter=_s(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Gs]=["@libp2p/autonat"];get[Ws](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,e)=>{this.handleIncomingAutonatStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=Kn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,e){let n=AbortSignal.timeout(this.timeout);try{let o=js(t,{maxDataLength:this.maxMessageSize}).pb(Y),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,e,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(d=>Pt(d).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("peerId missing from message"),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let d=ue(a.id);i=En(d)}catch(d){return this.log.error("invalid PeerId - %e",d),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(d=>xc(d)).filter(d=>{try{let f=Pt(d);return Ls(d)?!1:f.host!==Pt(e.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",d,e.remoteAddr),!1):o.includes(f.host)?!1:this.components.transportManager.dialTransportForMultiaddr(d)==null?(this.log.trace("not dialing %a - transport unsupported",d),!1):!0}catch{return!1}}).map(d=>(d.getComponents().find(f=>f.code===421)?.value==null&&(d=d.encapsulate(`/p2p/${i.toString()}`)),d));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(d=>d.toString()).join(", "),i);let u="",l=c[0];for(let d of c){let f;l=d;try{if(f=await this.components.connectionManager.openConnection(d,n),!f.remoteAddr.equals(d))throw this.log.error("tried to dial %a but dialed %a",d,f.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,d),{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.OK,addr:f.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),u=p.message}finally{f!=null&&await f.close()}}return{type:Y.MessageType.DIAL_RESPONSE,dialResponse:{status:Y.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:l.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||Pt(o.multiaddr).type==="ip6"&&(!e||!sc(o.multiaddr))||Ls(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:xs(),queue:new qn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>Pt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=js(i).pb(Y),[,c]=await Promise.all([a.write({type:Y.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==Y.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let u=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==Y.ResponseStatus.OK&&u!==Y.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),u===Y.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===Y.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Jd&&this.confirmAddress(o),o.failure===th&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=Pt(t);switch(e.type){case"ip4":return e.host.split(".")[0].padStart(3,"0");case"ip6":return e.host.split(":")[0].padStart(4,"0");default:throw new yt(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function eh(r={}){return t=>new Hn(t,r)}return Nc(rh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|