@libp2p/autonat-v2 2.1.2-47cf9cdc1 → 2.1.2-d5534174d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonatV2 = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PAutonatV2=(()=>{var gu=Object.create;var Vr=Object.defineProperty;var yu=Object.getOwnPropertyDescriptor;var bu=Object.getOwnPropertyNames;var wu=Object.getPrototypeOf,xu=Object.prototype.hasOwnProperty;var lo=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},wt=(e,t)=>{for(var r in t)Vr(e,r,{get:t[r],enumerable:!0})},Ei=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of bu(t))!xu.call(e,o)&&o!==r&&Vr(e,o,{get:()=>t[o],enumerable:!(n=yu(t,o))||n.enumerable});return e};var Eu=(e,t,r)=>(r=e!=null?gu(wu(e)):{},Ei(t||!e||!e.__esModule?Vr(r,"default",{value:e,enumerable:!0}):r,e)),Su=e=>Ei(Vr({},"__esModule",{value:!0}),e);var Gs=lo(We=>{"use strict";Object.defineProperty(We,"__esModule",{value:!0});We.Netmask4Impl=void 0;We.ip2long=Ge;We.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 yd=48,bd=97,wd=65;function xd(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)-yd)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-bd)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-wd)>>>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 Ge(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]=xd(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 Ys=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=Ge(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=(Ge(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):(Ge(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=Ge(this.first),n=Ge(this.last),o=0;for(;r<=n;)t(Mt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};We.Netmask4Impl=Ys});var Nc=lo(Xe=>{"use strict";Object.defineProperty(Xe,"__esModule",{value:!0});Xe.Netmask6Impl=void 0;Xe.ip6bigint=Xs;Xe.bigint2ip6=_e;var Ed=Gs(),Ws=(1n<<128n)-1n;function Xs(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,Ed.ip2long)(n),s=e.substring(0,r+1)+"0:0";return kc(s)&~0xffffffffn|BigInt(o)}return kc(e)}function kc(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>Ws)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 Qs=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=Ws>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Xs(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&Ws),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):(Xs(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}};Xe.Netmask6Impl=Qs});var Fc=lo(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});ie.long2ip=ie.ip2long=ie.Netmask=void 0;var jn=Gs();Object.defineProperty(ie,"ip2long",{enumerable:!0,get:function(){return jn.ip2long}});Object.defineProperty(ie,"long2ip",{enumerable:!0,get:function(){return jn.long2ip}});var Sd=Nc(),Js=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 Sd.Netmask6Impl(t,r):this._impl=new jn.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 jn.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()}};ie.Netmask=Js});var Mh={};wt(Mh,{autoNATv2:()=>Uh});var zt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ht=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},jr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Zr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Et=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var ar=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ho=Symbol.for("@libp2p/peer-id");function Si(e){return e!=null&&typeof e.start=="function"&&typeof e.stop=="function"}async function vi(...e){let t=[];for(let r of e)Si(r)&&t.push(r);await Promise.all(t.map(async r=>{r.beforeStart!=null&&await r.beforeStart()})),await Promise.all(t.map(async r=>{await r.start()})),await Promise.all(t.map(async r=>{r.afterStart!=null&&await r.afterStart()}))}async function _i(...e){let t=[];for(let r of e)Si(r)&&t.push(r);await Promise.all(t.map(async r=>{r.beforeStop!=null&&await r.beforeStop()})),await Promise.all(t.map(async r=>{await r.stop()})),await Promise.all(t.map(async r=>{r.afterStop!=null&&await r.afterStop()}))}function vu(e){return typeof e?.handleEvent=="function"}function _u(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Te=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=_u(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#t.set(i.type,a))}vu(r)?r.handleEvent(i):r(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:o})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Yr=Symbol.for("@libp2p/service-capabilities"),Gr=Symbol.for("@libp2p/service-dependencies");var bo={};wt(bo,{base58btc:()=>J,base58flickr:()=>Lu});var gp=new Uint8Array(0);function Ii(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 St(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ce(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ce(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Bi(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var Ai=4096;function Ti(e){let t=e.length;if(t<=Ai)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=Ai));return r}function Au(e){return e?.buffer instanceof ArrayBuffer}function ce(e){return Au(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 f=e.length,l=e.charAt(0),d=Math.log(f)/Math.log(256),h=Math.log(256)/Math.log(f);function I(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var S=0,g=0,_=0,B=E.length;_!==B&&E[_]===0;)_++,S++;for(var U=(B-_)*h+1>>>0,M=new Uint8Array(U);_!==B;){for(var k=E[_],O=0,P=U-1;(k!==0||O<g)&&P!==-1;P--,O++)k+=256*M[P]>>>0,M[P]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,_++}for(var K=U-g;K!==U&&M[K]===0;)K++;for(var C=l.repeat(S);K<U;++K)C+=e.charAt(M[K]);return C}function x(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var S=0;if(E[S]!==" "){for(var g=0,_=0;E[S]===l;)g++,S++;for(var B=(E.length-S)*d+1>>>0,U=new Uint8Array(B);E[S];){var M=n[E.charCodeAt(S)];if(M===255)return;for(var k=0,O=B-1;(M!==0||k<_)&&O!==-1;O--,k++)M+=f*U[O]>>>0,U[O]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");_=k,S++}if(E[S]!==" "){for(var P=B-_;P!==B&&U[P]===0;)P++;for(var K=new Uint8Array(g+(B-P)),C=g;P!==B;)K[C++]=U[P++];return K}}}function y(E){var S=x(E);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:I,decodeUnsafe:x,decode:y}}var Bu=Iu,Tu=Bu,Ri=Tu;var po=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")}},mo=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 Ci(this,t)}},go=class{decoders;constructor(t){this.decoders=t}or(t){return Ci(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 Ci(e,t){return new go({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var yo=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 po(t,r,n),this.decoder=new mo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function De({name:e,prefix:t,encode:r,decode:n}){return new yo(e,t,r,n)}function Yt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Ri(r,e,n);return De({prefix:t,name:e,encode:o,decode:i=>St(s(i))})}function Du(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ru(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 Cu(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 Q({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Cu(n,o);return De({prefix:t,name:e,encode(i){return Ru(i,n,r)},decode(i){return Du(i,s,r,e)}})}var J=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Lu=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wo={};wt(wo,{base32:()=>Gt,base32hex:()=>Nu,base32hexpad:()=>Uu,base32hexpadupper:()=>Mu,base32hexupper:()=>Fu,base32pad:()=>Pu,base32padupper:()=>ku,base32upper:()=>Ou,base32z:()=>Ku});var Gt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Ou=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Pu=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ku=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Nu=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Fu=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Uu=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Mu=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Ku=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xo={};wt(xo,{base36:()=>cr,base36upper:()=>zu});var cr=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),zu=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var qu=Pi,Li=128,Hu=127,$u=~Hu,Vu=Math.pow(2,31);function Pi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Vu;)t[r++]=e&255|Li,e/=128;for(;e&$u;)t[r++]=e&255|Li,e>>>=7;return t[r]=e|0,Pi.bytes=r-n+1,t}var ju=Eo,Zu=128,Oi=127;function Eo(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Eo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Oi)<<o:(i&Oi)*Math.pow(2,o),o+=7}while(i>=Zu);return Eo.bytes=s-n,r}var Yu=Math.pow(2,7),Gu=Math.pow(2,14),Wu=Math.pow(2,21),Xu=Math.pow(2,28),Qu=Math.pow(2,35),Ju=Math.pow(2,42),tf=Math.pow(2,49),ef=Math.pow(2,56),rf=Math.pow(2,63),nf=function(e){return e<Yu?1:e<Gu?2:e<Wu?3:e<Xu?4:e<Qu?5:e<Ju?6:e<tf?7:e<ef?8:e<rf?9:10},of={encode:qu,decode:ju,encodingLength:nf},sf=of,ur=sf;function fr(e,t=0){let r=ur.decode(e,t),n=ur.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Re(e,t,r=0){return ur.encode(e,t,r),t}function Ce(e){return ur.encodingLength(e)}function Oe(e,t){let r=t.byteLength,n=Ce(e),o=n+Ce(r),s=new Uint8Array(o+r);return Re(e,s,0),Re(r,s,n),s.set(t,o),new Le(e,r,t,s)}function lr(e){let t=St(e),[r,n]=fr(t),[o,s]=fr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(r,o,i,t)}function ki(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ii(e.bytes,r.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=ce(n),this.bytes=ce(o)}};function Ni(e,t){let{bytes:r,version:n}=e;return n===0?cf(r,So(e),t??J.encoder):uf(r,So(e),t??Gt.encoder)}var Fi=new WeakMap;function So(e){let t=Fi.get(e);if(t==null){let r=new Map;return Fi.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,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:r}=this;if(t!==dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ff)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=Oe(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&&ki(t.multihash,n.multihash)}toString(t){return Ni(this,t)}toJSON(){return{"/":Ni(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??Ui(n,o,s.bytes))}else if(r[lf]===!0){let{version:n,multihash:o,code:s}=r,i=lr(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==dr)throw new Error(`Version 0 CID must use dag-pb (code: ${dr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ui(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,dr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=St(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 Le(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,d]=fr(t.subarray(r));return r+=d,l},o=n(),s=dr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=af(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 So(s).set(n,t),s}};function af(e,t){switch(e[0]){case"Q":{let r=t??J;return[J.prefix,r.decode(`${J.prefix}${e}`)]}case J.prefix:{let r=t??J;return[J.prefix,r.decode(e)]}case Gt.prefix:{let r=t??Gt;return[Gt.prefix,r.decode(e)]}case cr.prefix:{let r=t??cr;return[cr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function cf(e,t,r){let{prefix:n}=r;if(n!==J.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 uf(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var dr=112,ff=18;function Ui(e,t,r){let n=Ce(e),o=n+Ce(t),s=new Uint8Array(o+r.byteLength);return Re(e,s,0),Re(t,s,n),s.set(r,o),s}var lf=Symbol.for("@ipld/js-cid/CID");var vo={};wt(vo,{identity:()=>Dt});var Mi=0,df="identity",Ki=St;function hf(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 Oe(Mi,Ki(e))}var Dt={code:Mi,name:df,encode:Ki,digest:hf};function ct(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 pf(e){return e.buffer instanceof ArrayBuffer}function Rt(e){return pf(e)?e:e.slice()}async function zi(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,Rt(t),Rt(r.subarray()));return n?.signal?.throwIfAborted(),s}function mt(e=0){return new Uint8Array(e)}function ut(e=0){return new Uint8Array(e)}function mf(e){return e?.buffer instanceof ArrayBuffer}function _o(e){if(mf(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=ut(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return _o(r)}var Hi=Symbol.for("@achingbrain/uint8arraylist");function qi(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 Xr(e){return!!e?.[Hi]}var rt=class e{bufs;length;[Hi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Xr(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(Xr(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=qi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=qi(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(Xr(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,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Xr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let h=this.get(l+d);if(n[d]!==h){f=Math.max(1,d-a[h]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ut(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=mt(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=mt(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=mt(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=ut(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=mt(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=mt(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=mt(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=mt(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=mt(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(!ct(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 Ao={};wt(Ao,{base10:()=>gf});var gf=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Io={};wt(Io,{base16:()=>yf,base16upper:()=>bf});var yf=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),bf=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Bo={};wt(Bo,{base2:()=>wf});var wf=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var To={};wt(To,{base256emoji:()=>_f});var $i=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}"),xf=$i.reduce((e,t,r)=>(e[r]=t,e),[]),Ef=$i.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Sf(e){return e.reduce((t,r)=>(t+=xf[r],t),"")}function vf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ef[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var _f=De({prefix:"\u{1F680}",name:"base256emoji",encode:Sf,decode:vf});var Ro={};wt(Ro,{base64:()=>Af,base64pad:()=>If,base64url:()=>Do,base64urlpad:()=>Bf});var Af=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),If=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Do=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bf=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Co={};wt(Co,{base8:()=>Tf});var Tf=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Lo={};wt(Lo,{identity:()=>Df});var Df=De({prefix:"\0",name:"identity",encode:e=>Ti(St(e)),decode:e=>St(Bi(e))});var e0=new TextEncoder,r0=new TextDecoder;var ko={};wt(ko,{sha256:()=>hr,sha512:()=>Of});var Lf=20;function Po({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Oo(e,t,r,n,o)}var Oo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Lf,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?Vi(n,this.code,r?.truncate):n.then(o=>Vi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Vi(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 Oe(t,e)}function Zi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var hr=Po({name:"sha2-256",code:18,encode:Zi("SHA-256")}),Of=Po({name:"sha2-512",code:19,encode:Zi("SHA-512")});var pr={...Lo,...Bo,...Co,...Ao,...Io,...wo,...xo,...bo,...Ro,...To},p0={...ko,...vo};function Gi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Yi=Gi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),No=Gi("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=ut(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Pf={utf8:Yi,"utf-8":Yi,hex:pr.base16,latin1:No,ascii:No,binary:No,...pr},Qr=Pf;function Z(e,t="utf8"){let r=Qr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function tt(e,t="utf8"){let r=Qr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var kf=parseInt("11111",2),Fo=parseInt("10000000",2),Nf=parseInt("01111111",2),Wi={0:mr,1:mr,2:Ff,3:Kf,4:zf,5:Mf,6:Uf,16:mr,22:mr,48:mr};function Uo(e,t={offset:0}){let r=e[t.offset]&kf;if(t.offset++,Wi[r]!=null)return Wi[r](e,t);throw new Error("No decoder for tag "+r)}function gr(e,t){let r=0;if((e[t.offset]&Fo)===Fo){let n=e[t.offset]&Nf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");o+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function mr(e,t){gr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Uo(e,t);if(n===null)break;r.push(n)}return r}function Ff(e,t){let r=gr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Uf(e,t){let r=gr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Mf(e,t){return t.offset++,null}function Kf(e,t){let r=gr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function zf(e,t){let r=gr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function qf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Mo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=qf(e.byteLength);return new rt(Uint8Array.from([t.byteLength|Fo]),t)}function Xi(e){let t=new rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new rt(Uint8Array.from([2]),Mo(t),t)}function Qi(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),Mo(r),r)}function Jr(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),Mo(r),r)}var Hf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),$f=Uint8Array.from([6,5,43,129,4,0,34]),Vf=Uint8Array.from([6,5,43,129,4,0,35]),jf={ext:!0,kty:"EC",crv:"P-256"},Zf={ext:!0,kty:"EC",crv:"P-384"},Yf={ext:!0,kty:"EC",crv:"P-521"},Ko=32,zo=48,qo=66;function Ji(e){let t=Uo(e);return ta(t)}function ta(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ko*2+1)return n=tt(t.subarray(r,r+Ko),"base64url"),o=tt(t.subarray(r+Ko),"base64url"),new Pe({...jf,key_ops:["verify"],x:n,y:o});if(t.byteLength===zo*2+1)return n=tt(t.subarray(r,r+zo),"base64url"),o=tt(t.subarray(r+zo),"base64url"),new Pe({...Zf,key_ops:["verify"],x:n,y:o});if(t.byteLength===qo*2+1)return n=tt(t.subarray(r,r+qo),"base64url"),o=tt(t.subarray(r+qo),"base64url"),new Pe({...Yf,key_ops:["verify"],x:n,y:o});throw new ht(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ea(e){return Jr([Xi(Uint8Array.from([1])),Jr([Gf(e.crv)],160),Jr([Qi(new rt(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function Gf(e){if(e==="P-256")return Hf;if(e==="P-384")return $f;if(e==="P-521")return Vf;throw new ht(`Invalid curve ${e}`)}var Pe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ea(this.jwk)),this._raw}toMultihash(){return Dt.digest(ke(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r,n){return zi(this.jwk,r,t,n)}};var tn=BigInt(4294967295),ra=BigInt(32);function Wf(e,t=!1){return t?{h:Number(e&tn),l:Number(e>>ra&tn)}:{h:Number(e>>ra&tn)|0,l:Number(e&tn)|0}}function na(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}=Wf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Xf=e=>e/2**32|0,Qf=e=>e>>>0;function oa(e,t,r,n){let o=Xf(r),s=Qf(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var Ho=(e,t,r)=>e>>>r,$o=(e,t,r)=>e<<32-r|t>>>r,fe=(e,t,r)=>e>>>r|t<<32-r,le=(e,t,r)=>e<<32-r|t>>>r,yr=(e,t,r)=>e<<64-r|t>>>r-32,br=(e,t,r)=>e>>>r-32|t<<64-r;function Ft(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var sa=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ia=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,aa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ca=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ua=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),fa=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function en(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Vo=e=>e?`"${e}" `:"";function qt(e,t=""){if(typeof e!="number")throw new TypeError(Vo(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Vo(t)+"expected integer >= 0, got "+e);return e}function vt(e,t,r=""){if(en(e)&&(t===void 0||e.length===t))return e;t!==void 0&&qt(t,"length");let n=en(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=Vo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function rn(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(qt(e.outputLen),qt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var la=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)};function Ne(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function nn(e,t){vt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function de(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function on(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ct(e,t){return e<<32-t|e>>>t}var ha=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",tl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function sn(e){if(vt(e),ha)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=tl[e[r]];return t}function da(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function an(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(ha)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=da(e.charCodeAt(s)),a=da(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 jo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];vt(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 el(e,t,r="opts"){return la(e,"defaults"),t!==void 0&&la(t,r),Object.assign(e,t)}function Zo(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=el({},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 pa(e=32){qt(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 Yo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ma(e,t,r){return e&t^~e&r}function ga(e,t,r){return e&t^e&r^t&r}var wr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=on(this.buffer)}update(t){Ne(this),vt(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=on(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){Ne(this),nn(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)),oa(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:on(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(r),t}clone(){return this._cloneInto()}},ya=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ba=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var rl=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]),Wt=new Uint32Array(64),Go=class extends wr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let l=0;l<16;l++,r+=4)Wt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=Wt[l-15],h=Wt[l-2],I=Ct(d,7)^Ct(d,18)^d>>>3,x=Ct(h,17)^Ct(h,19)^h>>>10;Wt[l]=x+Wt[l-7]+I+Wt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Ct(a,6)^Ct(a,11)^Ct(a,25),h=f+d+ma(a,c,u)+rl[l]+Wt[l]|0,x=(Ct(n,2)^Ct(n,13)^Ct(n,22))+ga(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+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,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){de(Wt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),de(this.buffer)}},Wo=class extends Go{constructor(){super(32,ya)}};var wa=na(["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))),nl=wa[0],ol=wa[1],Xt=new Uint32Array(80),Qt=new Uint32Array(80),Xo=class extends wr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:I,Hh:x,Hl:y}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,h,I,x,y]}set(t,r,n,o,s,i,a,c,u,f,l,d,h,I,x,y){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=I|0,this.Hh=x|0,this.Hl=y|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)Xt[g]=t.getUint32(r),Qt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let _=Xt[g-15]|0,B=Qt[g-15]|0,U=fe(_,B,1)^fe(_,B,8)^Ho(_,B,7),M=le(_,B,1)^le(_,B,8)^$o(_,B,7),k=Xt[g-2]|0,O=Qt[g-2]|0,P=fe(k,O,19)^yr(k,O,61)^Ho(k,O,6),K=le(k,O,19)^br(k,O,61)^$o(k,O,6),C=aa(M,K,Qt[g-7],Qt[g-16]),j=ca(C,U,P,Xt[g-7],Xt[g-16]);Xt[g]=j|0,Qt[g]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:I,Gh:x,Gl:y,Hh:E,Hl:S}=this;for(let g=0;g<80;g++){let _=fe(l,d,14)^fe(l,d,18)^yr(l,d,41),B=le(l,d,14)^le(l,d,18)^br(l,d,41),U=l&h^~l&x,M=d&I^~d&y,k=ua(S,B,M,ol[g],Qt[g]),O=fa(k,E,_,U,nl[g],Xt[g]),P=k|0,K=fe(n,o,28)^yr(n,o,34)^yr(n,o,39),C=le(n,o,28)^br(n,o,34)^br(n,o,39),j=n&s^n&a^s&a,R=o&i^o&c^i&c;E=x|0,S=y|0,x=h|0,y=I|0,h=l|0,I=d|0,{h:l,l:d}=Ft(u|0,f|0,O|0,P|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let D=sa(P,C,R);n=ia(D,O,K,j),o=D|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:f}=Ft(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Ft(this.Eh|0,this.El|0,l|0,d|0),{h,l:I}=Ft(this.Fh|0,this.Fl|0,h|0,I|0),{h:x,l:y}=Ft(this.Gh|0,this.Gl|0,x|0,y|0),{h:E,l:S}=Ft(this.Hh|0,this.Hl|0,E|0,S|0),this.set(n,o,s,i,a,c,u,f,l,d,h,I,x,y,E,S)}roundClean(){de(Xt,Qt)}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)}},Qo=class extends Xo{constructor(){super(64,ba)}};var xa=Zo(()=>new Wo,Yo(1));var Jo=Zo(()=>new Qo,Yo(3));function un(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 H=(e,t,r)=>vt(e,t,r),ts=qt;function Sa(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Jt(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 he(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var xr=sn,_t=(...e)=>jo(...e),Fe=e=>an(e),ee=en,pe=e=>pa(e),cn=BigInt(0),Ea=BigInt(1),sl=e=>e?`"${e}" `:"";function gt(e,t=""){if(typeof e!="boolean")throw new TypeError(sl(t)+"expected boolean, got type="+typeof e);return e}function fn(e){if(typeof e=="bigint"){if(!te(e))throw new RangeError("positive bigint expected, got "+e)}else ts(e);return e}function re(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function Er(e){let t=fn(e).toString(16);return t.length&1?"0"+t:t}function va(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?cn:BigInt("0x"+e)}function Ut(e){return va(sn(e))}function me(e){return va(sn(dn(vt(e)).reverse()))}function ln(e,t){if(qt(t),t===0)throw new Error("zero output length is invalid");e=fn(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return an(n.padStart(r,"0"))}function es(e,t){return ln(e,t).reverse()}function dn(e){return Uint8Array.from(H(e))}function te(e){return typeof e=="bigint"&&cn<=e}function rs(e,t,r){return te(e)&&te(t)&&te(r)&&t<=e&&e<r}function Ue(e,t,r,n){if(!rs(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Me(e){if(e<cn)throw new Error("expected non-negative bigint, got "+e);return e===cn?0:e.toString(2).length}var Sr=e=>(re(e,"n"),(Ea<<BigInt(e))-Ea);function _a(e,t,r){if(qt(e,"hashLen"),qt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...y)=>r(u,_t(c,...y)),h=(y=o)=>{u=d(s,y),c=d(),y.length!==0&&(u=d(i,y),c=d())},I=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,E=[];for(;y<t;){c=d();let S=c.slice();E.push(S),y+=c.length}return _t(...E)};return(y,E)=>{l(),h(y);let S;for(;(S=E(I()))===void 0;)h();return l(),S}}function yt(e,t={},r={},n="object"){Jt(e,n),Jt(t,"fields"),Jt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=e[i];if(!Object.hasOwn(e,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var et=BigInt(0),$=BigInt(1),ne=BigInt(2),Ba=BigInt(3),ns=BigInt(4),Ta=BigInt(5),il=BigInt(7),Da=BigInt(8),al=BigInt(9),cl=BigInt(15),Ra=BigInt(16),ul=BigInt("0x10000000000000000");function G(e,t){if(t<=et)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=et?r:t+r}function Ca(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<et)throw new Error("invalid exponent, negatives unsupported");if(t===et)return $;if(t===$)return e;let n=e%r;if(n<et&&(n+=r),t<ul){let a=$;for(;t>et;)t&$&&(a=a*n%r),n=n*n%r,t>>=$;return a}let o=[];for(;t>et;)o.push(Number(t&cl)),t>>=ns;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 Y(e,t,r){if(r<=$)throw new Error("pow2: expected modulus > 1, got "+r);if(t<et)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >et;)n*=n,n%=r;return n}function Aa(e,t){if(e===et)throw new Error("invert: expected non-zero number");if(t<=$)throw new Error("invert: expected modulus > 1, got "+t);let r=G(e,t),n=t,o=et,s=$;for(;r!==et;){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 G(o,t)}function La(e,t){if(t<=$)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=G(e,t);if(r===et)throw new Error("invertCt: expected non-zero number");let n=Ca(r,t-ne,t);if(G(r*n,t)!==$)throw new Error("invertCt: does not exist");return n}function os(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function ss(e,t){if((e&$)===et)throw new Error(t+": expected odd modulus, got "+e)}function Oa(e,t){let r=e,n=(r.ORDER+$)/ns,o=r.pow(t,n);return os(r,o,t),o}function fl(e,t){let r=e,n=(r.ORDER-Ta)/Da,o=r.mul(t,ne),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,ne),s),c=r.mul(i,r.sub(a,r.ONE));return os(r,c,t),c}function ll(e){let t=ze(e),r=Pa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+il)/Ra;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),h=u.mul(f,s),I=u.eql(u.sqr(l),c),x=u.eql(u.sqr(d),c);f=u.cmov(f,l,I),l=u.cmov(h,d,x);let y=u.eql(u.sqr(l),c),E=u.cmov(f,l,y);return os(u,E,c),E})}function Pa(e){if(e<Ba)throw new Error("sqrt is not defined for small field");ss(e,"tonelliShanks");let t=e-$,r=0;for(;t%ne===et;)t/=ne,r++;let n=ne,o=ze(e);for(;vr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Oa;let s=o.pow(n,t),i=(t+$)/ne;return function(c,u){let f=c;if(f.is0(u))return u;if(vr(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),h=f.pow(u,t),I=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))throw new Error("Cannot find square root: probably non-prime P");let x=1,y=f.sqr(h);for(;!f.eql(y,f.ONE);)if(x++,y=f.sqr(y),x===l)throw new Error("Cannot find square root");let E=$<<BigInt(l-x-1),S=f.pow(d,E);l=x,d=f.sqr(S),h=f.mul(h,d),I=f.mul(I,S)}return I}}function dl(e){return ss(e,"Fp.sqrt"),e%ns===Ba?Oa:e%Da===Ta?fl:e%Ra===al?ll(e):Pa(e)}var ka=(e,t)=>(G(e,t)&$)===$,hl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ke(e){if(Jt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);re(e.BYTES,"BYTES"),re(e.BITS,"BITS");for(let t of hl)he(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 pn(e,t,r=!1){Ke(e),un(t,"nums"),gt(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 vr(e,t){Ke(e);let r=e;ss(r.ORDER,"FpLegendre");let n=(r.ORDER-$)/ne,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 pl(e,t){if(t!==void 0&&ts(t),e<=et)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=Me(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 Ia=new WeakMap,hn=class{ORDER;BITS;BYTES;isLE;ZERO=et;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}=pl(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 G(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return et<=t&&t<this.ORDER}is0(t){return t===et}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&$)===$}neg(t){return G(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return G(t*t,this.ORDER)}add(t,r){return G(t+r,this.ORDER)}sub(t,r){return G(t-r,this.ORDER)}mul(t,r){return G(t*r,this.ORDER)}pow(t,r){return Ca(t,r,this.ORDER)}div(t,r){return G(t*Aa(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 Aa(t,this.ORDER)}sqrt(t){let r=Ia.get(this);return r||Ia.set(this,r=dl(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?es(t,this.BYTES):ln(t,this.BYTES)}fromBytes(t,r=!1){H(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):Ut(t);if(a&&(c=G(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return pn(this,t,!0)}cmov(t,r,n){return gt(n,"condition"),n?r:t}};function ze(e,t={}){return Object.freeze(hn.prototype),new hn(e,t)}function Na(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=Me(e-$);return Math.ceil(t/8)}function mn(e){let t=Na(e);return t+Math.ceil(t/2)}function gn(e,t,r=!1){H(e);let n=e.length,o=Na(t),s=Math.max(mn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?me(e):Ut(e),a=G(i,t-$)+$;return r?es(a,o):ln(a,o)}var cs=BigInt(0),_r=BigInt(1),ml=BigInt(4),is=16,Fa=128,gl=5,Ua=2**31;function oe(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);he(t.fromAffine,"Point.fromAffine"),he(t.fromBytes,"Point.fromBytes"),he(t.fromHex,"Point.fromHex"),Jt(t.BASE,"Point.BASE"),Jt(t.ZERO,"Point.ZERO"),Ke(t.Fp),Ke(t.Fn)}function yn(e,t){oe(e),Ka(t,e);let r=pn(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function yl(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 bl(e,t){let r=e*(4*t+128);if(r>Ua)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Ua/2**20+" MiB")}function us(e,t){if(e!==void 0){he(e,"randomBytes");try{let r=e(t);if(!ee(r)||r.length!==t)return}catch{return}return e}}function Ka(e,t){un(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function wl(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):te(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var za=new WeakMap;function as(e){return za.get(e)||1}function xl(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 El(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>cs;){let i=0;e&_r&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=_r}return s}function Sl(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+=_r),a.push(u)}if(e!==cs)throw new Error("invalid wnaf");return a}function vl(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 qe=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){oe(t),this.randomBytes=us(r,is),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=t;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(t,r){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=Sl(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],d=f*i,h=Math.abs(l)-1,I=s[d];for(let y=1;y<i;y++)I=y===h?s[d+y]:I;let x=I.negate();l===0?u=u.add(s[d]):c=c.add(l<0?x:I)}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),!rs(r,_r,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=as(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+Fa,s=this.randomBytes(is);if(!ee(s)||s.length!==is)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=gl,s=1<<o,i=Sr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let h=0;h<o;h++)u=u.double();let l=Number(r>>BigInt(f*o)&i),d=a[0];for(let h=1;h<s;h++)d=h===l?a[h]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===_r?!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),!te(r))throw new Error("invalid scalar");let o=as(t);if(o===1||r>=this.Point.Fn.ORDER)return bn(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),yl(r,this.bits);let n=Math.ceil((this.bits+Fa)/r)+1;bl(n*2**(r-1),this.Point.Fp.BYTES),za.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return as(t)!==1}};function bn(e,t,r,n=!1){if(oe(e),Ka(t,e),gt(n,"allowOversized"),wl(r,e.Fn,n?e.Fn.ORDER**ml:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>xl(i,4)),s=r.map(i=>El(i,4));return vl(e.ZERO,o,s)}function Ma(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ke(t),t}else return ze(e,{isLE:r})}function wn(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`);yt(r);for(let c of["p","n","h"]){let u=t[c];if(!(te(u)&&u!==cs))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ma(t.p,r.Fp,n),s=Ma(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 xn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var En=BigInt(0),Sn=BigInt(1),vn=BigInt(2),_l=BigInt(4),qa=BigInt(8);function Al(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 Ha(e,t={}){yt(t,{},{},"extraOpts");let r=t,n=wn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(vr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(vr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");yt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?pe:r.randomBytes,u=vn<<BigInt(o.BYTES*8)-Sn;function f(S){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(S)}let l=r.uvRatio===void 0?(S,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(S,g))}}catch{return{isValid:!1,value:En}}}:r.uvRatio;if(!Al(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=o.eql(i.a,o.neg(o.ONE))?S=>o.neg(S):o.eql(i.a,o.ONE)?S=>S:S=>o.mul(i.a,S);function h(S,g,_=!1){let B=_?Sn:En;return Ue("coordinate "+S,g,B,u),g}function I(S){if(!(S 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,_,B,U){this.X=h("x",g),this.Y=h("y",_),this.Z=h("z",B,!0),this.T=h("t",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof x)throw new Error("extended point not allowed");let{x:_,y:B}=g||{};return h("x",_),h("y",B),new x(_,B,o.ONE,o.mul(_,B))}static fromBytes(g,_=!1){let B=o.BYTES,{a:U,d:M}=i;g=dn(H(g,B,"point")),gt(_,"zip215");let k=dn(g),O=g[B-1];k[B-1]=O&-129;let P=me(k),K=_?u:o.ORDER;Ue("point.y",P,En,K);let C=o.sqr(P),j=o.sub(C,o.ONE),R=o.sub(o.mulN(M,C),U),{isValid:D,value:p}=l(j,R);if(!D)throw new Error("bad point: invalid y coordinate");let b=f(p),v=(O&128)!==0;if(!_&&o.is0(p)&&v)throw new Error("bad point: x=0 and x_0=1");return v!==b&&(p=o.neg(p)),x.fromAffine({x:p,y:P})}static fromHex(g,_=!1){return x.fromBytes(Fe(g),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,_=!0){return E.setWindowSize(this,g),_||this.multiply(vn),this}assertValidity(){let g=this,{a:_,d:B}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:U,Y:M,Z:k,T:O}=g,P=o.sqr(U),K=o.sqr(M),C=o.sqr(k),j=o.sqr(C),R=o.mul(P,_),D=o.mul(o.add(R,K),C),p=o.add(j,o.mul(B,o.mul(P,K)));if(!o.eql(D,p))throw new Error("bad point: equation left != right (1)");let b=o.mul(U,M),v=o.mul(k,O);if(!o.eql(b,v))throw new Error("bad point: equation left != right (2)")}equals(g){I(g);let{X:_,Y:B,Z:U}=this,{X:M,Y:k,Z:O}=g,P=o.mul(_,O),K=o.mul(M,U),C=o.mul(B,O),j=o.mul(k,U);return o.eql(P,K)&&o.eql(C,j)}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:_,Z:B}=this,U=o.sqr(g),M=o.sqr(_),k=o.mul(o.sqr(B),vn),O=d(U),P=o.addN(g,_),K=o.sub(o.subN(o.sqr(P),U),M),C=o.addN(O,M),j=o.subN(C,k),R=o.subN(O,M),D=o.mul(K,j),p=o.mul(C,R),b=o.mul(K,R),v=o.mul(j,C);return new x(D,p,v,b)}add(g){I(g);let{d:_}=i,{X:B,Y:U,Z:M,T:k}=this,{X:O,Y:P,Z:K,T:C}=g,j=o.mul(B,O),R=o.mul(U,P),D=o.mul(o.mulN(k,_),C),p=o.mul(M,K),b=o.sub(o.subN(o.mulN(o.addN(B,U),o.addN(O,P)),j),R),v=o.subN(p,D),L=o.addN(p,D),w=o.sub(R,d(j)),m=o.mul(b,v),A=o.mul(L,w),T=o.mul(b,w),N=o.mul(v,L);return new x(m,A,N,T)}subtract(g){return I(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:_,f:B}=E.mulSecret(this,g,a,y);return y([_,B])[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===Sn?this:E.mulUnsafe(this,g,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return E.mulUnsafe(this,i.n).is0()}toAffine(g){let _=this,B=g;if(B!=null&&typeof B!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof B);let{X:U,Y:M,Z:k}=_,O=_.is0();B==null&&(B=O?o.create(qa):o.inv(k));let P=o.mul(U,B),K=o.mul(M,B),C=o.mul(k,B);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(C,o.ONE))throw new Error("invZ was invalid");return{x:P,y:K}}clearCofactor(){return a===Sn?this:a===vn?this.double():a===_l?this.double().double():a===qa?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:_}=this.toAffine(),B=o.toBytes(_);return B[B.length-1]|=f(g)?128:0,B}toHex(){return xr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=S=>yn(x,S),E=new qe(x,c);return E.bits>=6&&x.BASE.precompute(6),Object.freeze(x.prototype),Object.freeze(x),x}function $a(e,t,r={}){if(oe(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;yt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(re(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?pe:o.randomBytes,d=o.toMontgomery,h=o.toMontgomerySecret,I=o.adjustScalarBytes===void 0?R=>R:o.adjustScalarBytes,x=o.domain===void 0?(R,D,p)=>{if(gt(p,"phflag"),D.length||p)throw new Error("Contexts/pre-hash are not supported");return R}:o.domain;function y(R){return c.create(me(R))}function E(R){let D=O.secretKey;H(R,O.secretKey,"secretKey");let p=H(n(R),2*D,"hashedSecretKey"),b=I(p.slice(0,D)),v=p.slice(D,2*D),L=y(b);return{head:b,prefix:v,scalar:L}}function S(R){let{head:D,prefix:p,scalar:b}=E(R),v=i.multiply(b),L=v.toBytes();return{head:D,prefix:p,scalar:b,point:v,pointBytes:L}}function g(R){return S(R).pointBytes}function _(R=Uint8Array.of(),...D){let p=_t(...D);return y(n(x(p,H(R,void 0,"context"),!!s)))}function B(R,D,p={}){yt(p,{},{},"options"),R=H(R,void 0,"message"),s&&(R=s(R));let{prefix:b,scalar:v,pointBytes:L}=S(D),w=_(p.context,b,R),m=i.multiply(w).toBytes(),A=_(p.context,m,L,R),T=c.create(w+A*v);if(!c.isValid(T))throw new Error("sign failed: invalid s");let N=_t(m,c.toBytes(T));return H(N,O.signature,"result")}let U={zip215:o.zip215};function M(R,D,p,b=U){yt(b);let{context:v}=b,L=b.zip215===void 0?!!U.zip215:b.zip215,w=O.signature;R=H(R,w,"signature"),D=H(D,void 0,"message"),p=H(p,O.publicKey,"publicKey"),L!==void 0&&gt(L,"zip215"),s&&(D=s(D));let m=w/2,A=R.subarray(0,m),T=me(R.subarray(m,w)),N,F,q;try{N=e.fromBytes(p,L),F=e.fromBytes(A,L),q=i.multiplyUnsafe(T)}catch{return!1}if(!L&&N.isSmallOrder())return!1;let z=_(v,A,p,D);return F.add(N.multiplyUnsafe(z)).subtract(q).clearCofactor().is0()}let k=a.BYTES,O={secretKey:k,publicKey:k,signature:2*k,seed:k};function P(R){return R=R===void 0?l(O.seed):R,H(R,O.seed,"seed")}function K(R){return ee(R)&&R.length===O.secretKey}function C(R,D){try{return!!e.fromBytes(R,D===void 0?U.zip215:D)}catch{return!1}}let j={getExtendedPublicKey:S,randomSecretKey:P,isValidSecretKey:K,isValidPublicKey:C,toMontgomery(R){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(e.fromBytes(R))},toMontgomerySecret(R){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(R)}};return Object.freeze(O),Object.freeze(j),Object.freeze({keygen:xn(P,g),getPublicKey:g,sign:B,verify:M,utils:j,Point:e,lengths:O})}var fs=BigInt(1),Va=BigInt(2);var Il=BigInt(5),Bl=BigInt(8),ls=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Tl={p:ls,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Bl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Dl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ls,a=e*e%s*e%s,c=Y(a,Va,s)*a%s,u=Y(c,fs,s)*e%s,f=Y(u,Il,s)*u%s,l=Y(f,t,s)*f%s,d=Y(l,r,s)*l%s,h=Y(d,n,s)*d%s,I=Y(h,o,s)*h%s,x=Y(I,o,s)*h%s,y=Y(x,t,s)*f%s;return{pow_p_5_8:Y(y,Va,s)*e%s,b2:a}}function Ya(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var ja=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Rl(e,t){let r=ls,n=G(t*t*t,r),o=G(n*n*t,r),s=Dl(e*o).pow_p_5_8,i=G(e*n*s,r),a=G(t*i*i,r),c=i,u=G(i*ja,r),f=a===e,l=a===G(-e,r),d=a===G(-e*ja,r);return f&&(i=c),(l||d)&&(i=u),ka(i,r)&&(i=G(-i,r)),{isValid:f||l,value:i}}var ds=Ha(Tl,{uvRatio:Rl}),Za=ds.Fp;function Cl(e){let{y:t}=e;return Za.toBytes(Za.div(fs+t,fs-t))}function Ll(e){let t=ds.Fp.BYTES;return vt(e,t),Ya(Jo(e.subarray(0,t))).subarray(0,t)}function Ol(e){return $a(ds,Jo,Object.assign({adjustScalarBytes:Ya,toMontgomery:Cl,toMontgomerySecret:Ll,zip215:!0},e))}var Ga=Ol({});var Ar=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},_n=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var An={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new _n("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 In=32;var hs,Pl=(async()=>{try{return await An.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function kl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await An.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await An.get().subtle.verify({name:"Ed25519"},n,Rt(t),Rt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Nl(e,t,r){return Ga.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Wa(e,t,r){return hs==null&&(hs=await Pl),hs?kl(e,t,r):Nl(e,t,r)}function Bn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Tn=class{type="Ed25519";raw;constructor(t){this.raw=ps(t,In)}toMultihash(){return Dt.digest(ke(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Wa(this.raw,r,t);return Bn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Qa(e){return e=ps(e,In),new Tn(e)}function ps(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ht(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Ul=Math.pow(2,7),Ml=Math.pow(2,14),Kl=Math.pow(2,21),ms=Math.pow(2,28),gs=Math.pow(2,35),ys=Math.pow(2,42),bs=Math.pow(2,49),V=128,ft=127;function bt(e){if(e<Ul)return 1;if(e<Ml)return 2;if(e<Kl)return 3;if(e<ms)return 4;if(e<gs)return 5;if(e<ys)return 6;if(e<bs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function He(e,t,r=0){switch(bt(e)){case 8:t[r++]=e&255|V,e/=128;case 7:t[r++]=e&255|V,e/=128;case 6:t[r++]=e&255|V,e/=128;case 5:t[r++]=e&255|V,e/=128;case 4:t[r++]=e&255|V,e>>>=7;case 3:t[r++]=e&255|V,e>>>=7;case 2:t[r++]=e&255|V,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function zl(e,t,r=0){switch(bt(e)){case 8:t.set(r++,e&255|V),e/=128;case 7:t.set(r++,e&255|V),e/=128;case 6:t.set(r++,e&255|V),e/=128;case 5:t.set(r++,e&255|V),e/=128;case 4:t.set(r++,e&255|V),e>>>=7;case 3:t.set(r++,e&255|V),e>>>=7;case 2:t.set(r++,e&255|V),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ws(e,t){let r=e[t],n=0;if(n+=r&ft,r<V||(r=e[t+1],n+=(r&ft)<<7,r<V)||(r=e[t+2],n+=(r&ft)<<14,r<V)||(r=e[t+3],n+=(r&ft)<<21,r<V)||(r=e[t+4],n+=(r&ft)*ms,r<V)||(r=e[t+5],n+=(r&ft)*gs,r<V)||(r=e[t+6],n+=(r&ft)*ys,r<V)||(r=e[t+7],n+=(r&ft)*bs,r<V))return n;throw new RangeError("Could not decode varint")}function ql(e,t){let r=e.get(t),n=0;if(n+=r&ft,r<V||(r=e.get(t+1),n+=(r&ft)<<7,r<V)||(r=e.get(t+2),n+=(r&ft)<<14,r<V)||(r=e.get(t+3),n+=(r&ft)<<21,r<V)||(r=e.get(t+4),n+=(r&ft)*ms,r<V)||(r=e.get(t+5),n+=(r&ft)*gs,r<V)||(r=e.get(t+6),n+=(r&ft)*ys,r<V)||(r=e.get(t+7),n+=(r&ft)*bs,r<V))return n;throw new RangeError("Could not decode varint")}function Ja(e,t,r=0){return t==null&&(t=ut(bt(e))),t instanceof Uint8Array?He(e,t,r):zl(e,t,r)}function Ir(e,t=0){return e instanceof Uint8Array?ws(e,t):ql(e,t)}var xs=new Float32Array([-0]),se=new Uint8Array(xs.buffer);function ec(e,t,r){xs[0]=e,t[r]=se[0],t[r+1]=se[1],t[r+2]=se[2],t[r+3]=se[3]}function rc(e,t){return se[0]=e[t],se[1]=e[t+1],se[2]=e[t+2],se[3]=e[t+3],xs[0]}var Es=new Float64Array([-0]),lt=new Uint8Array(Es.buffer);function nc(e,t,r){Es[0]=e,t[r]=lt[0],t[r+1]=lt[1],t[r+2]=lt[2],t[r+3]=lt[3],t[r+4]=lt[4],t[r+5]=lt[5],t[r+6]=lt[6],t[r+7]=lt[7]}function oc(e,t){return lt[0]=e[t],lt[1]=e[t+1],lt[2]=e[t+2],lt[3]=e[t+3],lt[4]=e[t+4],lt[5]=e[t+5],lt[6]=e[t+6],lt[7]=e[t+7],Es[0]}var Hl=BigInt(Number.MAX_SAFE_INTEGER),$l=BigInt(Number.MIN_SAFE_INTEGER),xt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<Hl&&t>$l)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>sc&&(o=0n,++n>sc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ge}},ge=new xt(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var sc=4294967296n;function ic(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 ac(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 Ss(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 Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Dn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var vs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Rt(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Lt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Dn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Dn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=rc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=oc(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 Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ac(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(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 Lt(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 Lt(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 Lt(this,8);let t=Dn(this.buf,this.pos+=4),r=Dn(this.buf,this.pos+=4);return new xt(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=ws(this.buf,this.pos);return this.pos+=bt(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 Br(e){return new vs(e instanceof Uint8Array?e:e.subarray())}function At(e,t,r){let n=Br(e);return t.decode(n,void 0,r)}function _s(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ut(i);o+i>t&&(n=ut(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,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function As(){}var Bs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Vl=_s();function jl(e){return globalThis.Buffer!=null?ut(e):Vl(e)}var Dr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye(As,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ye(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ts((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(Rn,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=xt.fromBigInt(t);return this._push(Rn,r.length(),r)}uint64Number(t){return this._push(He,bt(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=xt.fromBigInt(t).zzEncode();return this._push(Rn,r.length(),r)}sint64Number(t){let r=xt.fromNumber(t).zzEncode();return this._push(Rn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Is,1,t?1:0)}fixed32(t){return this._push(Tr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=xt.fromBigInt(t);return this._push(Tr,4,r.lo)._push(Tr,4,r.hi)}fixed64Number(t){let r=xt.fromNumber(t);return this._push(Tr,4,r.lo)._push(Tr,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(ec,4,t)}double(t){return this._push(nc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Is,1,0):this.uint32(r)._push(Yl,r,t)}string(t){let r=ic(t);return r!==0?this.uint32(r)._push(Ss,r,t):this._push(Is,1,0)}fork(){return this.states=new Bs(this),this.head=this.tail=new ye(As,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(As,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=jl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Is(e,t,r){t[r]=e&255}function Zl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ts=class extends ye{next;constructor(t,r){super(Zl,t,r),this.next=void 0}};function Rn(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 Tr(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 Yl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Dr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Gl,t,e),this},Dr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Wl,t,e),this});function Gl(e,t,r){t.set(e,r)}function Wl(e,t,r){e.length<40?Ss(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Z(e),r)}function Ds(){return new Dr}function It(e,t){let r=Ds();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Bt(e,t,r){let n=Br(e);yield*t.stream(n,void 0,"$",r)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Ln(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function be(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return Ln("enum",Cn.VARINT,r,n,o)}function Tt(e,t,r){return Ln("message",Cn.LENGTH_DELIMITED,e,t,r)}var Rr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var pt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(pt||(pt={}));var Rs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Rs||(Rs={}));(function(e){e.codec=()=>be(Rs)})(pt||(pt={}));var Cr;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(Cr||(Cr={}));var Cs;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(Cs||(Cs={}));var On=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(rn(t),vt(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),de(o)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(this),nn(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()}},uc=(()=>{let e=((t,r,n)=>new On(t,r).update(n).digest());return e.create=(t,r)=>new On(t,r),e})();var Ql=BigInt(0),Ls=class extends Error{constructor(t=""){super(t)}},Ht={Err:Ls,_tlv:{encode:(e,t)=>{let{Err:r}=Ht;if(re(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(Sa(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Er(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Er(o.length/2|128):"";return Er(e)+s+o+t},decode(e,t){let{Err:r}=Ht;t=H(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Ht;if(fn(e),e<Ql)throw new t("integer: negative integers are not allowed");let r=Er(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Ht;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){let{Err:t,_int:r,_tlv:n}=Ht,o=H(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Ht;yt(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)}},Os=(Object.freeze(Ht._tlv),Object.freeze(Ht._int),Object.freeze(Ht));var fc=(e,t)=>(e+(e>=0?t:-t)/lc)/t;function Jl(e,t,r){Ue("scalar",e,$t,r);let[[n,o],[s,i]]=t,a=fc(i*e,r),c=fc(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<$t,d=f<$t;l&&(u=-u),d&&(f=-f);let h=Sr(Math.ceil(Me(r)/2))+we;if(u<$t||u>=h||f<$t||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Ns(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ps(e,t){yt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return gt(r.lowS,"lowS"),gt(r.prehash,"prehash"),r.format!==void 0&&Ns(r.format),r}var $t=BigInt(0),we=BigInt(1),lc=BigInt(2),ks=BigInt(3),td=BigInt(4);function dc(e,t={}){let r=wn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;yt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u}=t,f=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 l=pc(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(D,p,b){if(u&&p.is0())return Uint8Array.of(0);let{x:v,y:L}=p.toAffine(),w=n.toBytes(v);if(gt(b,"isCompressed"),b){d();let m=!n.isOdd(L);return _t(hc(m),w)}else return _t(Uint8Array.of(4),w,n.toBytes(L))}function I(D){H(D,void 0,"Point");let{publicKey:p,publicKeyUncompressed:b}=l,v=D.length,L=D[0],w=D.subarray(1);if(u&&v===1&&L===0)return{x:n.ZERO,y:n.ZERO};if(v===p&&(L===2||L===3)){let m=n.fromBytes(w);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let A=g(m),T;try{T=n.sqrt(A)}catch(q){let z=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}d();let N=n.isOdd(T);return(L&1)===1!==N&&(T=n.neg(T)),{x:m,y:T}}else if(v===b&&L===4){let m=n.BYTES,A=n.fromBytes(w.subarray(0,m)),T=n.fromBytes(w.subarray(m,m*2));if(!_(A,T))throw new Error("bad point: is not on curve");return{x:A,y:T}}else throw new Error(`bad point: got length ${v}, expected compressed=${p} or uncompressed=${b}`)}let x=t.toBytes===void 0?h:t.toBytes,y=t.fromBytes===void 0?I:t.fromBytes,E=n.mul(s.b,ks),S=n.is0(s.a)?D=>n.ZERO:D=>n.mul(s.a,D);function g(D){let p=n.sqr(D),b=n.mul(p,D);return n.add(n.add(b,n.mul(D,s.a)),s.b)}function _(D,p){let b=n.sqr(p),v=g(D);return n.eql(b,v)}if(!_(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let B=n.mul(n.pow(s.a,ks),td),U=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(B,U)))throw new Error("bad curve params: a or b");function M(D,p,b=!1){if(!n.isValid(p)||b&&n.is0(p))throw new Error(`bad point coordinate ${D}`);return p}function k(D){if(!(D instanceof C))throw new Error("Weierstrass Point expected")}function O(D){if(!c||!c.basises)throw new Error("no endo");return Jl(D,c.basises,o.ORDER)}function P(D,p,b,v){if(!o.isValid(v))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:L,k1:w,k2neg:m,k2:A}=O(v),T=new C(n.mul(b.X,c.beta),b.Y,b.Z);D.push(L?b.negate():b,m?T.negate():T),p.push(w,A)}else D.push(b),p.push(v)}let K=new WeakSet;class C{static BASE=new C(s.Gx,s.Gy,n.ONE);static ZERO=new C(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,b,v){this.X=M("x",p),this.Y=M("y",b,!0),this.Z=M("z",v),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:b,y:v}=p||{};if(!p||!n.isValid(b)||!n.isValid(v))throw new Error("invalid affine point");if(p instanceof C)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(v)?C.ZERO:new C(b,v,n.ONE)}static fromBytes(p){let b=C.fromAffine(y(H(p,void 0,"point")));return b.assertValidity(),b}static fromHex(p){return C.fromBytes(Fe(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,b=!0){return R.setWindowSize(this,p),b||this.multiply(ks),this}assertValidity(){let p=this;if(p.is0()){if(t.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(K.has(p))return;let{x:b,y:v}=p.toAffine();if(!n.isValid(b)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!_(b,v))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");K.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){k(p);let{X:b,Y:v,Z:L}=this,{X:w,Y:m,Z:A}=p,T=n.eql(n.mul(b,A),n.mul(w,L)),N=n.eql(n.mul(v,A),n.mul(m,L));return T&&N}negate(){return new C(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:b,Z:v}=this,L=n.ZERO,w=n.ZERO,m=n.ZERO,A=n.mul(p,p),T=n.mul(b,b),N=n.mul(v,v),F=n.mul(p,b);return F=n.add(F,F),m=n.mul(p,v),m=n.add(m,m),L=S(m),w=n.mul(E,N),w=n.add(L,w),L=n.sub(T,w),w=n.add(T,w),w=n.mul(L,w),L=n.mul(F,L),m=n.mul(E,m),N=S(N),F=n.sub(A,N),F=S(F),F=n.add(F,m),m=n.add(A,A),A=n.add(m,A),A=n.add(A,N),A=n.mul(A,F),w=n.add(w,A),N=n.mul(b,v),N=n.add(N,N),A=n.mul(N,F),L=n.sub(L,A),m=n.mul(N,T),m=n.add(m,m),m=n.add(m,m),new C(L,w,m)}add(p){k(p);let{X:b,Y:v,Z:L}=this,{X:w,Y:m,Z:A}=p,T=n.ZERO,N=n.ZERO,F=n.ZERO,q=n.mul(b,w),z=n.mul(v,m),W=n.mul(L,A),dt=n.add(b,v),X=n.add(w,m);dt=n.mul(dt,X),X=n.add(q,z),dt=n.sub(dt,X),X=n.add(b,L);let it=n.add(w,A);return X=n.mul(X,it),it=n.add(q,W),X=n.sub(X,it),it=n.add(v,L),T=n.add(m,A),it=n.mul(it,T),T=n.add(z,W),it=n.sub(it,T),F=S(X),T=n.mul(E,W),F=n.add(T,F),T=n.sub(z,F),F=n.add(z,F),N=n.mul(T,F),z=n.add(q,q),z=n.add(z,q),W=S(W),X=n.mul(E,X),z=n.add(z,W),W=n.sub(q,W),W=S(W),X=n.add(X,W),q=n.mul(z,X),N=n.add(N,q),q=n.mul(it,X),T=n.mul(dt,T),T=n.sub(T,q),q=n.mul(dt,z),F=n.mul(it,F),F=n.add(F,q),new C(T,N,F)}subtract(p){return k(p),this.add(p.negate())}is0(){return this.equals(C.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:b,f:v}=R.mulSecret(this,p,i,j);return j([b,v])[0]}multiplyUnsafe(p){let b=this,v=p;if(!o.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===$t||b.is0())return C.ZERO;if(v===we)return b;if(R.hasWindowSize(this))return R.mulUnsafe(b,v,j);let L=[],w=[];return P(L,w,b,v),bn(C,L,w)}mulAddUnsafe(p,b,v){k(b);let L=[],w=[];return P(L,w,this,p),P(L,w,b,v),bn(C,L,w)}toAffine(p){let b=this,v=p;if(v!=null&&!n.isValid(v))throw new RangeError('"invertedZ" expected valid field element');let{X:L,Y:w,Z:m}=b;if(n.eql(m,n.ONE))return{x:L,y:w};let A=b.is0();v==null&&(v=A?n.ONE:n.inv(m));let T=n.mul(L,v),N=n.mul(w,v),F=n.mul(m,v);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:T,y:N}}isTorsionFree(){let{isTorsionFree:p}=t;return i===we?!0:p?p(C,this):R.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=t;return i===we?this:p?p(C,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===we?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return gt(p,"isCompressed"),this.assertValidity(),x(C,this,p)}toHex(p=!0){return xr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let j=D=>yn(C,D),R=new qe(C,f);return R.bits>=6&&C.BASE.precompute(6),Object.freeze(C.prototype),Object.freeze(C),C}function hc(e){return Uint8Array.of(e?2:3)}function pc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ed(e,t={}){oe(e);let{Fn:r}=e,n=t.randomBytes===void 0?pe:t.randomBytes,o=Object.assign(pc(e.Fp,r),{seed:Math.max(mn(r.ORDER),16)});function s(h){try{let I=r.fromBytes(h);return r.isValidNot0(I)}catch{return!1}}function i(h,I){let{publicKey:x,publicKeyUncompressed:y}=o;try{let E=h.length;return I===!0&&E!==x||I===!1&&E!==y?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,gn(H(h,o.seed,"seed"),r.ORDER)}function c(h,I=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(I)}function u(h){let{secretKey:I,publicKey:x,publicKeyUncompressed:y}=o,E=r._lengths;if(!ee(h))return;let S=H(h,void 0,"key").length,g=S===x||S===y,_=S===I||!!E?.includes(S);if(!(g&&_))return g}function f(h,I,x=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(I)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(h);return e.fromBytes(I).multiply(y).toBytes(x)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=xn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:e,utils:l,lengths:o})}function mc(e,t,r={}){oe(e);let n=t;rn(n),yt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?pe:o.randomBytes,i=o.hmac===void 0?(w,m)=>uc(n,w,m):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,l=mn(u),d=us(s,l),{keygen:h,getPublicKey:I,getSharedSecret:x,utils:y,lengths:E}=ed(e,o),S={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*lc+we<a.ORDER;function _(w){let m=u>>we;return w>m}function B(w,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return m}function U(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(w,m,A){return U(),(w===A?0:2)|Number(a.isOdd(m))}function k(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(w,m){Ns(m);let A=E.signature,T=m==="compact"?A:m==="recovered"?A+1:void 0;return H(w,T)}class P{r;s;recovery;constructor(m,A,T){if(this.r=B("r",m),this.s=B("s",A),T!=null){if(k(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(m,A=S.format){O(m,A);let T;if(A==="der"){let{r:z,s:W}=Os.toSig(H(m));return new P(z,W)}A==="recovered"&&(T=m[0],A="compact",m=m.subarray(1));let N=E.signature/2,F=m.subarray(0,N),q=m.subarray(N,N*2);return new P(c.fromBytes(F),c.fromBytes(q),T)}static fromHex(m,A){return this.fromBytes(Fe(m),A)}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:A,s:T}=this,N=this.assertRecovery(),F=N===2||N===3?A+u:A;if(!a.isValid(F))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let q=a.toBytes(F),z=e.fromBytes(_t(hc((N&1)===0),q)),W=c.inv(F),dt=C(H(m,void 0,"msgHash")),X=c.create(-dt*W),it=c.create(T*W),Pt=e.BASE.mulAddUnsafe(X,z,it);if(Pt.is0())throw new Error("invalid recovery: point at infinify");return Pt.assertValidity(),Pt}hasHighS(){return _(this.s)}toBytes(m=S.format){if(Ns(m),m==="der")return Fe(Os.hexFromSig(this));let{r:A,s:T}=this,N=c.toBytes(A),F=c.toBytes(T);return m==="recovered"?(k(),_t(Uint8Array.of(this.assertRecovery()),N,F)):_t(N,F)}toHex(m){return xr(this.toBytes(m))}}Object.freeze(P.prototype),Object.freeze(P);let K=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let A=Ut(m),T=m.length*8-f;return T>0?A>>BigInt(T):A}:o.bits2int,C=o.bits2int_modN===void 0?function(m){return c.create(K(m))}:o.bits2int_modN,j=Sr(f);function R(w){return Ue("num < 2^"+f,w,$t,j),c.toBytes(w)}function D(w,m){return H(w,void 0,"message"),m?H(n(w),void 0,"prehashed message"):w}function p(w,m,A){let{lowS:T,prehash:N,extraEntropy:F}=Ps(A,S);w=D(w,N);let q=C(w),z=c.fromBytes(m);if(!c.isValidNot0(z))throw new Error("invalid private key");let W=[R(z),R(q)];if(F!=null&&F!==!1){let Pt=F===!0?s(E.secretKey):F;W.push(H(Pt,void 0,"extraEntropy"))}let dt=_t(...W),X=q;function it(Pt){let Be=K(Pt);if(!c.isValidNot0(Be))return;let sr=e.BASE.multiply(Be).toAffine(),Zt=c.create(sr.x);if(Zt===$t)return;let kt;if(d!==void 0){let ir=Ut(gn(d(l),u)),hu=c.inv(c.mul(ir,Be)),pu=c.mul(ir,X),mu=c.mul(ir,z);kt=c.create(hu*c.create(pu+mu*Zt))}else{let ir=La(Be,u);kt=c.create(ir*c.create(X+Zt*z))}if(kt===$t)return;let fo=M(sr.x,sr.y,Zt),xi=kt;return T&&_(kt)&&(xi=c.neg(kt),fo^=1),new P(Zt,xi,g?void 0:fo)}return{seed:dt,k2sig:it}}function b(w,m,A={}){let{seed:T,k2sig:N}=p(w,m,A);return _a(n.outputLen,c.BYTES,i)(T,N).toBytes(A.format)}function v(w,m,A,T={}){let{lowS:N,prehash:F,format:q}=Ps(T,S);if(A=H(A,void 0,"publicKey"),m=D(m,F),!ee(w)){let z=w instanceof P?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+z)}O(w,q);try{let z=P.fromBytes(w,q),W=e.fromBytes(A);if(N&&z.hasHighS())return!1;let{r:dt,s:X}=z,it=C(m),Pt=c.inv(X),Be=c.create(it*Pt),sr=c.create(dt*Pt),Zt=e.BASE.mulAddUnsafe(Be,W,sr);if(Zt.is0())return!1;let kt=Zt.toAffine();return!(c.create(kt.x)!==dt||q==="recovered"&&z.recovery!==M(kt.x,kt.y,dt))}catch{return!1}}function L(w,m,A={}){let{prehash:T}=Ps(A,S);return m=D(m,T),P.fromBytes(w,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:h,getPublicKey:I,getSharedSecret:x,utils:y,lengths:E,Point:e,sign:b,verify:v,recoverPublicKey:L,Signature:P,hash:n})}var Us={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},rd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var gc=BigInt(2);function nd(e){let t=Us.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=Y(f,r,t)*f%t,d=Y(l,r,t)*f%t,h=Y(d,gc,t)*u%t,I=Y(h,o,t)*h%t,x=Y(I,s,t)*I%t,y=Y(x,a,t)*x%t,E=Y(y,c,t)*y%t,S=Y(E,a,t)*x%t,g=Y(S,r,t)*f%t,_=Y(g,i,t)*I%t,B=Y(_,n,t)*u%t,U=Y(B,gc,t);if(!Fs.eql(Fs.sqr(U),e))throw new Error("Cannot find square root");return U}var Fs=ze(Us.p,{sqrt:nd}),od=dc(Us,{Fp:Fs,endo:rd}),$e=mc(od,xa);function yc(e,t,r,n){let o=hr.digest(r instanceof Uint8Array?r:r.subarray());if(Bn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),$e.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ar(String(s))});try{return n?.signal?.throwIfAborted(),$e.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Ar(String(s))}}var Pn=class{type="secp256k1";raw;_key;constructor(t){this._key=wc(t),this.raw=bc(this._key)}toMultihash(){return Dt.digest(ke(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return yc(this._key,r,t,n)}};function xc(e){return new Pn(e)}function bc(e){return $e.Point.fromBytes(e).toBytes()}function wc(e){try{return $e.Point.fromBytes(e),e}catch(t){throw new jr(String(t))}}function Ec(e){let{Type:t,Data:r}=Cr.decode(e.digest),n=r??new Uint8Array;switch(t){case pt.Ed25519:return Qa(n);case pt.secp256k1:return xc(n);case pt.ECDSA:return Ji(n);default:throw new ar}}function ke(e){return Cr.encode({Type:pt[e.type],Data:e.raw})}var Sc=Symbol.for("nodejs.util.inspect.custom"),sd=114,Lr=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()})`}[ho]=!0;toString(){return this.string==null&&(this.string=J.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(sd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ct(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ct(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Sc](){return`PeerId(${this.toString()})`}},kn=class extends Lr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Nn=class extends Lr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Fn=class extends Lr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},id=2336,Un=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Dt.digest(Z(this.url))}[Sc](){return`PeerId(${this.url})`}[ho]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(id,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=tt(t)),t.toString()===this.toString())}};function vc(e){if(cd(e))return new kn({multihash:e});if(ad(e))try{let t=Ec(e);if(t.type==="Ed25519")return new Nn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Fn({multihash:e,publicKey:t})}catch{let r=tt(e.digest);return new Un(new URL(r))}throw new Zr("Supplied PeerID Multihash is invalid")}function ad(e){return e.code===Dt.code}function cd(e){return e.code===hr.code}function Ms(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 Mn(e){let t=lr(J.decode(`z${e}`));return vc(t)}var Kn=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 Ms(this.set.entries(),t=>{let r=Mn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=Mn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ms(this.set.values(),t=>Mn(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 Ks(){return new Kn}var zs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},_c={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ac=new globalThis.TextEncoder;function ud(e,t){let r=zs[t],n=_c[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function fd(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=zs[t],o=_c[t],s=e;for(;s.length>0;){let i=Ac.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 qs(e,{size:t=32,utf8Buffer:r}={}){if(!zs[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 fd(e,t,r);e=Ac.encode(e)}return ud(e,t)}var Or={hash:e=>Number(qs(e,{size:32})),hashV:(e,t)=>ld(Or.hash(e,t))};function ld(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),Z(t,"base16")}var Hs=64,Ot=class{fp;h;seed;constructor(t,r,n,o=2){if(o>Hs)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=mt(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?ct(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 Ot))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Ot))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 Ot))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 Ot))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var dd=500,Pr=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??Or,this.seed=t.seed??xe(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=Z(t));let r=new Ot(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<dd;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=Z(t));let r=new Ot(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=Z(t));let r=new Ot(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}},hd={1:.5,2:.84,4:.95,8:.98};function pd(e=.001){return e>.002?2:e>1e-5?4:8}function Ic(e,t=.001){let r=pd(t),n=hd[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),Hs);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var zn=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??Or,this.seed=t.seed??xe(0,Math.pow(2,10)),this.filterSeries=[new Pr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=Z(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 Pr({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=Z(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=Z(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 $s(e,t=.001,r){return new zn({...Ic(e,t),...r??{}})}function kr(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 Ve(e){let t=kr(e);if(t==null)throw new ht(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var qn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Bc=45,md=15,je=new qn;function Hn(e){if(!(e.length>md))return je.new(e).parseWith(()=>je.readIPv4Addr())}function $n(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Bc))return je.new(e).parseWith(()=>je.readIPv6Addr())}function Ze(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Bc)return;let r=je.new(e).parseWith(()=>je.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function Tc(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 Dc(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 Vs(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 Rc(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 Cc(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,Ab=parseInt("0xFFFF",16),gd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Nr(e,t){t.length===ve&&e.length===Se&&Tc(t,0,11)&&(t=t.slice(12)),t.length===Se&&e.length===ve&&Dc(e,gd,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 Lc(e,t){if(typeof t=="string"&&(t=Ze(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 js(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=Se,o=Hn(t);if(o==null&&(n=ve,o=$n(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=Zs(s,8*n);return{network:Nr(o,i),mask:i}}function Zs(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 Fr=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=js(t));else{let n=Ze(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=Ze(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Zs(o,8*n.length);this.network=Nr(n,this.mask)}}contains(t){return Lc({network:this.network,mask:this.mask},t)}toString(){let t=Rc(this.mask),r=t!==-1?String(t):Cc(this.mask);return Vs(this.network)+"/"+r}};function Oc(e,t){return new Fr(e).contains(t)}function Pc(e){try{let t=Ve(e);return t.type==="ip6"?Oc("2000::/3",t.host):!1}catch{return!1}}function Ye(e){return!!Hn(e)}function Vn(e){return!!$n(e)}var Uc=Eu(Fc(),1),vd=["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"],_d=vd.map(e=>new Uc.Netmask(e));function ti(e){for(let t of _d)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 Id(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 ti(o)}function Bd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function Td(e){let t=e.split(":"),r=t[t.length-1];return ti(r)}function Dd(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 Zn(e){if(Ye(e))return ti(e);if(Ad(e))return Id(e);if(Bd(e))return Td(e);if(Vn(e))return Dd(e)}function Mc(e){try{let t=Ve(e);switch(t.type){case"ip4":case"ip6":return Zn(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var ot=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Vt=class extends Error{static name="ValidationError";name="ValidationError"},Yn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Gn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function ri(e){return t=>tt(t,e)}function ni(e){return t=>Z(t,e)}function Qe(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 Kc(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=Z(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 zc(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=Gt.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 oi(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=tt(t,"base32"),o=Qe(r);return`${n}:${o}`}var si=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 ot("Invalid byte value in IP address");t[n]=o}),t},qc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=Ye(r[n]),i;s&&(i=si(r[n]),r[n]=tt(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,tt(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 ot("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Hc=function(e){if(e.byteLength!==4)throw new ot("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},$c=function(e){if(e.byteLength!==16)throw new ot("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 ot(`Invalid IPv6 address "${r}"`)}};function Vc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ot(`Invalid IPv6 address "${e}"`)}}var ei=Object.values(pr).map(e=>e.decoder),Rd=(function(){let e=ei[0].or(ei[1]);return ei.slice(2).forEach(t=>e=e.or(t)),e})();function jc(e){return Rd.decode(e)}function Zc(e){return t=>e.encoder.encode(t)}function Cd(e){if(parseInt(e).toString()!==e)throw new Vt("Value must be an integer")}function Ld(e){if(e<0)throw new Vt("Value must be a positive integer, or zero")}function Od(e){return t=>{if(t>e)throw new Vt(`Value must be smaller than or equal to ${e}`)}}function Pd(...e){return t=>{for(let r of e)r(t)}}var Ur=Pd(Cd,Ld,Od(65535));var nt=-1,ii=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 Gn(`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)}))}},jt=new ii,wh=[{code:4,name:"ip4",size:32,valueToBytes:si,bytesToValue:Hc,validate:e=>{if(!Ye(e))throw new Vt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ae,bytesToValue:Qe,validate:Ur},{code:273,name:"udp",size:16,valueToBytes:Ae,bytesToValue:Qe,validate:Ur},{code:33,name:"dccp",size:16,valueToBytes:Ae,bytesToValue:Qe,validate:Ur},{code:41,name:"ip6",size:128,valueToBytes:qc,bytesToValue:$c,stringToValue:Vc,validate:e=>{if(!Vn(e))throw new Vt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:nt},{code:43,name:"ipcidr",size:8,bytesToValue:ri("base10"),valueToBytes:ni("base10")},{code:53,name:"dns",size:nt},{code:54,name:"dns4",size:nt},{code:55,name:"dns6",size:nt},{code:56,name:"dnsaddr",size:nt},{code:132,name:"sctp",size:16,valueToBytes:Ae,bytesToValue:Qe,validate:Ur},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:nt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:nt,bytesToValue:ri("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?ni("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:oi,valueToBytes:Kc},{code:445,name:"onion3",size:296,bytesToValue:oi,valueToBytes:zc},{code:446,name:"garlic64",size:nt},{code:447,name:"garlic32",size:nt},{code:448,name:"tls"},{code:449,name:"sni",size:nt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:nt,bytesToValue:Zc(Do),valueToBytes:jc},{code:480,name:"http"},{code:481,name:"http-path",size:nt,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:nt}];wh.forEach(e=>{jt.addProtocol(e)});function Yc(e){let t=[],r=0;for(;r<e.length;){let n=Ir(e,r),o=jt.getProtocol(n),s=bt(n),i=xh(o,e,r+s),a=0;i>0&&o.size===nt&&(a=bt(i));let c=s+a+i,u={code:n,name:o.name,bytes:Rt(e.subarray(r,r+c))};if(i>0){let f=r+s+a,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??tt(l)}t.push(u),r+=c}return t}function Gc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=jt.getProtocol(n.code),s=bt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Z(n.value),a=i.byteLength,o.size===nt&&(c=bt(a)));let u=new Uint8Array(s+c+a),f=0;He(n.code,u,f),f+=s,i!=null&&(o.size===nt&&(He(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Nt(r,t)}function Wc(e){if(e.charAt(0)!=="/")throw new ot('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=jt.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 ot(`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 ot(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ot("Incomplete multiaddr");return t}function Xc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=jt.getProtocol(t.code);if(r==null)throw new ot(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function xh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Ir(t,r)}var Eh=Symbol.for("nodejs.util.inspect.custom"),ui=Symbol.for("@multiformats/multiaddr");function Sh(e){if(e==null&&(e="/"),Qc(e))return e.getComponents();if(e instanceof Uint8Array)return Yc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Wc(e);if(Array.isArray(e))return e;throw new ot("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Wn=class e{[ui]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Sh(t),r.validate!==!1&&vh(this)}get bytes(){return this.#r==null&&(this.#r=Gc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Xc(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 Yn(`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 ct(this.bytes,t.bytes)}[Eh](){return`Multiaddr(${this.toString()})`}};function vh(e){e.getComponents().forEach(t=>{let r=jt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Qc(e){return!!e?.[ui]}function Jc(e){return new Wn(e)}function Je(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Xn=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}},tr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Xn(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 Xn(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 fi=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 _h(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 _h(e,t){t=t??{};let r=t.onEnd,n=new tr,o,s,i,a=Je(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,E)=>{s=S=>{s=null,n.push(S);try{y(e(n))}catch(g){E(g)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Je()})}},u=y=>s!=null?s(y):(n.push(y),o),f=y=>(n=new tr,s!=null?s({error:y}):(n.push({error:y}),o)),l=y=>{if(i)return o;if(t?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},d=y=>i?o:(i=!0,y!=null?f(y):u({done:!0})),h=()=>(n=new tr,d(),{done:!0}),I=y=>(d(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:I,push:l,end:d,get readableLength(){return n.size},onEmpty:async y=>{let E=y?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let S,g;E!=null&&(S=new Promise((_,B)=>{g=()=>{B(new fi)},E.addEventListener("abort",g)}));try{await Promise.race([a.promise,S])}finally{g!=null&&E!=null&&E?.removeEventListener("abort",g)}}},r==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(y){return x.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return x.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(y){return x.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return x.readableLength},onEmpty:y=>x.onEmpty(y)},o}var li=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},tu=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function di(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,f=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){d(tu(i));return}if(i&&(c=()=>{d(tu(i))},i.addEventListener("abort",c,{once:!0})),e.then(l,d),r===Number.POSITIVE_INFINITY)return;let h=new li;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(I){d(I)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?d(o):(h.message=o??`Promise timed out after ${r} milliseconds`,d(h))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Ah=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Ih(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=Ah(e),l=async(...h)=>{let I=r.multiArgs?h:h[0];if(r.filter)try{if(!await r.filter(I))return}catch(x){n(),i(x);return}c.push(I),r.count===c.length&&(n(),s(c))},d=(...h)=>{n(),i(r.rejectionMultiArgs?h:h[0])};n=()=>{for(let h of a)f(h,l);for(let h of r.rejectionEvents)a.includes(h)||f(h,d)};for(let h of a)u(h,l);for(let h of r.rejectionEvents)a.includes(h)||u(h,d);r.signal&&r.signal.addEventListener("abort",()=>{d(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=di(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function er(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Ih(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Mr(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 Jn=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 Bh(e){return e.reason}async function Kr(e,t,r){if(t==null)return e;let n=r?.translateError??Bh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var to=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=Je(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new zt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Th(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var eo=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,r){this.id=Th(),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 zt),this.cleanup())}async join(t){let r=new to(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 Kr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){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.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var ro=class extends Te{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=Mr(this.emitEmpty.bind(this),1),this.emitIdle=Mr(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 Jn;let n=new eo(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 zt)}),this.clear()}async onEmpty(t){this.size!==0&&await er(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await er(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await er(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 zt("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 zr(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 Dh=4194304,no=class extends Error{static name="UnwrappedError";name="UnwrappedError"},pi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},mi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},gi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Rh(e){return typeof e?.closeRead=="function"}function Ch(e){return typeof e?.close=="function"}function hi(e){return Rh(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Ch(e)?e.status!=="open":!1}function Lh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Oh(e,t){let r=t?.maxBufferSize??Dh,n=new rt,o,s=!1;if(!Lh(e))throw new ht("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};e.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};e.addEventListener("close",a);let c=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(s===!0)throw new no("Stream was unwrapped");if(hi(e)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Ie(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Kr(o.promise,f?.signal),hi(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let d=f?.bytes??n.byteLength;if(n.byteLength<d){if(hi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Ie(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(f)}let h=n.sublist(0,d);return n.consume(d),h},async write(f,l){if(s===!0)throw new no("Stream was unwrapped");e.send(f)||await er(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n))),e}};return u}function Ph(e,t={}){let r=Oh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=bt(t.maxDataLength));let n=t?.lengthDecoder??Ir,o=t?.lengthEncoder??Ja;return{async read(i){let a=-1,c=new rt;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new pi("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new gi(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new mi(`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 rt(o(i.byteLength),i),a)},async writeV(i,a){let c=new rt(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function rr(e,t){let r=Ph(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 oo=class extends ro{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function eu(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal},f;r?.timeout!=null&&(f=zr([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=f),s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Mr(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 yi=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 ru(e){let{name:t,metrics:r}=e,n;return r!=null?n=new yi({name:t,metrics:r}):n=new Map,n}var bi="libp2p",wi="autonat";var nu="dial-request",ou="dial-back",su=200n*1024n,iu=4096;var nr;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s={...s},s.dialDataResponse!=null&&(s.dialDataRequest=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialDataRequest!=null&&(s.dialDataResponse=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialResponse!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialRequest=void 0),s.dialRequest!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialResponse=void 0),s.dialRequest!=null&&(i.uint32(10),qr.codec().encode(s.dialRequest,i)),s.dialResponse!=null&&(i.uint32(18),Kt.codec().encode(s.dialResponse,i)),s.dialDataRequest!=null&&(i.uint32(26),Hr.codec().encode(s.dialDataRequest,i)),s.dialDataResponse!=null&&(i.uint32(34),$r.codec().encode(s.dialDataResponse,i)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.dialRequest=qr.codec().decode(s,s.uint32(),{limits:a.limits?.dialRequest});break}case 2:{c.dialResponse=Kt.codec().decode(s,s.uint32(),{limits:a.limits?.dialResponse});break}case 3:{c.dialDataRequest=Hr.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataRequest});break}case 4:{c.dialDataResponse=$r.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}return c.dialDataResponse!=null&&(delete c.dialDataRequest,delete c.dialResponse,delete c.dialRequest),c.dialDataRequest!=null&&(delete c.dialDataResponse,delete c.dialResponse,delete c.dialRequest),c.dialResponse!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialRequest),c.dialRequest!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialResponse),c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield*qr.codec().stream(s,s.uint32(),`${a}.dialRequest`,{limits:c.limits?.dialRequest});break}case 2:{yield*Kt.codec().stream(s,s.uint32(),`${a}.dialResponse`,{limits:c.limits?.dialResponse});break}case 3:{yield*Hr.codec().stream(s,s.uint32(),`${a}.dialDataRequest`,{limits:c.limits?.dialDataRequest});break}case 4:{yield*$r.codec().stream(s,s.uint32(),`${a}.dialDataResponse`,{limits:c.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(nr||(nr={}));var qr;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.addrs!=null&&s.addrs.length>0)for(let c of s.addrs)i.uint32(10),i.bytes(c);s.nonce!=null&&s.nonce!==0n&&(i.uint32(17),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrs:[],nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(a.limits?.addrs!=null&&c.addrs.length===a.limits.addrs)throw new Rr('Decode error - repeated field "addrs" had too many elements');c.addrs.push(s.bytes());break}case 2:{c.nonce=s.fixed64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={addrs:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(c.limits?.addrs!=null&&u.addrs===c.limits.addrs)throw new Rr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${a}.addrs[]`,index:u.addrs,value:s.bytes()},u.addrs++;break}case 2:{yield{field:`${a}.nonce`,value:s.fixed64()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(qr||(qr={}));var Hr;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.addrIdx!=null&&s.addrIdx!==0&&(i.uint32(8),i.uint32(s.addrIdx)),s.numBytes!=null&&s.numBytes!==0n&&(i.uint32(16),i.uint64(s.numBytes)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrIdx:0,numBytes:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.addrIdx=s.uint32();break}case 2:{c.numBytes=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.addrIdx`,value:s.uint32()};break}case 2:{yield{field:`${a}.numBytes`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(Hr||(Hr={}));var st;(function(e){e.UNUSED="UNUSED",e.E_DIAL_ERROR="E_DIAL_ERROR",e.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",e.OK="OK"})(st||(st={}));var so;(function(e){e[e.UNUSED=0]="UNUSED",e[e.E_DIAL_ERROR=100]="E_DIAL_ERROR",e[e.E_DIAL_BACK_ERROR=101]="E_DIAL_BACK_ERROR",e[e.OK=200]="OK"})(so||(so={}));(function(e){e.codec=()=>be(so)})(st||(st={}));var Kt;(function(e){let t;(function(a){a.E_INTERNAL_ERROR="E_INTERNAL_ERROR",a.E_REQUEST_REJECTED="E_REQUEST_REJECTED",a.E_DIAL_REFUSED="E_DIAL_REFUSED",a.OK="OK"})(t=e.ResponseStatus||(e.ResponseStatus={}));let r;(function(a){a[a.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",a[a.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",a[a.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",a[a.OK=200]="OK"})(r||(r={})),(function(a){a.codec=()=>be(r)})(t=e.ResponseStatus||(e.ResponseStatus={}));let n;e.codec=()=>(n==null&&(n=Tt((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&r[a.status]!==0&&(c.uint32(8),e.ResponseStatus.codec().encode(a.status,c)),a.addrIdx!=null&&a.addrIdx!==0&&(c.uint32(16),c.uint32(a.addrIdx)),a.dialStatus!=null&&so[a.dialStatus]!==0&&(c.uint32(24),st.codec().encode(a.dialStatus,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:st.UNUSED},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{f.status=e.ResponseStatus.codec().decode(a);break}case 2:{f.addrIdx=a.uint32();break}case 3:{f.dialStatus=st.codec().decode(a);break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{yield{field:`${u}.status`,value:e.ResponseStatus.codec().decode(a)};break}case 2:{yield{field:`${u}.addrIdx`,value:a.uint32()};break}case 3:{yield{field:`${u}.dialStatus`,value:st.codec().decode(a)};break}default:{a.skipType(d&7);break}}}})),n);function o(a){return It(a,e.codec())}e.encode=o;function s(a,c){return At(a,e.codec(),c)}e.decode=s;function i(a,c){return Bt(a,e.codec(),c)}e.stream=i})(Kt||(Kt={}));var $r;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.data!=null&&s.data.byteLength>0&&(i.uint32(10),i.bytes(s.data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={data:mt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.data=s.bytes():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.data`,value:s.bytes()}:s.skipType(f&7)}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})($r||($r={}));var or;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.nonce!=null&&s.nonce!==0n&&(i.uint32(9),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.nonce=s.fixed64():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.nonce`,value:s.fixed64()}:s.skipType(f&7)}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(or||(or={}));var ae;(function(e){let t;(function(a){a.OK="OK"})(t=e.DialBackStatus||(e.DialBackStatus={}));let r;(function(a){a[a.OK=0]="OK"})(r||(r={})),(function(a){a.codec=()=>be(r)})(t=e.DialBackStatus||(e.DialBackStatus={}));let n;e.codec=()=>(n==null&&(n=Tt((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&r[a.status]!==0&&(c.uint32(8),e.DialBackStatus.codec().encode(a.status,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.OK},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?f.status=e.DialBackStatus.codec().decode(a):a.skipType(d&7)}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?yield{field:`${u}.status`,value:e.DialBackStatus.codec().decode(a)}:a.skipType(d&7)}})),n);function o(a){return It(a,e.codec())}e.encode=o;function s(a,c){return At(a,e.codec(),c)}e.decode=s;function i(a,c){return Bt(a,e.codec(),c)}e.stream=i})(ae||(ae={}));function io(e,t){return Math.round(Math.random()*(t-e)+e)}var Nh=4,Fh=8,ao=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;safeDispatchEvent;constructor(t,r){this.components=t,this.safeDispatchEvent=r.safeDispatchEvent,this.log=t.logger.forComponent("libp2p:auto-nat-v2:client"),this.started=!1,this.dialRequestProtocol=r.dialRequestProtocol,this.dialBackProtocol=r.dialBackProtocol,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.connectionThreshold=r.connectionThreshold??80,this.maxMessageSize=r.maxMessageSize??8192,this.dialResults=ru({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=eu(this.findRandomPeers.bind(this),6e4),this.addressFilter=$s(1024),this.queue=new oo({concurrency:3,maxSize:50}),this.maxDialDataBytes=r.maxDialDataBytes??su,this.dialDataChunkSize=r.dialDataChunkSize??iu,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[Yr]=["@libp2p/autonat"];get[Gr](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.components.registrar.register(this.dialRequestProtocol,{onConnect:(t,r)=>{this.verifyExternalAddresses(r).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),await this.components.registrar.handle(this.dialBackProtocol,(t,r)=>{this.handleDialBackStream(t,r).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),await this.components.registrar.unhandle(this.dialBackProtocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let r=zr([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:r})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:r})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleDialBackStream(t,r){let n=AbortSignal.timeout(this.timeout);let o=rr(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read(or,{signal:n});if(!this.nonces.has(s.nonce))throw new Et("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:ae.DialBackStatus.OK},ae),await t.close({signal:n})}catch(s){this.log.error("error handling incoming dial back stream - %e",s),t.abort(s)}}getUnverifiedMultiaddrs(t,r){let n=this.components.addressManager.getAddressesWithMetadata().sort((s,i)=>s.type==="observed"&&i.type!=="observed"?1:i.type==="observed"&&s.type!=="observed"?-1:0).filter(s=>{if(!(s.expires<Date.now()))return!1;let a=kr(s.multiaddr);return!(a==null||a.type==="ip6"&&(!r||!Pc(s.multiaddr))||Mc(s.multiaddr))}),o=[];for(let s of n){let i=s.multiaddr.toString(),a=this.dialResults.get(i);if(a!=null&&a.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",a.multiaddr,t);continue}if(a==null){let c=s.expires<Date.now();if(c&&this.addressFilter.remove?.(i),this.addressFilter.has(i))continue;this.addressFilter.add(i),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",i),a={multiaddr:s.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:Ks(),type:s.type,lastVerified:s.lastVerified},this.dialResults.set(i,a)}o.push(a)}return o}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:a})=>kr(a)?.type==="ip6"),o=kr(t.remoteAddr);if(o?.type!=="ip4"&&o?.type!=="ip6")return;let s=this.getNetworkSegment(t.remoteAddr),i=this.getUnverifiedMultiaddrs(s,n);if(i.length!==0){if(!this.hasConnectionCapacity()){i[0]?.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",i[0].multiaddr),this.confirmAddress(i[0])):this.log("skipping verifying %a because we are too close to the connection limit",i[0]?.multiaddr);return}this.queue.add(async a=>{let c=zr([a.signal,AbortSignal.timeout(this.timeout)]),u=BigInt(io(0,Number.MAX_SAFE_INTEGER));this.nonces.add(u);try{await this.askPeerToVerify(t,s,u,a)}finally{c.clear(),this.nonces.delete(u)}},{peerId:t.remotePeer}).catch(a=>{this.log.error("error from %p verifying addresses - %e",t.remotePeer,a)})}}async askPeerToVerify(t,r,n,o){let s=[...this.dialResults.values()].filter(a=>a.result==null).map(a=>a.multiaddr);if(s.length===0){this.queue.clear();return}this.log.trace("asking %a to verify multiaddrs %s",t.remoteAddr,s);let i=await t.newStream(this.dialRequestProtocol,o);try{let a=rr(i).pb(nr);await a.write({dialRequest:{addrs:s.map(c=>c.bytes),nonce:n}},o);for(let c=0;c<s.length;c++){let u=await a.read(o);if(u.dialDataRequest!=null){if(u.dialDataRequest.numBytes>this.maxDialDataBytes){this.log("too many dial data byte requested by %p - %s/%s",t.remotePeer,u.dialDataRequest.numBytes,this.maxDialDataBytes);continue}this.log("sending %d bytes to %p as anti-amplification attack protection",u.dialDataRequest.numBytes,t.remotePeer);let h=new Uint8Array(this.dialDataChunkSize),I=BigInt(this.dialDataChunkSize);for(let x=0n;x<u.dialDataRequest.numBytes;x+=I)await a.write({dialDataResponse:{data:h}},o);u=await a.read(o)}if(u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}if(u.dialResponse.status!==Kt.ResponseStatus.OK)return;let l=s[u.dialResponse.addrIdx];if(l==null){this.log.trace("peer dialed unknown address");continue}let d=this.dialResults.get(l.toString());if(d==null){this.log.trace("peer reported %a as %s but there is no result object",l,u.dialResponse.status);continue}if(d.networkSegments.includes(r)){this.log.trace("%a results already included network segment %s",l,r);continue}if(d.result!=null){this.log.trace("already resolved result for %a, ignoring response from",l,t.remotePeer);continue}if(d.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,l);continue}if(d.verifyingPeers.add(t.remotePeer),d.networkSegments.push(r),u.dialResponse.dialStatus===st.OK){if(this.log.trace("%p dialed %a successfully",t.remotePeer,d.multiaddr),this.emitReachabilityEvent(d,"verifying"),d.success++,d.type!=="observed"){this.confirmAddress(d);continue}}else if(u.dialResponse.dialStatus===st.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,d.multiaddr),this.emitReachabilityEvent(d,"verifying"),d.failure++;else if(u.dialResponse.dialStatus===st.E_DIAL_BACK_ERROR){this.log.trace("%p saw error while dialing %a",t.remotePeer,d.multiaddr);continue}this.log("%a success %d failure %d",d.multiaddr,d.success,d.failure),d.success===Nh&&this.confirmAddress(d),d.failure===Fh&&this.unconfirmAddress(d)}}finally{try{await i.close(o)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let r=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return r/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,this.emitReachabilityEvent(t,"reachable")}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,this.emitReachabilityEvent(t,"unreachable")}emitReachabilityEvent(t,r){this.safeDispatchEvent(`address:${r}`,{detail:{addr:t.multiaddr,type:t.type,success:t.success,failure:t.failure}})}getNetworkSegment(t){let r=Ve(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 ht(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};var co=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:server"),this.started=!1,this.dialRequestProtocol=r.dialRequestProtocol,this.dialBackProtocol=r.dialBackProtocol,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.maxMessageSize=r.maxMessageSize??8192,this.handleDialRequestStream=this.handleDialRequestStream.bind(this)}async start(){this.started||(await this.components.registrar.handle(this.dialRequestProtocol,this.handleDialRequestStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),this.started=!1}async handleDialRequestStream(t,r){let n=AbortSignal.timeout(this.timeout);let o=rr(t,{maxDataLength:this.maxMessageSize}).pb(nr),s=lu(r.remoteAddr);if(s==null)throw new Et(`Could not find IP address in connection address "${r.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new Et("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new Et("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=Jc(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:Kt.ResponseStatus.E_DIAL_REFUSED,dialStatus:st.UNUSED}},{signal:n});continue}let f=lu(c);if(f==null)throw new Et(`Could not find IP address in requested address "${c}"`);if(Zn(f))throw new Et(`Requested address had private IP "${c}"`);f!==s&&await this.preventAmplificationAttack(o,a,{signal:n});let l=await this.dialClientBack(c,i.nonce,{signal:n});await o.write({dialResponse:{addrIdx:a,status:Kt.ResponseStatus.OK,dialStatus:l}},{signal:n})}catch(c){this.log.error("error handling incoming dialback request - %e",c)}await t.close({signal:n})}async preventAmplificationAttack(t,r,n){let o=io(3e4,1e5);await t.write({dialDataRequest:{addrIdx:r,numBytes:BigInt(o)}},n);let s=0;for(;s<o;){let{dialDataResponse:i}=await t.read(n);if(i==null)throw new Et("Did not receive DialDataResponse message on incoming dial request stream");s+=i.data.byteLength}}async dialClientBack(t,r,n){let o;try{o=await this.components.connectionManager.openConnection(t,{force:!0,...n})}catch(s){return this.log.error("failed to open connection to %a - %e",t,s),st.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=rr(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:r},or,n),(await i.read(ae,n)).status!==ae.DialBackStatus.OK)throw new Et("DialBackResponse status was not OK");await o.close(n)}catch(s){return this.log.error("could not perform dial back - %e",s),o.abort(s),st.E_DIAL_BACK_ERROR}return st.OK}};function lu(e){return e.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var uo=class extends Te{client;server;constructor(t,r){super();let n=`/${r.protocolPrefix??bi}/${wi}/${"2"}/${nu}`,o=`/${r.protocolPrefix??bi}/${wi}/${"2"}/${ou}`;this.client=new ao(t,{...r,dialRequestProtocol:n,dialBackProtocol:o,safeDispatchEvent:this.safeDispatchEvent.bind(this)}),this.server=new co(t,{...r,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[Yr]=["@libp2p/autonat"];get[Gr](){return["@libp2p/identify"]}async start(){await vi(this.client,this.server)}async stop(){await _i(this.client,this.server)}};function Uh(e={}){return t=>new uo(t,e)}return Su(Mh);})();
2
+ "use strict";var Libp2PAutonatV2=(()=>{var bu=Object.create;var Vr=Object.defineProperty;var wu=Object.getOwnPropertyDescriptor;var xu=Object.getOwnPropertyNames;var Eu=Object.getPrototypeOf,Su=Object.prototype.hasOwnProperty;var lo=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},wt=(e,t)=>{for(var r in t)Vr(e,r,{get:t[r],enumerable:!0})},Si=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of xu(t))!Su.call(e,o)&&o!==r&&Vr(e,o,{get:()=>t[o],enumerable:!(n=wu(t,o))||n.enumerable});return e};var vu=(e,t,r)=>(r=e!=null?bu(Eu(e)):{},Si(t||!e||!e.__esModule?Vr(r,"default",{value:e,enumerable:!0}):r,e)),_u=e=>Si(Vr({},"__esModule",{value:!0}),e);var Ws=lo(We=>{"use strict";Object.defineProperty(We,"__esModule",{value:!0});We.Netmask4Impl=void 0;We.ip2long=Ge;We.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 xd=48,Ed=97,Sd=65;function vd(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)-xd)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-Ed)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-Sd)>>>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 Ge(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]=vd(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 Gs=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=Ge(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=(Ge(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):(Ge(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=Ge(this.first),n=Ge(this.last),o=0;for(;r<=n;)t(Mt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};We.Netmask4Impl=Gs});var Uc=lo(Xe=>{"use strict";Object.defineProperty(Xe,"__esModule",{value:!0});Xe.Netmask6Impl=void 0;Xe.ip6bigint=Qs;Xe.bigint2ip6=_e;var _d=Ws(),Xs=(1n<<128n)-1n;function Qs(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,_d.ip2long)(n),s=e.substring(0,r+1)+"0:0";return Fc(s)&~0xffffffffn|BigInt(o)}return Fc(e)}function Fc(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>Xs)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 Js=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=Xs>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Qs(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&Xs),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):(Qs(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}};Xe.Netmask6Impl=Js});var Mc=lo(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});ie.long2ip=ie.ip2long=ie.Netmask=void 0;var jn=Ws();Object.defineProperty(ie,"ip2long",{enumerable:!0,get:function(){return jn.ip2long}});Object.defineProperty(ie,"long2ip",{enumerable:!0,get:function(){return jn.long2ip}});var Ad=Uc(),ti=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 Ad.Netmask6Impl(t,r):this._impl=new jn.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 jn.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()}};ie.Netmask=ti});var qh={};wt(qh,{autoNATv2:()=>zh});var zt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ht=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},jr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Zr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Et=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var ar=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ho=Symbol.for("@libp2p/peer-id");function vi(e){return e!=null&&typeof e.start=="function"&&typeof e.stop=="function"}async function _i(...e){let t=[];for(let r of e)vi(r)&&t.push(r);await Promise.all(t.map(async r=>{r.beforeStart!=null&&await r.beforeStart()})),await Promise.all(t.map(async r=>{await r.start()})),await Promise.all(t.map(async r=>{r.afterStart!=null&&await r.afterStart()}))}async function Ai(...e){let t=[];for(let r of e)vi(r)&&t.push(r);await Promise.all(t.map(async r=>{r.beforeStop!=null&&await r.beforeStop()})),await Promise.all(t.map(async r=>{await r.stop()})),await Promise.all(t.map(async r=>{r.afterStop!=null&&await r.afterStop()}))}function Au(e){return typeof e?.handleEvent=="function"}function Iu(e){return e===!0||e===!1}function Bu(e){return Iu(e)?e:e?.capture??!1}function po(e){let t={capture:Bu(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function Ii(e,t){return po(e).capture===po(t).capture}var Te=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=po(n);if(o?.signal?.aborted===!0)return;let s=u=>{o.once&&this.removeEventListener(t,r,o),Au(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:Ii(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&&Ii(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 Yr=Symbol.for("@libp2p/service-capabilities"),Gr=Symbol.for("@libp2p/service-dependencies");var wo={};wt(wo,{base58btc:()=>J,base58flickr:()=>ku});var wp=new Uint8Array(0);function Ti(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 St(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ce(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ce(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 Bi=4096;function Ri(e){let t=e.length;if(t<=Bi)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=Bi));return r}function Tu(e){return e?.buffer instanceof ArrayBuffer}function ce(e){return Tu(e)?e:e.slice()}function Du(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<e.length;s++){var i=e.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=e.length,l=e.charAt(0),d=Math.log(f)/Math.log(256),h=Math.log(256)/Math.log(f);function I(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var S=0,g=0,_=0,B=E.length;_!==B&&E[_]===0;)_++,S++;for(var U=(B-_)*h+1>>>0,M=new Uint8Array(U);_!==B;){for(var k=E[_],O=0,P=U-1;(k!==0||O<g)&&P!==-1;P--,O++)k+=256*M[P]>>>0,M[P]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,_++}for(var K=U-g;K!==U&&M[K]===0;)K++;for(var L=l.repeat(S);K<U;++K)L+=e.charAt(M[K]);return L}function x(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var S=0;if(E[S]!==" "){for(var g=0,_=0;E[S]===l;)g++,S++;for(var B=(E.length-S)*d+1>>>0,U=new Uint8Array(B);E[S];){var M=n[E.charCodeAt(S)];if(M===255)return;for(var k=0,O=B-1;(M!==0||k<_)&&O!==-1;O--,k++)M+=f*U[O]>>>0,U[O]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");_=k,S++}if(E[S]!==" "){for(var P=B-_;P!==B&&U[P]===0;)P++;for(var K=new Uint8Array(g+(B-P)),L=g;P!==B;)K[L++]=U[P++];return K}}}function y(E){var S=x(E);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:I,decodeUnsafe:x,decode:y}}var Ru=Du,Lu=Ru,Ci=Lu;var mo=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")}},go=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 Oi(this,t)}},yo=class{decoders;constructor(t){this.decoders=t}or(t){return Oi(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 Oi(e,t){return new yo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var bo=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 mo(t,r,n),this.decoder=new go(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function De({name:e,prefix:t,encode:r,decode:n}){return new bo(e,t,r,n)}function Yt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Ci(r,e,n);return De({prefix:t,name:e,encode:o,decode:i=>St(s(i))})}function Cu(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ou(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 Pu(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 Q({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Pu(n,o);return De({prefix:t,name:e,encode(i){return Ou(i,n,r)},decode(i){return Cu(i,s,r,e)}})}var J=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ku=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xo={};wt(xo,{base32:()=>Gt,base32hex:()=>Mu,base32hexpad:()=>zu,base32hexpadupper:()=>qu,base32hexupper:()=>Ku,base32pad:()=>Fu,base32padupper:()=>Uu,base32upper:()=>Nu,base32z:()=>Hu});var Gt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Nu=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Fu=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Uu=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Mu=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Ku=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),zu=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),qu=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Hu=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Eo={};wt(Eo,{base36:()=>cr,base36upper:()=>$u});var cr=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),$u=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Vu=Ni,Pi=128,ju=127,Zu=~ju,Yu=Math.pow(2,31);function Ni(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Yu;)t[r++]=e&255|Pi,e/=128;for(;e&Zu;)t[r++]=e&255|Pi,e>>>=7;return t[r]=e|0,Ni.bytes=r-n+1,t}var Gu=So,Wu=128,ki=127;function So(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw So.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ki)<<o:(i&ki)*Math.pow(2,o),o+=7}while(i>=Wu);return So.bytes=s-n,r}var Xu=Math.pow(2,7),Qu=Math.pow(2,14),Ju=Math.pow(2,21),tf=Math.pow(2,28),ef=Math.pow(2,35),rf=Math.pow(2,42),nf=Math.pow(2,49),of=Math.pow(2,56),sf=Math.pow(2,63),af=function(e){return e<Xu?1:e<Qu?2:e<Ju?3:e<tf?4:e<ef?5:e<rf?6:e<nf?7:e<of?8:e<sf?9:10},cf={encode:Vu,decode:Gu,encodingLength:af},uf=cf,ur=uf;function fr(e,t=0){let r=ur.decode(e,t),n=ur.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Re(e,t,r=0){return ur.encode(e,t,r),t}function Le(e){return ur.encodingLength(e)}function Oe(e,t){let r=t.byteLength,n=Le(e),o=n+Le(r),s=new Uint8Array(o+r);return Re(e,s,0),Re(r,s,n),s.set(t,o),new Ce(e,r,t,s)}function lr(e){let t=St(e),[r,n]=fr(t),[o,s]=fr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ce(r,o,i,t)}function Fi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ti(e.bytes,r.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=ce(n),this.bytes=ce(o)}};function Ui(e,t){let{bytes:r,version:n}=e;return n===0?lf(r,vo(e),t??J.encoder):df(r,vo(e),t??Gt.encoder)}var Mi=new WeakMap;function vo(e){let t=Mi.get(e);if(t==null){let r=new Map;return Mi.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,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:r}=this;if(t!==dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==hf)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=Oe(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&&Fi(t.multihash,n.multihash)}toString(t){return Ui(this,t)}toJSON(){return{"/":Ui(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??Ki(n,o,s.bytes))}else if(r[pf]===!0){let{version:n,multihash:o,code:s}=r,i=lr(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==dr)throw new Error(`Version 0 CID must use dag-pb (code: ${dr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ki(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,dr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=St(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 Ce(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,d]=fr(t.subarray(r));return r+=d,l},o=n(),s=dr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=ff(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 vo(s).set(n,t),s}};function ff(e,t){switch(e[0]){case"Q":{let r=t??J;return[J.prefix,r.decode(`${J.prefix}${e}`)]}case J.prefix:{let r=t??J;return[J.prefix,r.decode(e)]}case Gt.prefix:{let r=t??Gt;return[Gt.prefix,r.decode(e)]}case cr.prefix:{let r=t??cr;return[cr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function lf(e,t,r){let{prefix:n}=r;if(n!==J.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 df(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var dr=112,hf=18;function Ki(e,t,r){let n=Le(e),o=n+Le(t),s=new Uint8Array(o+r.byteLength);return Re(e,s,0),Re(t,s,n),s.set(r,o),s}var pf=Symbol.for("@ipld/js-cid/CID");var _o={};wt(_o,{identity:()=>Dt});var zi=0,mf="identity",qi=St;function gf(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 Oe(zi,qi(e))}var Dt={code:zi,name:mf,encode:qi,digest:gf};function ct(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 yf(e){return e.buffer instanceof ArrayBuffer}function Rt(e){return yf(e)?e:e.slice()}async function Hi(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,Rt(t),Rt(r.subarray()));return n?.signal?.throwIfAborted(),s}function mt(e=0){return new Uint8Array(e)}function ut(e=0){return new Uint8Array(e)}function bf(e){return e?.buffer instanceof ArrayBuffer}function Ao(e){if(bf(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=ut(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return Ao(r)}var Vi=Symbol.for("@achingbrain/uint8arraylist");function $i(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 Xr(e){return!!e?.[Vi]}var rt=class e{bufs;length;[Vi]=!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(Xr(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(Xr(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=$i(this.bufs,t);return r.buf[r.index]}set(t,r){let n=$i(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(Xr(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,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Xr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let h=this.get(l+d);if(n[d]!==h){f=Math.max(1,d-a[h]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ut(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=mt(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=mt(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=mt(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=ut(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=mt(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=mt(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=mt(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=mt(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=mt(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(!ct(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 Io={};wt(Io,{base10:()=>wf});var wf=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Bo={};wt(Bo,{base16:()=>xf,base16upper:()=>Ef});var xf=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Ef=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var To={};wt(To,{base2:()=>Sf});var Sf=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Do={};wt(Do,{base256emoji:()=>Bf});var ji=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}"),vf=ji.reduce((e,t,r)=>(e[r]=t,e),[]),_f=ji.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Af(e){return e.reduce((t,r)=>(t+=vf[r],t),"")}function If(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=_f[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Bf=De({prefix:"\u{1F680}",name:"base256emoji",encode:Af,decode:If});var Lo={};wt(Lo,{base64:()=>Tf,base64pad:()=>Df,base64url:()=>Ro,base64urlpad:()=>Rf});var Tf=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Df=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ro=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Rf=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Co={};wt(Co,{base8:()=>Lf});var Lf=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Oo={};wt(Oo,{identity:()=>Cf});var Cf=De({prefix:"\0",name:"identity",encode:e=>Ri(St(e)),decode:e=>St(Di(e))});var o0=new TextEncoder,s0=new TextDecoder;var No={};wt(No,{sha256:()=>hr,sha512:()=>Nf});var kf=20;function ko({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Po(e,t,r,n,o)}var Po=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??kf,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?Zi(n,this.code,r?.truncate):n.then(o=>Zi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Zi(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 Oe(t,e)}function Gi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var hr=ko({name:"sha2-256",code:18,encode:Gi("SHA-256")}),Nf=ko({name:"sha2-512",code:19,encode:Gi("SHA-512")});var pr={...Oo,...To,...Co,...Io,...Bo,...xo,...Eo,...wo,...Lo,...Do},y0={...No,..._o};function Xi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Wi=Xi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fo=Xi("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=ut(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ff={utf8:Wi,"utf-8":Wi,hex:pr.base16,latin1:Fo,ascii:Fo,binary:Fo,...pr},Qr=Ff;function Z(e,t="utf8"){let r=Qr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function tt(e,t="utf8"){let r=Qr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Uf=parseInt("11111",2),Uo=parseInt("10000000",2),Mf=parseInt("01111111",2),Qi={0:mr,1:mr,2:Kf,3:Hf,4:$f,5:qf,6:zf,16:mr,22:mr,48:mr};function Mo(e,t={offset:0}){let r=e[t.offset]&Uf;if(t.offset++,Qi[r]!=null)return Qi[r](e,t);throw new Error("No decoder for tag "+r)}function gr(e,t){let r=0;if((e[t.offset]&Uo)===Uo){let n=e[t.offset]&Mf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");o+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function mr(e,t){gr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Mo(e,t);if(n===null)break;r.push(n)}return r}function Kf(e,t){let r=gr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function zf(e,t){let r=gr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function qf(e,t){return t.offset++,null}function Hf(e,t){let r=gr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function $f(e,t){let r=gr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Vf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Ko(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Vf(e.byteLength);return new rt(Uint8Array.from([t.byteLength|Uo]),t)}function Ji(e){let t=new rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new rt(Uint8Array.from([2]),Ko(t),t)}function ta(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),Ko(r),r)}function Jr(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),Ko(r),r)}var jf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Zf=Uint8Array.from([6,5,43,129,4,0,34]),Yf=Uint8Array.from([6,5,43,129,4,0,35]),Gf={ext:!0,kty:"EC",crv:"P-256"},Wf={ext:!0,kty:"EC",crv:"P-384"},Xf={ext:!0,kty:"EC",crv:"P-521"},zo=32,qo=48,Ho=66;function ea(e){let t=Mo(e);return ra(t)}function ra(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===zo*2+1)return n=tt(t.subarray(r,r+zo),"base64url"),o=tt(t.subarray(r+zo),"base64url"),new Pe({...Gf,key_ops:["verify"],x:n,y:o});if(t.byteLength===qo*2+1)return n=tt(t.subarray(r,r+qo),"base64url"),o=tt(t.subarray(r+qo),"base64url"),new Pe({...Wf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ho*2+1)return n=tt(t.subarray(r,r+Ho),"base64url"),o=tt(t.subarray(r+Ho),"base64url"),new Pe({...Xf,key_ops:["verify"],x:n,y:o});throw new ht(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function na(e){return Jr([Ji(Uint8Array.from([1])),Jr([Qf(e.crv)],160),Jr([ta(new rt(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function Qf(e){if(e==="P-256")return jf;if(e==="P-384")return Zf;if(e==="P-521")return Yf;throw new ht(`Invalid curve ${e}`)}var Pe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=na(this.jwk)),this._raw}toMultihash(){return Dt.digest(ke(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r,n){return Hi(this.jwk,r,t,n)}};var tn=BigInt(4294967295),oa=BigInt(32);function Jf(e,t=!1){return t?{h:Number(e&tn),l:Number(e>>oa&tn)}:{h:Number(e>>oa&tn)|0,l:Number(e&tn)|0}}function sa(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}=Jf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var tl=e=>e/2**32|0,el=e=>e>>>0;function ia(e,t,r,n){let o=tl(r),s=el(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var $o=(e,t,r)=>e>>>r,Vo=(e,t,r)=>e<<32-r|t>>>r,fe=(e,t,r)=>e>>>r|t<<32-r,le=(e,t,r)=>e<<32-r|t>>>r,yr=(e,t,r)=>e<<64-r|t>>>r-32,br=(e,t,r)=>e>>>r-32|t<<64-r;function Ft(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var aa=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ca=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ua=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),fa=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,la=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),da=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function en(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var jo=e=>e?`"${e}" `:"";function qt(e,t=""){if(typeof e!="number")throw new TypeError(jo(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(jo(t)+"expected integer >= 0, got "+e);return e}function vt(e,t,r=""){if(en(e)&&(t===void 0||e.length===t))return e;t!==void 0&&qt(t,"length");let n=en(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=jo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function rn(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(qt(e.outputLen),qt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var ha=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)};function Ne(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function nn(e,t){vt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function de(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function on(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Lt(e,t){return e<<32-t|e>>>t}var ma=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",nl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function sn(e){if(vt(e),ma)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=nl[e[r]];return t}function pa(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function an(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(ma)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=pa(e.charCodeAt(s)),a=pa(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 Zo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];vt(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 ol(e,t,r="opts"){return ha(e,"defaults"),t!==void 0&&ha(t,r),Object.assign(e,t)}function Yo(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=ol({},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 ga(e=32){qt(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 Go=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ya(e,t,r){return e&t^~e&r}function ba(e,t,r){return e&t^e&r^t&r}var wr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=on(this.buffer)}update(t){Ne(this),vt(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=on(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){Ne(this),nn(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)),ia(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:on(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(r),t}clone(){return this._cloneInto()}},wa=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var xa=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var sl=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]),Wt=new Uint32Array(64),Wo=class extends wr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let l=0;l<16;l++,r+=4)Wt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=Wt[l-15],h=Wt[l-2],I=Lt(d,7)^Lt(d,18)^d>>>3,x=Lt(h,17)^Lt(h,19)^h>>>10;Wt[l]=x+Wt[l-7]+I+Wt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Lt(a,6)^Lt(a,11)^Lt(a,25),h=f+d+ya(a,c,u)+sl[l]+Wt[l]|0,x=(Lt(n,2)^Lt(n,13)^Lt(n,22))+ba(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+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,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){de(Wt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),de(this.buffer)}},Xo=class extends Wo{constructor(){super(32,wa)}};var Ea=sa(["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))),il=Ea[0],al=Ea[1],Xt=new Uint32Array(80),Qt=new Uint32Array(80),Qo=class extends wr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:I,Hh:x,Hl:y}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,h,I,x,y]}set(t,r,n,o,s,i,a,c,u,f,l,d,h,I,x,y){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=I|0,this.Hh=x|0,this.Hl=y|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)Xt[g]=t.getUint32(r),Qt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let _=Xt[g-15]|0,B=Qt[g-15]|0,U=fe(_,B,1)^fe(_,B,8)^$o(_,B,7),M=le(_,B,1)^le(_,B,8)^Vo(_,B,7),k=Xt[g-2]|0,O=Qt[g-2]|0,P=fe(k,O,19)^yr(k,O,61)^$o(k,O,6),K=le(k,O,19)^br(k,O,61)^Vo(k,O,6),L=ua(M,K,Qt[g-7],Qt[g-16]),j=fa(L,U,P,Xt[g-7],Xt[g-16]);Xt[g]=j|0,Qt[g]=L|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:I,Gh:x,Gl:y,Hh:E,Hl:S}=this;for(let g=0;g<80;g++){let _=fe(l,d,14)^fe(l,d,18)^yr(l,d,41),B=le(l,d,14)^le(l,d,18)^br(l,d,41),U=l&h^~l&x,M=d&I^~d&y,k=la(S,B,M,al[g],Qt[g]),O=da(k,E,_,U,il[g],Xt[g]),P=k|0,K=fe(n,o,28)^yr(n,o,34)^yr(n,o,39),L=le(n,o,28)^br(n,o,34)^br(n,o,39),j=n&s^n&a^s&a,R=o&i^o&c^i&c;E=x|0,S=y|0,x=h|0,y=I|0,h=l|0,I=d|0,{h:l,l:d}=Ft(u|0,f|0,O|0,P|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let D=aa(P,L,R);n=ca(D,O,K,j),o=D|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:f}=Ft(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Ft(this.Eh|0,this.El|0,l|0,d|0),{h,l:I}=Ft(this.Fh|0,this.Fl|0,h|0,I|0),{h:x,l:y}=Ft(this.Gh|0,this.Gl|0,x|0,y|0),{h:E,l:S}=Ft(this.Hh|0,this.Hl|0,E|0,S|0),this.set(n,o,s,i,a,c,u,f,l,d,h,I,x,y,E,S)}roundClean(){de(Xt,Qt)}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)}},Jo=class extends Qo{constructor(){super(64,xa)}};var Sa=Yo(()=>new Xo,Go(1));var ts=Yo(()=>new Jo,Go(3));function un(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 H=(e,t,r)=>vt(e,t,r),es=qt;function _a(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Jt(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 he(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var xr=sn,_t=(...e)=>Zo(...e),Fe=e=>an(e),ee=en,pe=e=>ga(e),cn=BigInt(0),va=BigInt(1),cl=e=>e?`"${e}" `:"";function gt(e,t=""){if(typeof e!="boolean")throw new TypeError(cl(t)+"expected boolean, got type="+typeof e);return e}function fn(e){if(typeof e=="bigint"){if(!te(e))throw new RangeError("positive bigint expected, got "+e)}else es(e);return e}function re(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function Er(e){let t=fn(e).toString(16);return t.length&1?"0"+t:t}function Aa(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?cn:BigInt("0x"+e)}function Ut(e){return Aa(sn(e))}function me(e){return Aa(sn(dn(vt(e)).reverse()))}function ln(e,t){if(qt(t),t===0)throw new Error("zero output length is invalid");e=fn(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return an(n.padStart(r,"0"))}function rs(e,t){return ln(e,t).reverse()}function dn(e){return Uint8Array.from(H(e))}function te(e){return typeof e=="bigint"&&cn<=e}function ns(e,t,r){return te(e)&&te(t)&&te(r)&&t<=e&&e<r}function Ue(e,t,r,n){if(!ns(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Me(e){if(e<cn)throw new Error("expected non-negative bigint, got "+e);return e===cn?0:e.toString(2).length}var Sr=e=>(re(e,"n"),(va<<BigInt(e))-va);function Ia(e,t,r){if(qt(e,"hashLen"),qt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...y)=>r(u,_t(c,...y)),h=(y=o)=>{u=d(s,y),c=d(),y.length!==0&&(u=d(i,y),c=d())},I=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,E=[];for(;y<t;){c=d();let S=c.slice();E.push(S),y+=c.length}return _t(...E)};return(y,E)=>{l(),h(y);let S;for(;(S=E(I()))===void 0;)h();return l(),S}}function yt(e,t={},r={},n="object"){Jt(e,n),Jt(t,"fields"),Jt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=e[i];if(!Object.hasOwn(e,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var et=BigInt(0),$=BigInt(1),ne=BigInt(2),Da=BigInt(3),os=BigInt(4),Ra=BigInt(5),ul=BigInt(7),La=BigInt(8),fl=BigInt(9),ll=BigInt(15),Ca=BigInt(16),dl=BigInt("0x10000000000000000");function G(e,t){if(t<=et)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=et?r:t+r}function Oa(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<et)throw new Error("invalid exponent, negatives unsupported");if(t===et)return $;if(t===$)return e;let n=e%r;if(n<et&&(n+=r),t<dl){let a=$;for(;t>et;)t&$&&(a=a*n%r),n=n*n%r,t>>=$;return a}let o=[];for(;t>et;)o.push(Number(t&ll)),t>>=os;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 Y(e,t,r){if(r<=$)throw new Error("pow2: expected modulus > 1, got "+r);if(t<et)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >et;)n*=n,n%=r;return n}function Ba(e,t){if(e===et)throw new Error("invert: expected non-zero number");if(t<=$)throw new Error("invert: expected modulus > 1, got "+t);let r=G(e,t),n=t,o=et,s=$;for(;r!==et;){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 G(o,t)}function Pa(e,t){if(t<=$)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=G(e,t);if(r===et)throw new Error("invertCt: expected non-zero number");let n=Oa(r,t-ne,t);if(G(r*n,t)!==$)throw new Error("invertCt: does not exist");return n}function ss(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function is(e,t){if((e&$)===et)throw new Error(t+": expected odd modulus, got "+e)}function ka(e,t){let r=e,n=(r.ORDER+$)/os,o=r.pow(t,n);return ss(r,o,t),o}function hl(e,t){let r=e,n=(r.ORDER-Ra)/La,o=r.mul(t,ne),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,ne),s),c=r.mul(i,r.sub(a,r.ONE));return ss(r,c,t),c}function pl(e){let t=ze(e),r=Na(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+ul)/Ca;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),h=u.mul(f,s),I=u.eql(u.sqr(l),c),x=u.eql(u.sqr(d),c);f=u.cmov(f,l,I),l=u.cmov(h,d,x);let y=u.eql(u.sqr(l),c),E=u.cmov(f,l,y);return ss(u,E,c),E})}function Na(e){if(e<Da)throw new Error("sqrt is not defined for small field");is(e,"tonelliShanks");let t=e-$,r=0;for(;t%ne===et;)t/=ne,r++;let n=ne,o=ze(e);for(;vr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ka;let s=o.pow(n,t),i=(t+$)/ne;return function(c,u){let f=c;if(f.is0(u))return u;if(vr(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),h=f.pow(u,t),I=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))throw new Error("Cannot find square root: probably non-prime P");let x=1,y=f.sqr(h);for(;!f.eql(y,f.ONE);)if(x++,y=f.sqr(y),x===l)throw new Error("Cannot find square root");let E=$<<BigInt(l-x-1),S=f.pow(d,E);l=x,d=f.sqr(S),h=f.mul(h,d),I=f.mul(I,S)}return I}}function ml(e){return is(e,"Fp.sqrt"),e%os===Da?ka:e%La===Ra?hl:e%Ca===fl?pl(e):Na(e)}var Fa=(e,t)=>(G(e,t)&$)===$,gl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ke(e){if(Jt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);re(e.BYTES,"BYTES"),re(e.BITS,"BITS");for(let t of gl)he(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 pn(e,t,r=!1){Ke(e),un(t,"nums"),gt(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 vr(e,t){Ke(e);let r=e;is(r.ORDER,"FpLegendre");let n=(r.ORDER-$)/ne,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 yl(e,t){if(t!==void 0&&es(t),e<=et)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=Me(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 Ta=new WeakMap,hn=class{ORDER;BITS;BYTES;isLE;ZERO=et;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}=yl(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 G(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return et<=t&&t<this.ORDER}is0(t){return t===et}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&$)===$}neg(t){return G(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return G(t*t,this.ORDER)}add(t,r){return G(t+r,this.ORDER)}sub(t,r){return G(t-r,this.ORDER)}mul(t,r){return G(t*r,this.ORDER)}pow(t,r){return Oa(t,r,this.ORDER)}div(t,r){return G(t*Ba(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 Ba(t,this.ORDER)}sqrt(t){let r=Ta.get(this);return r||Ta.set(this,r=ml(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?rs(t,this.BYTES):ln(t,this.BYTES)}fromBytes(t,r=!1){H(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):Ut(t);if(a&&(c=G(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return pn(this,t,!0)}cmov(t,r,n){return gt(n,"condition"),n?r:t}};function ze(e,t={}){return Object.freeze(hn.prototype),new hn(e,t)}function Ua(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=Me(e-$);return Math.ceil(t/8)}function mn(e){let t=Ua(e);return t+Math.ceil(t/2)}function gn(e,t,r=!1){H(e);let n=e.length,o=Ua(t),s=Math.max(mn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?me(e):Ut(e),a=G(i,t-$)+$;return r?rs(a,o):ln(a,o)}var us=BigInt(0),_r=BigInt(1),bl=BigInt(4),as=16,Ma=128,wl=5,Ka=2**31;function oe(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);he(t.fromAffine,"Point.fromAffine"),he(t.fromBytes,"Point.fromBytes"),he(t.fromHex,"Point.fromHex"),Jt(t.BASE,"Point.BASE"),Jt(t.ZERO,"Point.ZERO"),Ke(t.Fp),Ke(t.Fn)}function yn(e,t){oe(e),qa(t,e);let r=pn(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function xl(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 El(e,t){let r=e*(4*t+128);if(r>Ka)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Ka/2**20+" MiB")}function fs(e,t){if(e!==void 0){he(e,"randomBytes");try{let r=e(t);if(!ee(r)||r.length!==t)return}catch{return}return e}}function qa(e,t){un(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Sl(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):te(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var Ha=new WeakMap;function cs(e){return Ha.get(e)||1}function vl(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 _l(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>us;){let i=0;e&_r&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=_r}return s}function Al(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+=_r),a.push(u)}if(e!==us)throw new Error("invalid wnaf");return a}function Il(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 qe=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){oe(t),this.randomBytes=fs(r,as),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=t;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(t,r){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=Al(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],d=f*i,h=Math.abs(l)-1,I=s[d];for(let y=1;y<i;y++)I=y===h?s[d+y]:I;let x=I.negate();l===0?u=u.add(s[d]):c=c.add(l<0?x:I)}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),!ns(r,_r,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=cs(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+Ma,s=this.randomBytes(as);if(!ee(s)||s.length!==as)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=wl,s=1<<o,i=Sr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let h=0;h<o;h++)u=u.double();let l=Number(r>>BigInt(f*o)&i),d=a[0];for(let h=1;h<s;h++)d=h===l?a[h]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===_r?!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),!te(r))throw new Error("invalid scalar");let o=cs(t);if(o===1||r>=this.Point.Fn.ORDER)return bn(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),xl(r,this.bits);let n=Math.ceil((this.bits+Ma)/r)+1;El(n*2**(r-1),this.Point.Fp.BYTES),Ha.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return cs(t)!==1}};function bn(e,t,r,n=!1){if(oe(e),qa(t,e),gt(n,"allowOversized"),Sl(r,e.Fn,n?e.Fn.ORDER**bl:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>vl(i,4)),s=r.map(i=>_l(i,4));return Il(e.ZERO,o,s)}function za(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ke(t),t}else return ze(e,{isLE:r})}function wn(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`);yt(r);for(let c of["p","n","h"]){let u=t[c];if(!(te(u)&&u!==us))throw new Error(`CURVE.${c} must be positive bigint`)}let o=za(t.p,r.Fp,n),s=za(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 xn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var En=BigInt(0),Sn=BigInt(1),vn=BigInt(2),Bl=BigInt(4),$a=BigInt(8);function Tl(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 Va(e,t={}){yt(t,{},{},"extraOpts");let r=t,n=wn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(vr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(vr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");yt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?pe:r.randomBytes,u=vn<<BigInt(o.BYTES*8)-Sn;function f(S){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(S)}let l=r.uvRatio===void 0?(S,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(S,g))}}catch{return{isValid:!1,value:En}}}:r.uvRatio;if(!Tl(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=o.eql(i.a,o.neg(o.ONE))?S=>o.neg(S):o.eql(i.a,o.ONE)?S=>S:S=>o.mul(i.a,S);function h(S,g,_=!1){let B=_?Sn:En;return Ue("coordinate "+S,g,B,u),g}function I(S){if(!(S 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,_,B,U){this.X=h("x",g),this.Y=h("y",_),this.Z=h("z",B,!0),this.T=h("t",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof x)throw new Error("extended point not allowed");let{x:_,y:B}=g||{};return h("x",_),h("y",B),new x(_,B,o.ONE,o.mul(_,B))}static fromBytes(g,_=!1){let B=o.BYTES,{a:U,d:M}=i;g=dn(H(g,B,"point")),gt(_,"zip215");let k=dn(g),O=g[B-1];k[B-1]=O&-129;let P=me(k),K=_?u:o.ORDER;Ue("point.y",P,En,K);let L=o.sqr(P),j=o.sub(L,o.ONE),R=o.sub(o.mulN(M,L),U),{isValid:D,value:p}=l(j,R);if(!D)throw new Error("bad point: invalid y coordinate");let b=f(p),v=(O&128)!==0;if(!_&&o.is0(p)&&v)throw new Error("bad point: x=0 and x_0=1");return v!==b&&(p=o.neg(p)),x.fromAffine({x:p,y:P})}static fromHex(g,_=!1){return x.fromBytes(Fe(g),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,_=!0){return E.setWindowSize(this,g),_||this.multiply(vn),this}assertValidity(){let g=this,{a:_,d:B}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:U,Y:M,Z:k,T:O}=g,P=o.sqr(U),K=o.sqr(M),L=o.sqr(k),j=o.sqr(L),R=o.mul(P,_),D=o.mul(o.add(R,K),L),p=o.add(j,o.mul(B,o.mul(P,K)));if(!o.eql(D,p))throw new Error("bad point: equation left != right (1)");let b=o.mul(U,M),v=o.mul(k,O);if(!o.eql(b,v))throw new Error("bad point: equation left != right (2)")}equals(g){I(g);let{X:_,Y:B,Z:U}=this,{X:M,Y:k,Z:O}=g,P=o.mul(_,O),K=o.mul(M,U),L=o.mul(B,O),j=o.mul(k,U);return o.eql(P,K)&&o.eql(L,j)}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:_,Z:B}=this,U=o.sqr(g),M=o.sqr(_),k=o.mul(o.sqr(B),vn),O=d(U),P=o.addN(g,_),K=o.sub(o.subN(o.sqr(P),U),M),L=o.addN(O,M),j=o.subN(L,k),R=o.subN(O,M),D=o.mul(K,j),p=o.mul(L,R),b=o.mul(K,R),v=o.mul(j,L);return new x(D,p,v,b)}add(g){I(g);let{d:_}=i,{X:B,Y:U,Z:M,T:k}=this,{X:O,Y:P,Z:K,T:L}=g,j=o.mul(B,O),R=o.mul(U,P),D=o.mul(o.mulN(k,_),L),p=o.mul(M,K),b=o.sub(o.subN(o.mulN(o.addN(B,U),o.addN(O,P)),j),R),v=o.subN(p,D),C=o.addN(p,D),w=o.sub(R,d(j)),m=o.mul(b,v),A=o.mul(C,w),T=o.mul(b,w),N=o.mul(v,C);return new x(m,A,N,T)}subtract(g){return I(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:_,f:B}=E.mulSecret(this,g,a,y);return y([_,B])[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===Sn?this:E.mulUnsafe(this,g,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return E.mulUnsafe(this,i.n).is0()}toAffine(g){let _=this,B=g;if(B!=null&&typeof B!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof B);let{X:U,Y:M,Z:k}=_,O=_.is0();B==null&&(B=O?o.create($a):o.inv(k));let P=o.mul(U,B),K=o.mul(M,B),L=o.mul(k,B);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(L,o.ONE))throw new Error("invZ was invalid");return{x:P,y:K}}clearCofactor(){return a===Sn?this:a===vn?this.double():a===Bl?this.double().double():a===$a?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:_}=this.toAffine(),B=o.toBytes(_);return B[B.length-1]|=f(g)?128:0,B}toHex(){return xr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=S=>yn(x,S),E=new qe(x,c);return E.bits>=6&&x.BASE.precompute(6),Object.freeze(x.prototype),Object.freeze(x),x}function ja(e,t,r={}){if(oe(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;yt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(re(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?pe:o.randomBytes,d=o.toMontgomery,h=o.toMontgomerySecret,I=o.adjustScalarBytes===void 0?R=>R:o.adjustScalarBytes,x=o.domain===void 0?(R,D,p)=>{if(gt(p,"phflag"),D.length||p)throw new Error("Contexts/pre-hash are not supported");return R}:o.domain;function y(R){return c.create(me(R))}function E(R){let D=O.secretKey;H(R,O.secretKey,"secretKey");let p=H(n(R),2*D,"hashedSecretKey"),b=I(p.slice(0,D)),v=p.slice(D,2*D),C=y(b);return{head:b,prefix:v,scalar:C}}function S(R){let{head:D,prefix:p,scalar:b}=E(R),v=i.multiply(b),C=v.toBytes();return{head:D,prefix:p,scalar:b,point:v,pointBytes:C}}function g(R){return S(R).pointBytes}function _(R=Uint8Array.of(),...D){let p=_t(...D);return y(n(x(p,H(R,void 0,"context"),!!s)))}function B(R,D,p={}){yt(p,{},{},"options"),R=H(R,void 0,"message"),s&&(R=s(R));let{prefix:b,scalar:v,pointBytes:C}=S(D),w=_(p.context,b,R),m=i.multiply(w).toBytes(),A=_(p.context,m,C,R),T=c.create(w+A*v);if(!c.isValid(T))throw new Error("sign failed: invalid s");let N=_t(m,c.toBytes(T));return H(N,O.signature,"result")}let U={zip215:o.zip215};function M(R,D,p,b=U){yt(b);let{context:v}=b,C=b.zip215===void 0?!!U.zip215:b.zip215,w=O.signature;R=H(R,w,"signature"),D=H(D,void 0,"message"),p=H(p,O.publicKey,"publicKey"),C!==void 0&&gt(C,"zip215"),s&&(D=s(D));let m=w/2,A=R.subarray(0,m),T=me(R.subarray(m,w)),N,F,q;try{N=e.fromBytes(p,C),F=e.fromBytes(A,C),q=i.multiplyUnsafe(T)}catch{return!1}if(!C&&N.isSmallOrder())return!1;let z=_(v,A,p,D);return F.add(N.multiplyUnsafe(z)).subtract(q).clearCofactor().is0()}let k=a.BYTES,O={secretKey:k,publicKey:k,signature:2*k,seed:k};function P(R){return R=R===void 0?l(O.seed):R,H(R,O.seed,"seed")}function K(R){return ee(R)&&R.length===O.secretKey}function L(R,D){try{return!!e.fromBytes(R,D===void 0?U.zip215:D)}catch{return!1}}let j={getExtendedPublicKey:S,randomSecretKey:P,isValidSecretKey:K,isValidPublicKey:L,toMontgomery(R){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(e.fromBytes(R))},toMontgomerySecret(R){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(R)}};return Object.freeze(O),Object.freeze(j),Object.freeze({keygen:xn(P,g),getPublicKey:g,sign:B,verify:M,utils:j,Point:e,lengths:O})}var ls=BigInt(1),Za=BigInt(2);var Dl=BigInt(5),Rl=BigInt(8),ds=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ll={p:ds,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Rl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Cl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ds,a=e*e%s*e%s,c=Y(a,Za,s)*a%s,u=Y(c,ls,s)*e%s,f=Y(u,Dl,s)*u%s,l=Y(f,t,s)*f%s,d=Y(l,r,s)*l%s,h=Y(d,n,s)*d%s,I=Y(h,o,s)*h%s,x=Y(I,o,s)*h%s,y=Y(x,t,s)*f%s;return{pow_p_5_8:Y(y,Za,s)*e%s,b2:a}}function Wa(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ya=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ol(e,t){let r=ds,n=G(t*t*t,r),o=G(n*n*t,r),s=Cl(e*o).pow_p_5_8,i=G(e*n*s,r),a=G(t*i*i,r),c=i,u=G(i*Ya,r),f=a===e,l=a===G(-e,r),d=a===G(-e*Ya,r);return f&&(i=c),(l||d)&&(i=u),Fa(i,r)&&(i=G(-i,r)),{isValid:f||l,value:i}}var hs=Va(Ll,{uvRatio:Ol}),Ga=hs.Fp;function Pl(e){let{y:t}=e;return Ga.toBytes(Ga.div(ls+t,ls-t))}function kl(e){let t=hs.Fp.BYTES;return vt(e,t),Wa(ts(e.subarray(0,t))).subarray(0,t)}function Nl(e){return ja(hs,ts,Object.assign({adjustScalarBytes:Wa,toMontgomery:Pl,toMontgomerySecret:kl,zip215:!0},e))}var Xa=Nl({});var Ar=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},_n=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var An={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new _n("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 In=32;var ps,Fl=(async()=>{try{return await An.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ul(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await An.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await An.get().subtle.verify({name:"Ed25519"},n,Rt(t),Rt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ml(e,t,r){return Xa.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Qa(e,t,r){return ps==null&&(ps=await Fl),ps?Ul(e,t,r):Ml(e,t,r)}function Bn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Tn=class{type="Ed25519";raw;constructor(t){this.raw=ms(t,In)}toMultihash(){return Dt.digest(ke(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Qa(this.raw,r,t);return Bn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function tc(e){return e=ms(e,In),new Tn(e)}function ms(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ht(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var zl=Math.pow(2,7),ql=Math.pow(2,14),Hl=Math.pow(2,21),gs=Math.pow(2,28),ys=Math.pow(2,35),bs=Math.pow(2,42),ws=Math.pow(2,49),V=128,ft=127;function bt(e){if(e<zl)return 1;if(e<ql)return 2;if(e<Hl)return 3;if(e<gs)return 4;if(e<ys)return 5;if(e<bs)return 6;if(e<ws)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function He(e,t,r=0){switch(bt(e)){case 8:t[r++]=e&255|V,e/=128;case 7:t[r++]=e&255|V,e/=128;case 6:t[r++]=e&255|V,e/=128;case 5:t[r++]=e&255|V,e/=128;case 4:t[r++]=e&255|V,e>>>=7;case 3:t[r++]=e&255|V,e>>>=7;case 2:t[r++]=e&255|V,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function $l(e,t,r=0){switch(bt(e)){case 8:t.set(r++,e&255|V),e/=128;case 7:t.set(r++,e&255|V),e/=128;case 6:t.set(r++,e&255|V),e/=128;case 5:t.set(r++,e&255|V),e/=128;case 4:t.set(r++,e&255|V),e>>>=7;case 3:t.set(r++,e&255|V),e>>>=7;case 2:t.set(r++,e&255|V),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function xs(e,t){let r=e[t],n=0;if(n+=r&ft,r<V||(r=e[t+1],n+=(r&ft)<<7,r<V)||(r=e[t+2],n+=(r&ft)<<14,r<V)||(r=e[t+3],n+=(r&ft)<<21,r<V)||(r=e[t+4],n+=(r&ft)*gs,r<V)||(r=e[t+5],n+=(r&ft)*ys,r<V)||(r=e[t+6],n+=(r&ft)*bs,r<V)||(r=e[t+7],n+=(r&ft)*ws,r<V))return n;throw new RangeError("Could not decode varint")}function Vl(e,t){let r=e.get(t),n=0;if(n+=r&ft,r<V||(r=e.get(t+1),n+=(r&ft)<<7,r<V)||(r=e.get(t+2),n+=(r&ft)<<14,r<V)||(r=e.get(t+3),n+=(r&ft)<<21,r<V)||(r=e.get(t+4),n+=(r&ft)*gs,r<V)||(r=e.get(t+5),n+=(r&ft)*ys,r<V)||(r=e.get(t+6),n+=(r&ft)*bs,r<V)||(r=e.get(t+7),n+=(r&ft)*ws,r<V))return n;throw new RangeError("Could not decode varint")}function ec(e,t,r=0){return t==null&&(t=ut(bt(e))),t instanceof Uint8Array?He(e,t,r):$l(e,t,r)}function Ir(e,t=0){return e instanceof Uint8Array?xs(e,t):Vl(e,t)}var Es=new Float32Array([-0]),se=new Uint8Array(Es.buffer);function nc(e,t,r){Es[0]=e,t[r]=se[0],t[r+1]=se[1],t[r+2]=se[2],t[r+3]=se[3]}function oc(e,t){return se[0]=e[t],se[1]=e[t+1],se[2]=e[t+2],se[3]=e[t+3],Es[0]}var Ss=new Float64Array([-0]),lt=new Uint8Array(Ss.buffer);function sc(e,t,r){Ss[0]=e,t[r]=lt[0],t[r+1]=lt[1],t[r+2]=lt[2],t[r+3]=lt[3],t[r+4]=lt[4],t[r+5]=lt[5],t[r+6]=lt[6],t[r+7]=lt[7]}function ic(e,t){return lt[0]=e[t],lt[1]=e[t+1],lt[2]=e[t+2],lt[3]=e[t+3],lt[4]=e[t+4],lt[5]=e[t+5],lt[6]=e[t+6],lt[7]=e[t+7],Ss[0]}var jl=BigInt(Number.MAX_SAFE_INTEGER),Zl=BigInt(Number.MIN_SAFE_INTEGER),xt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<jl&&t>Zl)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>ac&&(o=0n,++n>ac&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ge}},ge=new xt(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var ac=4294967296n;function cc(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 uc(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 vs(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 Ct(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Dn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var _s=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Rt(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,Ct(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 Ct(this,4);return Dn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return Dn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=oc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=ic(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 Ct(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return uc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ct(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ct(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 xt(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 Ct(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 Ct(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 Ct(this,8);let t=Dn(this.buf,this.pos+=4),r=Dn(this.buf,this.pos+=4);return new xt(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=xs(this.buf,this.pos);return this.pos+=bt(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 Br(e){return new _s(e instanceof Uint8Array?e:e.subarray())}function At(e,t,r){let n=Br(e);return t.decode(n,void 0,r)}function As(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ut(i);o+i>t&&(n=ut(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,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Is(){}var Ts=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Yl=As();function Gl(e){return globalThis.Buffer!=null?ut(e):Yl(e)}var Dr=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,r,n){return this.tail=this.tail.next=new ye(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ds((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(Rn,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=xt.fromBigInt(t);return this._push(Rn,r.length(),r)}uint64Number(t){return this._push(He,bt(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=xt.fromBigInt(t).zzEncode();return this._push(Rn,r.length(),r)}sint64Number(t){let r=xt.fromNumber(t).zzEncode();return this._push(Rn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Bs,1,t?1:0)}fixed32(t){return this._push(Tr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=xt.fromBigInt(t);return this._push(Tr,4,r.lo)._push(Tr,4,r.hi)}fixed64Number(t){let r=xt.fromNumber(t);return this._push(Tr,4,r.lo)._push(Tr,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(nc,4,t)}double(t){return this._push(sc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Bs,1,0):this.uint32(r)._push(Xl,r,t)}string(t){let r=cc(t);return r!==0?this.uint32(r)._push(vs,r,t):this._push(Bs,1,0)}fork(){return this.states=new Ts(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,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=Gl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Bs(e,t,r){t[r]=e&255}function Wl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ds=class extends ye{next;constructor(t,r){super(Wl,t,r),this.next=void 0}};function Rn(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 Tr(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 Xl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Dr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ql,t,e),this},Dr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Jl,t,e),this});function Ql(e,t,r){t.set(e,r)}function Jl(e,t,r){e.length<40?vs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Z(e),r)}function Rs(){return new Dr}function It(e,t){let r=Rs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Bt(e,t,r){let n=Br(e);yield*t.stream(n,void 0,"$",r)}var Ln={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Cn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function be(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return Cn("enum",Ln.VARINT,r,n,o)}function Tt(e,t,r){return Cn("message",Ln.LENGTH_DELIMITED,e,t,r)}var Rr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var pt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(pt||(pt={}));var Ls;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ls||(Ls={}));(function(e){e.codec=()=>be(Ls)})(pt||(pt={}));var Lr;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(Lr||(Lr={}));var Cs;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(Cs||(Cs={}));var On=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(rn(t),vt(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),de(o)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(this),nn(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()}},lc=(()=>{let e=((t,r,n)=>new On(t,r).update(n).digest());return e.create=(t,r)=>new On(t,r),e})();var ed=BigInt(0),Os=class extends Error{constructor(t=""){super(t)}},Ht={Err:Os,_tlv:{encode:(e,t)=>{let{Err:r}=Ht;if(re(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(_a(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Er(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Er(o.length/2|128):"";return Er(e)+s+o+t},decode(e,t){let{Err:r}=Ht;t=H(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Ht;if(fn(e),e<ed)throw new t("integer: negative integers are not allowed");let r=Er(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Ht;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){let{Err:t,_int:r,_tlv:n}=Ht,o=H(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Ht;yt(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)}},Ps=(Object.freeze(Ht._tlv),Object.freeze(Ht._int),Object.freeze(Ht));var dc=(e,t)=>(e+(e>=0?t:-t)/hc)/t;function rd(e,t,r){Ue("scalar",e,$t,r);let[[n,o],[s,i]]=t,a=dc(i*e,r),c=dc(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<$t,d=f<$t;l&&(u=-u),d&&(f=-f);let h=Sr(Math.ceil(Me(r)/2))+we;if(u<$t||u>=h||f<$t||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Fs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ks(e,t){yt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return gt(r.lowS,"lowS"),gt(r.prehash,"prehash"),r.format!==void 0&&Fs(r.format),r}var $t=BigInt(0),we=BigInt(1),hc=BigInt(2),Ns=BigInt(3),nd=BigInt(4);function pc(e,t={}){let r=wn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;yt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u}=t,f=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 l=gc(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(D,p,b){if(u&&p.is0())return Uint8Array.of(0);let{x:v,y:C}=p.toAffine(),w=n.toBytes(v);if(gt(b,"isCompressed"),b){d();let m=!n.isOdd(C);return _t(mc(m),w)}else return _t(Uint8Array.of(4),w,n.toBytes(C))}function I(D){H(D,void 0,"Point");let{publicKey:p,publicKeyUncompressed:b}=l,v=D.length,C=D[0],w=D.subarray(1);if(u&&v===1&&C===0)return{x:n.ZERO,y:n.ZERO};if(v===p&&(C===2||C===3)){let m=n.fromBytes(w);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let A=g(m),T;try{T=n.sqrt(A)}catch(q){let z=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}d();let N=n.isOdd(T);return(C&1)===1!==N&&(T=n.neg(T)),{x:m,y:T}}else if(v===b&&C===4){let m=n.BYTES,A=n.fromBytes(w.subarray(0,m)),T=n.fromBytes(w.subarray(m,m*2));if(!_(A,T))throw new Error("bad point: is not on curve");return{x:A,y:T}}else throw new Error(`bad point: got length ${v}, expected compressed=${p} or uncompressed=${b}`)}let x=t.toBytes===void 0?h:t.toBytes,y=t.fromBytes===void 0?I:t.fromBytes,E=n.mul(s.b,Ns),S=n.is0(s.a)?D=>n.ZERO:D=>n.mul(s.a,D);function g(D){let p=n.sqr(D),b=n.mul(p,D);return n.add(n.add(b,n.mul(D,s.a)),s.b)}function _(D,p){let b=n.sqr(p),v=g(D);return n.eql(b,v)}if(!_(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let B=n.mul(n.pow(s.a,Ns),nd),U=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(B,U)))throw new Error("bad curve params: a or b");function M(D,p,b=!1){if(!n.isValid(p)||b&&n.is0(p))throw new Error(`bad point coordinate ${D}`);return p}function k(D){if(!(D instanceof L))throw new Error("Weierstrass Point expected")}function O(D){if(!c||!c.basises)throw new Error("no endo");return rd(D,c.basises,o.ORDER)}function P(D,p,b,v){if(!o.isValid(v))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:C,k1:w,k2neg:m,k2:A}=O(v),T=new L(n.mul(b.X,c.beta),b.Y,b.Z);D.push(C?b.negate():b,m?T.negate():T),p.push(w,A)}else D.push(b),p.push(v)}let K=new WeakSet;class L{static BASE=new L(s.Gx,s.Gy,n.ONE);static ZERO=new L(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,b,v){this.X=M("x",p),this.Y=M("y",b,!0),this.Z=M("z",v),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:b,y:v}=p||{};if(!p||!n.isValid(b)||!n.isValid(v))throw new Error("invalid affine point");if(p instanceof L)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(v)?L.ZERO:new L(b,v,n.ONE)}static fromBytes(p){let b=L.fromAffine(y(H(p,void 0,"point")));return b.assertValidity(),b}static fromHex(p){return L.fromBytes(Fe(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,b=!0){return R.setWindowSize(this,p),b||this.multiply(Ns),this}assertValidity(){let p=this;if(p.is0()){if(t.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(K.has(p))return;let{x:b,y:v}=p.toAffine();if(!n.isValid(b)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!_(b,v))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");K.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){k(p);let{X:b,Y:v,Z:C}=this,{X:w,Y:m,Z:A}=p,T=n.eql(n.mul(b,A),n.mul(w,C)),N=n.eql(n.mul(v,A),n.mul(m,C));return T&&N}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:b,Z:v}=this,C=n.ZERO,w=n.ZERO,m=n.ZERO,A=n.mul(p,p),T=n.mul(b,b),N=n.mul(v,v),F=n.mul(p,b);return F=n.add(F,F),m=n.mul(p,v),m=n.add(m,m),C=S(m),w=n.mul(E,N),w=n.add(C,w),C=n.sub(T,w),w=n.add(T,w),w=n.mul(C,w),C=n.mul(F,C),m=n.mul(E,m),N=S(N),F=n.sub(A,N),F=S(F),F=n.add(F,m),m=n.add(A,A),A=n.add(m,A),A=n.add(A,N),A=n.mul(A,F),w=n.add(w,A),N=n.mul(b,v),N=n.add(N,N),A=n.mul(N,F),C=n.sub(C,A),m=n.mul(N,T),m=n.add(m,m),m=n.add(m,m),new L(C,w,m)}add(p){k(p);let{X:b,Y:v,Z:C}=this,{X:w,Y:m,Z:A}=p,T=n.ZERO,N=n.ZERO,F=n.ZERO,q=n.mul(b,w),z=n.mul(v,m),W=n.mul(C,A),dt=n.add(b,v),X=n.add(w,m);dt=n.mul(dt,X),X=n.add(q,z),dt=n.sub(dt,X),X=n.add(b,C);let it=n.add(w,A);return X=n.mul(X,it),it=n.add(q,W),X=n.sub(X,it),it=n.add(v,C),T=n.add(m,A),it=n.mul(it,T),T=n.add(z,W),it=n.sub(it,T),F=S(X),T=n.mul(E,W),F=n.add(T,F),T=n.sub(z,F),F=n.add(z,F),N=n.mul(T,F),z=n.add(q,q),z=n.add(z,q),W=S(W),X=n.mul(E,X),z=n.add(z,W),W=n.sub(q,W),W=S(W),X=n.add(X,W),q=n.mul(z,X),N=n.add(N,q),q=n.mul(it,X),T=n.mul(dt,T),T=n.sub(T,q),q=n.mul(dt,z),F=n.mul(it,F),F=n.add(F,q),new L(T,N,F)}subtract(p){return k(p),this.add(p.negate())}is0(){return this.equals(L.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:b,f:v}=R.mulSecret(this,p,i,j);return j([b,v])[0]}multiplyUnsafe(p){let b=this,v=p;if(!o.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===$t||b.is0())return L.ZERO;if(v===we)return b;if(R.hasWindowSize(this))return R.mulUnsafe(b,v,j);let C=[],w=[];return P(C,w,b,v),bn(L,C,w)}mulAddUnsafe(p,b,v){k(b);let C=[],w=[];return P(C,w,this,p),P(C,w,b,v),bn(L,C,w)}toAffine(p){let b=this,v=p;if(v!=null&&!n.isValid(v))throw new RangeError('"invertedZ" expected valid field element');let{X:C,Y:w,Z:m}=b;if(n.eql(m,n.ONE))return{x:C,y:w};let A=b.is0();v==null&&(v=A?n.ONE:n.inv(m));let T=n.mul(C,v),N=n.mul(w,v),F=n.mul(m,v);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:T,y:N}}isTorsionFree(){let{isTorsionFree:p}=t;return i===we?!0:p?p(L,this):R.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=t;return i===we?this:p?p(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===we?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return gt(p,"isCompressed"),this.assertValidity(),x(L,this,p)}toHex(p=!0){return xr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let j=D=>yn(L,D),R=new qe(L,f);return R.bits>=6&&L.BASE.precompute(6),Object.freeze(L.prototype),Object.freeze(L),L}function mc(e){return Uint8Array.of(e?2:3)}function gc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function od(e,t={}){oe(e);let{Fn:r}=e,n=t.randomBytes===void 0?pe:t.randomBytes,o=Object.assign(gc(e.Fp,r),{seed:Math.max(mn(r.ORDER),16)});function s(h){try{let I=r.fromBytes(h);return r.isValidNot0(I)}catch{return!1}}function i(h,I){let{publicKey:x,publicKeyUncompressed:y}=o;try{let E=h.length;return I===!0&&E!==x||I===!1&&E!==y?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,gn(H(h,o.seed,"seed"),r.ORDER)}function c(h,I=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(I)}function u(h){let{secretKey:I,publicKey:x,publicKeyUncompressed:y}=o,E=r._lengths;if(!ee(h))return;let S=H(h,void 0,"key").length,g=S===x||S===y,_=S===I||!!E?.includes(S);if(!(g&&_))return g}function f(h,I,x=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(I)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(h);return e.fromBytes(I).multiply(y).toBytes(x)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=xn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:e,utils:l,lengths:o})}function yc(e,t,r={}){oe(e);let n=t;rn(n),yt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?pe:o.randomBytes,i=o.hmac===void 0?(w,m)=>lc(n,w,m):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,l=mn(u),d=fs(s,l),{keygen:h,getPublicKey:I,getSharedSecret:x,utils:y,lengths:E}=od(e,o),S={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*hc+we<a.ORDER;function _(w){let m=u>>we;return w>m}function B(w,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return m}function U(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(w,m,A){return U(),(w===A?0:2)|Number(a.isOdd(m))}function k(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(w,m){Fs(m);let A=E.signature,T=m==="compact"?A:m==="recovered"?A+1:void 0;return H(w,T)}class P{r;s;recovery;constructor(m,A,T){if(this.r=B("r",m),this.s=B("s",A),T!=null){if(k(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(m,A=S.format){O(m,A);let T;if(A==="der"){let{r:z,s:W}=Ps.toSig(H(m));return new P(z,W)}A==="recovered"&&(T=m[0],A="compact",m=m.subarray(1));let N=E.signature/2,F=m.subarray(0,N),q=m.subarray(N,N*2);return new P(c.fromBytes(F),c.fromBytes(q),T)}static fromHex(m,A){return this.fromBytes(Fe(m),A)}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:A,s:T}=this,N=this.assertRecovery(),F=N===2||N===3?A+u:A;if(!a.isValid(F))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let q=a.toBytes(F),z=e.fromBytes(_t(mc((N&1)===0),q)),W=c.inv(F),dt=L(H(m,void 0,"msgHash")),X=c.create(-dt*W),it=c.create(T*W),Pt=e.BASE.mulAddUnsafe(X,z,it);if(Pt.is0())throw new Error("invalid recovery: point at infinify");return Pt.assertValidity(),Pt}hasHighS(){return _(this.s)}toBytes(m=S.format){if(Fs(m),m==="der")return Fe(Ps.hexFromSig(this));let{r:A,s:T}=this,N=c.toBytes(A),F=c.toBytes(T);return m==="recovered"?(k(),_t(Uint8Array.of(this.assertRecovery()),N,F)):_t(N,F)}toHex(m){return xr(this.toBytes(m))}}Object.freeze(P.prototype),Object.freeze(P);let K=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let A=Ut(m),T=m.length*8-f;return T>0?A>>BigInt(T):A}:o.bits2int,L=o.bits2int_modN===void 0?function(m){return c.create(K(m))}:o.bits2int_modN,j=Sr(f);function R(w){return Ue("num < 2^"+f,w,$t,j),c.toBytes(w)}function D(w,m){return H(w,void 0,"message"),m?H(n(w),void 0,"prehashed message"):w}function p(w,m,A){let{lowS:T,prehash:N,extraEntropy:F}=ks(A,S);w=D(w,N);let q=L(w),z=c.fromBytes(m);if(!c.isValidNot0(z))throw new Error("invalid private key");let W=[R(z),R(q)];if(F!=null&&F!==!1){let Pt=F===!0?s(E.secretKey):F;W.push(H(Pt,void 0,"extraEntropy"))}let dt=_t(...W),X=q;function it(Pt){let Be=K(Pt);if(!c.isValidNot0(Be))return;let sr=e.BASE.multiply(Be).toAffine(),Zt=c.create(sr.x);if(Zt===$t)return;let kt;if(d!==void 0){let ir=Ut(gn(d(l),u)),mu=c.inv(c.mul(ir,Be)),gu=c.mul(ir,X),yu=c.mul(ir,z);kt=c.create(mu*c.create(gu+yu*Zt))}else{let ir=Pa(Be,u);kt=c.create(ir*c.create(X+Zt*z))}if(kt===$t)return;let fo=M(sr.x,sr.y,Zt),Ei=kt;return T&&_(kt)&&(Ei=c.neg(kt),fo^=1),new P(Zt,Ei,g?void 0:fo)}return{seed:dt,k2sig:it}}function b(w,m,A={}){let{seed:T,k2sig:N}=p(w,m,A);return Ia(n.outputLen,c.BYTES,i)(T,N).toBytes(A.format)}function v(w,m,A,T={}){let{lowS:N,prehash:F,format:q}=ks(T,S);if(A=H(A,void 0,"publicKey"),m=D(m,F),!ee(w)){let z=w instanceof P?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+z)}O(w,q);try{let z=P.fromBytes(w,q),W=e.fromBytes(A);if(N&&z.hasHighS())return!1;let{r:dt,s:X}=z,it=L(m),Pt=c.inv(X),Be=c.create(it*Pt),sr=c.create(dt*Pt),Zt=e.BASE.mulAddUnsafe(Be,W,sr);if(Zt.is0())return!1;let kt=Zt.toAffine();return!(c.create(kt.x)!==dt||q==="recovered"&&z.recovery!==M(kt.x,kt.y,dt))}catch{return!1}}function C(w,m,A={}){let{prehash:T}=ks(A,S);return m=D(m,T),P.fromBytes(w,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:h,getPublicKey:I,getSharedSecret:x,utils:y,lengths:E,Point:e,sign:b,verify:v,recoverPublicKey:C,Signature:P,hash:n})}var Ms={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},sd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var bc=BigInt(2);function id(e){let t=Ms.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=Y(f,r,t)*f%t,d=Y(l,r,t)*f%t,h=Y(d,bc,t)*u%t,I=Y(h,o,t)*h%t,x=Y(I,s,t)*I%t,y=Y(x,a,t)*x%t,E=Y(y,c,t)*y%t,S=Y(E,a,t)*x%t,g=Y(S,r,t)*f%t,_=Y(g,i,t)*I%t,B=Y(_,n,t)*u%t,U=Y(B,bc,t);if(!Us.eql(Us.sqr(U),e))throw new Error("Cannot find square root");return U}var Us=ze(Ms.p,{sqrt:id}),ad=pc(Ms,{Fp:Us,endo:sd}),$e=yc(ad,Sa);function wc(e,t,r,n){let o=hr.digest(r instanceof Uint8Array?r:r.subarray());if(Bn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),$e.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ar(String(s))});try{return n?.signal?.throwIfAborted(),$e.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Ar(String(s))}}var Pn=class{type="secp256k1";raw;_key;constructor(t){this._key=Ec(t),this.raw=xc(this._key)}toMultihash(){return Dt.digest(ke(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return wc(this._key,r,t,n)}};function Sc(e){return new Pn(e)}function xc(e){return $e.Point.fromBytes(e).toBytes()}function Ec(e){try{return $e.Point.fromBytes(e),e}catch(t){throw new jr(String(t))}}function vc(e){let{Type:t,Data:r}=Lr.decode(e.digest),n=r??new Uint8Array;switch(t){case pt.Ed25519:return tc(n);case pt.secp256k1:return Sc(n);case pt.ECDSA:return ea(n);default:throw new ar}}function ke(e){return Lr.encode({Type:pt[e.type],Data:e.raw})}var _c=Symbol.for("nodejs.util.inspect.custom"),cd=114,Cr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ho]=!0;toString(){return this.string==null&&(this.string=J.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(cd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ct(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ct(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[_c](){return`PeerId(${this.toString()})`}},kn=class extends Cr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Nn=class extends Cr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Fn=class extends Cr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ud=2336,Un=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Dt.digest(Z(this.url))}[_c](){return`PeerId(${this.url})`}[ho]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(ud,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=tt(t)),t.toString()===this.toString())}};function Ac(e){if(ld(e))return new kn({multihash:e});if(fd(e))try{let t=vc(e);if(t.type==="Ed25519")return new Nn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Fn({multihash:e,publicKey:t})}catch{let r=tt(e.digest);return new Un(new URL(r))}throw new Zr("Supplied PeerID Multihash is invalid")}function fd(e){return e.code===Dt.code}function ld(e){return e.code===hr.code}function Ks(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 Mn(e){let t=lr(J.decode(`z${e}`));return Ac(t)}var Kn=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 Ks(this.set.entries(),t=>{let r=Mn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=Mn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ks(this.set.values(),t=>Mn(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 zs(){return new Kn}var qs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ic={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Bc=new globalThis.TextEncoder;function dd(e,t){let r=qs[t],n=Ic[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function hd(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=qs[t],o=Ic[t],s=e;for(;s.length>0;){let i=Bc.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 Hs(e,{size:t=32,utf8Buffer:r}={}){if(!qs[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 hd(e,t,r);e=Bc.encode(e)}return dd(e,t)}var Or={hash:e=>Number(Hs(e,{size:32})),hashV:(e,t)=>pd(Or.hash(e,t))};function pd(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),Z(t,"base16")}var $s=64,Ot=class{fp;h;seed;constructor(t,r,n,o=2){if(o>$s)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=mt(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?ct(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 Ot))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Ot))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 Ot))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 Ot))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var md=500,Pr=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??Or,this.seed=t.seed??xe(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=Z(t));let r=new Ot(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<md;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=Z(t));let r=new Ot(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=Z(t));let r=new Ot(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}},gd={1:.5,2:.84,4:.95,8:.98};function yd(e=.001){return e>.002?2:e>1e-5?4:8}function Tc(e,t=.001){let r=yd(t),n=gd[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),$s);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var zn=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??Or,this.seed=t.seed??xe(0,Math.pow(2,10)),this.filterSeries=[new Pr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=Z(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 Pr({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=Z(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=Z(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 Vs(e,t=.001,r){return new zn({...Tc(e,t),...r??{}})}function kr(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 Ve(e){let t=kr(e);if(t==null)throw new ht(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var qn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Dc=45,bd=15,je=new qn;function Hn(e){if(!(e.length>bd))return je.new(e).parseWith(()=>je.readIPv4Addr())}function $n(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Dc))return je.new(e).parseWith(()=>je.readIPv6Addr())}function Ze(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Dc)return;let r=je.new(e).parseWith(()=>je.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function Rc(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 Lc(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 js(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 Cc(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 Oc(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,Tb=parseInt("0xFFFF",16),wd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Nr(e,t){t.length===ve&&e.length===Se&&Rc(t,0,11)&&(t=t.slice(12)),t.length===Se&&e.length===ve&&Lc(e,wd,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 Pc(e,t){if(typeof t=="string"&&(t=Ze(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 Zs(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=Se,o=Hn(t);if(o==null&&(n=ve,o=$n(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=Ys(s,8*n);return{network:Nr(o,i),mask:i}}function Ys(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 Fr=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=Zs(t));else{let n=Ze(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=Ze(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ys(o,8*n.length);this.network=Nr(n,this.mask)}}contains(t){return Pc({network:this.network,mask:this.mask},t)}toString(){let t=Cc(this.mask),r=t!==-1?String(t):Oc(this.mask);return js(this.network)+"/"+r}};function kc(e,t){return new Fr(e).contains(t)}function Nc(e){try{let t=Ve(e);return t.type==="ip6"?kc("2000::/3",t.host):!1}catch{return!1}}function Ye(e){return!!Hn(e)}function Vn(e){return!!$n(e)}var Kc=vu(Mc(),1),Id=["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"],Bd=Id.map(e=>new Kc.Netmask(e));function ei(e){for(let t of Bd)if(t.contains(e))return!0;return!1}function Td(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function Dd(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 ei(o)}function Rd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function Ld(e){let t=e.split(":"),r=t[t.length-1];return ei(r)}function Cd(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 Zn(e){if(Ye(e))return ei(e);if(Td(e))return Dd(e);if(Rd(e))return Ld(e);if(Vn(e))return Cd(e)}function zc(e){try{let t=Ve(e);switch(t.type){case"ip4":case"ip6":return Zn(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var ot=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Vt=class extends Error{static name="ValidationError";name="ValidationError"},Yn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Gn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function ni(e){return t=>tt(t,e)}function oi(e){return t=>Z(t,e)}function Qe(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 qc(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=Z(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 Hc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Gt.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 si(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=tt(t,"base32"),o=Qe(r);return`${n}:${o}`}var ii=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 ot("Invalid byte value in IP address");t[n]=o}),t},$c=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=Ye(r[n]),i;s&&(i=ii(r[n]),r[n]=tt(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,tt(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 ot("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Vc=function(e){if(e.byteLength!==4)throw new ot("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},jc=function(e){if(e.byteLength!==16)throw new ot("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 ot(`Invalid IPv6 address "${r}"`)}};function Zc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ot(`Invalid IPv6 address "${e}"`)}}var ri=Object.values(pr).map(e=>e.decoder),Od=(function(){let e=ri[0].or(ri[1]);return ri.slice(2).forEach(t=>e=e.or(t)),e})();function Yc(e){return Od.decode(e)}function Gc(e){return t=>e.encoder.encode(t)}function Pd(e){if(parseInt(e).toString()!==e)throw new Vt("Value must be an integer")}function kd(e){if(e<0)throw new Vt("Value must be a positive integer, or zero")}function Nd(e){return t=>{if(t>e)throw new Vt(`Value must be smaller than or equal to ${e}`)}}function Fd(...e){return t=>{for(let r of e)r(t)}}var Ur=Fd(Pd,kd,Nd(65535));var nt=-1,ai=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 Gn(`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)}))}},jt=new ai,Sh=[{code:4,name:"ip4",size:32,valueToBytes:ii,bytesToValue:Vc,validate:e=>{if(!Ye(e))throw new Vt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ae,bytesToValue:Qe,validate:Ur},{code:273,name:"udp",size:16,valueToBytes:Ae,bytesToValue:Qe,validate:Ur},{code:33,name:"dccp",size:16,valueToBytes:Ae,bytesToValue:Qe,validate:Ur},{code:41,name:"ip6",size:128,valueToBytes:$c,bytesToValue:jc,stringToValue:Zc,validate:e=>{if(!Vn(e))throw new Vt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:nt},{code:43,name:"ipcidr",size:8,bytesToValue:ni("base10"),valueToBytes:oi("base10")},{code:53,name:"dns",size:nt},{code:54,name:"dns4",size:nt},{code:55,name:"dns6",size:nt},{code:56,name:"dnsaddr",size:nt},{code:132,name:"sctp",size:16,valueToBytes:Ae,bytesToValue:Qe,validate:Ur},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:nt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:nt,bytesToValue:ni("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?oi("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:si,valueToBytes:qc},{code:445,name:"onion3",size:296,bytesToValue:si,valueToBytes:Hc},{code:446,name:"garlic64",size:nt},{code:447,name:"garlic32",size:nt},{code:448,name:"tls"},{code:449,name:"sni",size:nt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:nt,bytesToValue:Gc(Ro),valueToBytes:Yc},{code:480,name:"http"},{code:481,name:"http-path",size:nt,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:nt}];Sh.forEach(e=>{jt.addProtocol(e)});function Wc(e){let t=[],r=0;for(;r<e.length;){let n=Ir(e,r),o=jt.getProtocol(n),s=bt(n),i=vh(o,e,r+s),a=0;i>0&&o.size===nt&&(a=bt(i));let c=s+a+i,u={code:n,name:o.name,bytes:Rt(e.subarray(r,r+c))};if(i>0){let f=r+s+a,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??tt(l)}t.push(u),r+=c}return t}function Xc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=jt.getProtocol(n.code),s=bt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Z(n.value),a=i.byteLength,o.size===nt&&(c=bt(a)));let u=new Uint8Array(s+c+a),f=0;He(n.code,u,f),f+=s,i!=null&&(o.size===nt&&(He(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Nt(r,t)}function Qc(e){if(e.charAt(0)!=="/")throw new ot('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=jt.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 ot(`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 ot(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ot("Incomplete multiaddr");return t}function Jc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=jt.getProtocol(t.code);if(r==null)throw new ot(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function vh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Ir(t,r)}var _h=Symbol.for("nodejs.util.inspect.custom"),fi=Symbol.for("@multiformats/multiaddr");function Ah(e){if(e==null&&(e="/"),tu(e))return e.getComponents();if(e instanceof Uint8Array)return Wc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Qc(e);if(Array.isArray(e))return e;throw new ot("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Wn=class e{[fi]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Ah(t),r.validate!==!1&&Ih(this)}get bytes(){return this.#r==null&&(this.#r=Xc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Jc(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 Yn(`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 ct(this.bytes,t.bytes)}[_h](){return`Multiaddr(${this.toString()})`}};function Ih(e){e.getComponents().forEach(t=>{let r=jt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function tu(e){return!!e?.[fi]}function eu(e){return new Wn(e)}function Je(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Xn=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}},tr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Xn(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 Xn(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 li=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 Bh(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 Bh(e,t){t=t??{};let r=t.onEnd,n=new tr,o,s,i,a=Je(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,E)=>{s=S=>{s=null,n.push(S);try{y(e(n))}catch(g){E(g)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Je()})}},u=y=>s!=null?s(y):(n.push(y),o),f=y=>(n=new tr,s!=null?s({error:y}):(n.push({error:y}),o)),l=y=>{if(i)return o;if(t?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},d=y=>i?o:(i=!0,y!=null?f(y):u({done:!0})),h=()=>(n=new tr,d(),{done:!0}),I=y=>(d(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:I,push:l,end:d,get readableLength(){return n.size},onEmpty:async y=>{let E=y?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let S,g;E!=null&&(S=new Promise((_,B)=>{g=()=>{B(new li)},E.addEventListener("abort",g)}));try{await Promise.race([a.promise,S])}finally{g!=null&&E!=null&&E?.removeEventListener("abort",g)}}},r==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(y){return x.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return x.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(y){return x.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return x.readableLength},onEmpty:y=>x.onEmpty(y)},o}var di=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},ru=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function hi(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,f=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){d(ru(i));return}if(i&&(c=()=>{d(ru(i))},i.addEventListener("abort",c,{once:!0})),e.then(l,d),r===Number.POSITIVE_INFINITY)return;let h=new di;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(I){d(I)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?d(o):(h.message=o??`Promise timed out after ${r} milliseconds`,d(h))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Th=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Dh(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=Th(e),l=async(...h)=>{let I=r.multiArgs?h:h[0];if(r.filter)try{if(!await r.filter(I))return}catch(x){n(),i(x);return}c.push(I),r.count===c.length&&(n(),s(c))},d=(...h)=>{n(),i(r.rejectionMultiArgs?h:h[0])};n=()=>{for(let h of a)f(h,l);for(let h of r.rejectionEvents)a.includes(h)||f(h,d)};for(let h of a)u(h,l);for(let h of r.rejectionEvents)a.includes(h)||u(h,d);r.signal&&r.signal.addEventListener("abort",()=>{d(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=hi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function er(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Dh(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Mr(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 Jn=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 Rh(e){return e.reason}async function Kr(e,t,r){if(t==null)return e;let n=r?.translateError??Rh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var to=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=Je(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new zt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Lh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var eo=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,r){this.id=Lh(),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 zt),this.cleanup())}async join(t){let r=new to(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 Kr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){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.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var ro=class extends Te{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=Mr(this.emitEmpty.bind(this),1),this.emitIdle=Mr(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 Jn;let n=new eo(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 zt)}),this.clear()}async onEmpty(t){this.size!==0&&await er(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await er(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await er(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 zt("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 zr(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 Ch=4194304,no=class extends Error{static name="UnwrappedError";name="UnwrappedError"},mi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},gi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},yi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Oh(e){return typeof e?.closeRead=="function"}function Ph(e){return typeof e?.close=="function"}function pi(e){return Oh(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Ph(e)?e.status!=="open":!1}function kh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Nh(e,t){let r=t?.maxBufferSize??Ch,n=new rt,o,s=!1;if(!kh(e))throw new ht("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};e.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};e.addEventListener("close",a);let c=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(s===!0)throw new no("Stream was unwrapped");if(pi(e)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Ie(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Kr(o.promise,f?.signal),pi(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let d=f?.bytes??n.byteLength;if(n.byteLength<d){if(pi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Ie(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(f)}let h=n.sublist(0,d);return n.consume(d),h},async write(f,l){if(s===!0)throw new no("Stream was unwrapped");e.send(f)||await er(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n))),e}};return u}function Fh(e,t={}){let r=Nh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=bt(t.maxDataLength));let n=t?.lengthDecoder??Ir,o=t?.lengthEncoder??ec;return{async read(i){let a=-1,c=new rt;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new mi("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new yi(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new gi(`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 rt(o(i.byteLength),i),a)},async writeV(i,a){let c=new rt(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function rr(e,t){let r=Fh(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 oo=class extends ro{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function nu(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal},f;r?.timeout!=null&&(f=zr([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=f),s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Mr(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 bi=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 ou(e){let{name:t,metrics:r}=e,n;return r!=null?n=new bi({name:t,metrics:r}):n=new Map,n}var wi="libp2p",xi="autonat";var su="dial-request",iu="dial-back",au=200n*1024n,cu=4096;var nr;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s={...s},s.dialDataResponse!=null&&(s.dialDataRequest=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialDataRequest!=null&&(s.dialDataResponse=void 0,s.dialResponse=void 0,s.dialRequest=void 0),s.dialResponse!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialRequest=void 0),s.dialRequest!=null&&(s.dialDataResponse=void 0,s.dialDataRequest=void 0,s.dialResponse=void 0),s.dialRequest!=null&&(i.uint32(10),qr.codec().encode(s.dialRequest,i)),s.dialResponse!=null&&(i.uint32(18),Kt.codec().encode(s.dialResponse,i)),s.dialDataRequest!=null&&(i.uint32(26),Hr.codec().encode(s.dialDataRequest,i)),s.dialDataResponse!=null&&(i.uint32(34),$r.codec().encode(s.dialDataResponse,i)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.dialRequest=qr.codec().decode(s,s.uint32(),{limits:a.limits?.dialRequest});break}case 2:{c.dialResponse=Kt.codec().decode(s,s.uint32(),{limits:a.limits?.dialResponse});break}case 3:{c.dialDataRequest=Hr.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataRequest});break}case 4:{c.dialDataResponse=$r.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}return c.dialDataResponse!=null&&(delete c.dialDataRequest,delete c.dialResponse,delete c.dialRequest),c.dialDataRequest!=null&&(delete c.dialDataResponse,delete c.dialResponse,delete c.dialRequest),c.dialResponse!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialRequest),c.dialRequest!=null&&(delete c.dialDataResponse,delete c.dialDataRequest,delete c.dialResponse),c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield*qr.codec().stream(s,s.uint32(),`${a}.dialRequest`,{limits:c.limits?.dialRequest});break}case 2:{yield*Kt.codec().stream(s,s.uint32(),`${a}.dialResponse`,{limits:c.limits?.dialResponse});break}case 3:{yield*Hr.codec().stream(s,s.uint32(),`${a}.dialDataRequest`,{limits:c.limits?.dialDataRequest});break}case 4:{yield*$r.codec().stream(s,s.uint32(),`${a}.dialDataResponse`,{limits:c.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(nr||(nr={}));var qr;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.addrs!=null&&s.addrs.length>0)for(let c of s.addrs)i.uint32(10),i.bytes(c);s.nonce!=null&&s.nonce!==0n&&(i.uint32(17),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrs:[],nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(a.limits?.addrs!=null&&c.addrs.length===a.limits.addrs)throw new Rr('Decode error - repeated field "addrs" had too many elements');c.addrs.push(s.bytes());break}case 2:{c.nonce=s.fixed64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={addrs:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(c.limits?.addrs!=null&&u.addrs===c.limits.addrs)throw new Rr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${a}.addrs[]`,index:u.addrs,value:s.bytes()},u.addrs++;break}case 2:{yield{field:`${a}.nonce`,value:s.fixed64()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(qr||(qr={}));var Hr;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.addrIdx!=null&&s.addrIdx!==0&&(i.uint32(8),i.uint32(s.addrIdx)),s.numBytes!=null&&s.numBytes!==0n&&(i.uint32(16),i.uint64(s.numBytes)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={addrIdx:0,numBytes:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.addrIdx=s.uint32();break}case 2:{c.numBytes=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.addrIdx`,value:s.uint32()};break}case 2:{yield{field:`${a}.numBytes`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(Hr||(Hr={}));var st;(function(e){e.UNUSED="UNUSED",e.E_DIAL_ERROR="E_DIAL_ERROR",e.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",e.OK="OK"})(st||(st={}));var so;(function(e){e[e.UNUSED=0]="UNUSED",e[e.E_DIAL_ERROR=100]="E_DIAL_ERROR",e[e.E_DIAL_BACK_ERROR=101]="E_DIAL_BACK_ERROR",e[e.OK=200]="OK"})(so||(so={}));(function(e){e.codec=()=>be(so)})(st||(st={}));var Kt;(function(e){let t;(function(a){a.E_INTERNAL_ERROR="E_INTERNAL_ERROR",a.E_REQUEST_REJECTED="E_REQUEST_REJECTED",a.E_DIAL_REFUSED="E_DIAL_REFUSED",a.OK="OK"})(t=e.ResponseStatus||(e.ResponseStatus={}));let r;(function(a){a[a.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",a[a.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",a[a.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",a[a.OK=200]="OK"})(r||(r={})),(function(a){a.codec=()=>be(r)})(t=e.ResponseStatus||(e.ResponseStatus={}));let n;e.codec=()=>(n==null&&(n=Tt((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&r[a.status]!==0&&(c.uint32(8),e.ResponseStatus.codec().encode(a.status,c)),a.addrIdx!=null&&a.addrIdx!==0&&(c.uint32(16),c.uint32(a.addrIdx)),a.dialStatus!=null&&so[a.dialStatus]!==0&&(c.uint32(24),st.codec().encode(a.dialStatus,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:st.UNUSED},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{f.status=e.ResponseStatus.codec().decode(a);break}case 2:{f.addrIdx=a.uint32();break}case 3:{f.dialStatus=st.codec().decode(a);break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{yield{field:`${u}.status`,value:e.ResponseStatus.codec().decode(a)};break}case 2:{yield{field:`${u}.addrIdx`,value:a.uint32()};break}case 3:{yield{field:`${u}.dialStatus`,value:st.codec().decode(a)};break}default:{a.skipType(d&7);break}}}})),n);function o(a){return It(a,e.codec())}e.encode=o;function s(a,c){return At(a,e.codec(),c)}e.decode=s;function i(a,c){return Bt(a,e.codec(),c)}e.stream=i})(Kt||(Kt={}));var $r;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.data!=null&&s.data.byteLength>0&&(i.uint32(10),i.bytes(s.data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={data:mt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.data=s.bytes():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.data`,value:s.bytes()}:s.skipType(f&7)}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})($r||($r={}));var or;(function(e){let t;e.codec=()=>(t==null&&(t=Tt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.nonce!=null&&s.nonce!==0n&&(i.uint32(9),i.fixed64(s.nonce)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={nonce:0n},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.nonce=s.fixed64():s.skipType(f&7)}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.nonce`,value:s.fixed64()}:s.skipType(f&7)}})),t);function r(s){return It(s,e.codec())}e.encode=r;function n(s,i){return At(s,e.codec(),i)}e.decode=n;function o(s,i){return Bt(s,e.codec(),i)}e.stream=o})(or||(or={}));var ae;(function(e){let t;(function(a){a.OK="OK"})(t=e.DialBackStatus||(e.DialBackStatus={}));let r;(function(a){a[a.OK=0]="OK"})(r||(r={})),(function(a){a.codec=()=>be(r)})(t=e.DialBackStatus||(e.DialBackStatus={}));let n;e.codec=()=>(n==null&&(n=Tt((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&r[a.status]!==0&&(c.uint32(8),e.DialBackStatus.codec().encode(a.status,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.OK},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?f.status=e.DialBackStatus.codec().decode(a):a.skipType(d&7)}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();d>>>3===1?yield{field:`${u}.status`,value:e.DialBackStatus.codec().decode(a)}:a.skipType(d&7)}})),n);function o(a){return It(a,e.codec())}e.encode=o;function s(a,c){return At(a,e.codec(),c)}e.decode=s;function i(a,c){return Bt(a,e.codec(),c)}e.stream=i})(ae||(ae={}));function io(e,t){return Math.round(Math.random()*(t-e)+e)}var Mh=4,Kh=8,ao=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;safeDispatchEvent;constructor(t,r){this.components=t,this.safeDispatchEvent=r.safeDispatchEvent,this.log=t.logger.forComponent("libp2p:auto-nat-v2:client"),this.started=!1,this.dialRequestProtocol=r.dialRequestProtocol,this.dialBackProtocol=r.dialBackProtocol,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.connectionThreshold=r.connectionThreshold??80,this.maxMessageSize=r.maxMessageSize??8192,this.dialResults=ou({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=nu(this.findRandomPeers.bind(this),6e4),this.addressFilter=Vs(1024),this.queue=new oo({concurrency:3,maxSize:50}),this.maxDialDataBytes=r.maxDialDataBytes??au,this.dialDataChunkSize=r.dialDataChunkSize??cu,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[Yr]=["@libp2p/autonat"];get[Gr](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.components.registrar.register(this.dialRequestProtocol,{onConnect:(t,r)=>{this.verifyExternalAddresses(r).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),await this.components.registrar.handle(this.dialBackProtocol,(t,r)=>{this.handleDialBackStream(t,r).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),await this.components.registrar.unhandle(this.dialBackProtocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let r=zr([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:r})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:r})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleDialBackStream(t,r){let n=AbortSignal.timeout(this.timeout);let o=rr(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read(or,{signal:n});if(!this.nonces.has(s.nonce))throw new Et("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:ae.DialBackStatus.OK},ae),await t.close({signal:n})}catch(s){this.log.error("error handling incoming dial back stream - %e",s),t.abort(s)}}getUnverifiedMultiaddrs(t,r){let n=this.components.addressManager.getAddressesWithMetadata().sort((s,i)=>s.type==="observed"&&i.type!=="observed"?1:i.type==="observed"&&s.type!=="observed"?-1:0).filter(s=>{if(!(s.expires<Date.now()))return!1;let a=kr(s.multiaddr);return!(a==null||a.type==="ip6"&&(!r||!Nc(s.multiaddr))||zc(s.multiaddr))}),o=[];for(let s of n){let i=s.multiaddr.toString(),a=this.dialResults.get(i);if(a!=null&&a.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",a.multiaddr,t);continue}if(a==null){let c=s.expires<Date.now();if(c&&this.addressFilter.remove?.(i),this.addressFilter.has(i))continue;this.addressFilter.add(i),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",i),a={multiaddr:s.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:zs(),type:s.type,lastVerified:s.lastVerified},this.dialResults.set(i,a)}o.push(a)}return o}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:a})=>kr(a)?.type==="ip6"),o=kr(t.remoteAddr);if(o?.type!=="ip4"&&o?.type!=="ip6")return;let s=this.getNetworkSegment(t.remoteAddr),i=this.getUnverifiedMultiaddrs(s,n);if(i.length!==0){if(!this.hasConnectionCapacity()){i[0]?.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",i[0].multiaddr),this.confirmAddress(i[0])):this.log("skipping verifying %a because we are too close to the connection limit",i[0]?.multiaddr);return}this.queue.add(async a=>{let c=zr([a.signal,AbortSignal.timeout(this.timeout)]),u=BigInt(io(0,Number.MAX_SAFE_INTEGER));this.nonces.add(u);try{await this.askPeerToVerify(t,s,u,a)}finally{c.clear(),this.nonces.delete(u)}},{peerId:t.remotePeer}).catch(a=>{this.log.error("error from %p verifying addresses - %e",t.remotePeer,a)})}}async askPeerToVerify(t,r,n,o){let s=[...this.dialResults.values()].filter(a=>a.result==null).map(a=>a.multiaddr);if(s.length===0){this.queue.clear();return}this.log.trace("asking %a to verify multiaddrs %s",t.remoteAddr,s);let i=await t.newStream(this.dialRequestProtocol,o);try{let a=rr(i).pb(nr);await a.write({dialRequest:{addrs:s.map(c=>c.bytes),nonce:n}},o);for(let c=0;c<s.length;c++){let u=await a.read(o);if(u.dialDataRequest!=null){if(u.dialDataRequest.numBytes>this.maxDialDataBytes){this.log("too many dial data byte requested by %p - %s/%s",t.remotePeer,u.dialDataRequest.numBytes,this.maxDialDataBytes);continue}this.log("sending %d bytes to %p as anti-amplification attack protection",u.dialDataRequest.numBytes,t.remotePeer);let h=new Uint8Array(this.dialDataChunkSize),I=BigInt(this.dialDataChunkSize);for(let x=0n;x<u.dialDataRequest.numBytes;x+=I)await a.write({dialDataResponse:{data:h}},o);u=await a.read(o)}if(u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}if(u.dialResponse.status!==Kt.ResponseStatus.OK)return;let l=s[u.dialResponse.addrIdx];if(l==null){this.log.trace("peer dialed unknown address");continue}let d=this.dialResults.get(l.toString());if(d==null){this.log.trace("peer reported %a as %s but there is no result object",l,u.dialResponse.status);continue}if(d.networkSegments.includes(r)){this.log.trace("%a results already included network segment %s",l,r);continue}if(d.result!=null){this.log.trace("already resolved result for %a, ignoring response from",l,t.remotePeer);continue}if(d.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,l);continue}if(d.verifyingPeers.add(t.remotePeer),d.networkSegments.push(r),u.dialResponse.dialStatus===st.OK){if(this.log.trace("%p dialed %a successfully",t.remotePeer,d.multiaddr),this.emitReachabilityEvent(d,"verifying"),d.success++,d.type!=="observed"){this.confirmAddress(d);continue}}else if(u.dialResponse.dialStatus===st.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,d.multiaddr),this.emitReachabilityEvent(d,"verifying"),d.failure++;else if(u.dialResponse.dialStatus===st.E_DIAL_BACK_ERROR){this.log.trace("%p saw error while dialing %a",t.remotePeer,d.multiaddr);continue}this.log("%a success %d failure %d",d.multiaddr,d.success,d.failure),d.success===Mh&&this.confirmAddress(d),d.failure===Kh&&this.unconfirmAddress(d)}}finally{try{await i.close(o)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let r=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return r/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,this.emitReachabilityEvent(t,"reachable")}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,this.emitReachabilityEvent(t,"unreachable")}emitReachabilityEvent(t,r){this.safeDispatchEvent(`address:${r}`,{detail:{addr:t.multiaddr,type:t.type,success:t.success,failure:t.failure}})}getNetworkSegment(t){let r=Ve(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 ht(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};var co=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:server"),this.started=!1,this.dialRequestProtocol=r.dialRequestProtocol,this.dialBackProtocol=r.dialBackProtocol,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.maxMessageSize=r.maxMessageSize??8192,this.handleDialRequestStream=this.handleDialRequestStream.bind(this)}async start(){this.started||(await this.components.registrar.handle(this.dialRequestProtocol,this.handleDialRequestStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),this.started=!1}async handleDialRequestStream(t,r){let n=AbortSignal.timeout(this.timeout);let o=rr(t,{maxDataLength:this.maxMessageSize}).pb(nr),s=hu(r.remoteAddr);if(s==null)throw new Et(`Could not find IP address in connection address "${r.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new Et("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new Et("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=eu(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:Kt.ResponseStatus.E_DIAL_REFUSED,dialStatus:st.UNUSED}},{signal:n});continue}let f=hu(c);if(f==null)throw new Et(`Could not find IP address in requested address "${c}"`);if(Zn(f))throw new Et(`Requested address had private IP "${c}"`);f!==s&&await this.preventAmplificationAttack(o,a,{signal:n});let l=await this.dialClientBack(c,i.nonce,{signal:n});await o.write({dialResponse:{addrIdx:a,status:Kt.ResponseStatus.OK,dialStatus:l}},{signal:n})}catch(c){this.log.error("error handling incoming dialback request - %e",c)}await t.close({signal:n})}async preventAmplificationAttack(t,r,n){let o=io(3e4,1e5);await t.write({dialDataRequest:{addrIdx:r,numBytes:BigInt(o)}},n);let s=0;for(;s<o;){let{dialDataResponse:i}=await t.read(n);if(i==null)throw new Et("Did not receive DialDataResponse message on incoming dial request stream");s+=i.data.byteLength}}async dialClientBack(t,r,n){let o;try{o=await this.components.connectionManager.openConnection(t,{force:!0,...n})}catch(s){return this.log.error("failed to open connection to %a - %e",t,s),st.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=rr(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:r},or,n),(await i.read(ae,n)).status!==ae.DialBackStatus.OK)throw new Et("DialBackResponse status was not OK");await o.close(n)}catch(s){return this.log.error("could not perform dial back - %e",s),o.abort(s),st.E_DIAL_BACK_ERROR}return st.OK}};function hu(e){return e.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var uo=class extends Te{client;server;constructor(t,r){super();let n=`/${r.protocolPrefix??wi}/${xi}/${"2"}/${su}`,o=`/${r.protocolPrefix??wi}/${xi}/${"2"}/${iu}`;this.client=new ao(t,{...r,dialRequestProtocol:n,dialBackProtocol:o,safeDispatchEvent:this.safeDispatchEvent.bind(this)}),this.server=new co(t,{...r,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[Yr]=["@libp2p/autonat"];get[Gr](){return["@libp2p/identify"]}async start(){await _i(this.client,this.server)}async stop(){await Ai(this.client,this.server)}};function zh(e={}){return t=>new uo(t,e)}return _u(qh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: