@libp2p/autonat-v2 2.1.2 → 2.1.3

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 fu=Object.create;var Qr=Object.defineProperty;var lu=Object.getOwnPropertyDescriptor;var du=Object.getOwnPropertyNames;var hu=Object.getPrototypeOf,pu=Object.prototype.hasOwnProperty;var fo=(r,t)=>()=>{try{return t||r((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}},bt=(r,t)=>{for(var e in t)Qr(r,e,{get:t[e],enumerable:!0})},vi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of du(t))!pu.call(r,o)&&o!==e&&Qr(r,o,{get:()=>t[o],enumerable:!(n=lu(t,o))||n.enumerable});return r};var mu=(r,t,e)=>(e=r!=null?fu(hu(r)):{},vi(t||!r||!r.__esModule?Qr(e,"default",{value:r,enumerable:!0}):e,r)),gu=r=>vi(Qr({},"__esModule",{value:!0}),r);var Xs=fo(tr=>{"use strict";Object.defineProperty(tr,"__esModule",{value:!0});tr.Netmask4Impl=void 0;tr.ip2long=Je;tr.long2ip=Kt;function Kt(r){let t=(r&-16777216)>>>24,e=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[t,e,n,o].join(".")}var nd=48,od=97,sd=65;function id(r){let t=0,e=10,n="9",o=0;r.length>1&&r[o]==="0"&&(r[o+1]==="x"||r[o+1]==="X"?(o+=2,e=16):"0"<=r[o+1]&&r[o+1]<="9"&&(o++,e=8,n="7"));let s=o;for(;o<r.length;){if("0"<=r[o]&&r[o]<=n)t=t*e+(r.charCodeAt(o)-nd)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-od)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.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 Je(r){let t=[];for(let e=0;e<=3&&r.length!==0;e++){if(e>0){if(r[0]!==".")throw new Error("Invalid IP");r=r.substring(1)}let[n,o]=id(r);r=r.substring(o),t.push(n)}if(r.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 r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;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=Je(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=(Je(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=Kt(this.netLong),this.mask=Kt(this.maskLong),this.hostmask=Kt(~this.maskLong),this.first=this.bitmask<=30?Kt(this.netLong+1):this.base,this.last=this.bitmask<=30?Kt(this.netLong+this.size-2):Kt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Kt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):(Je(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(Kt(this.netLong+this.size*t),this.mask)}forEach(t){let e=Je(this.first),n=Je(this.last),o=0;for(;e<=n;)t(Kt(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};tr.Netmask4Impl=Ys});var Oc=fo(er=>{"use strict";Object.defineProperty(er,"__esModule",{value:!0});er.Netmask6Impl=void 0;er.ip6bigint=Qs;er.bigint2ip6=Ie;var ad=Xs(),Ws=(1n<<128n)-1n;function Qs(r){let t=r.indexOf("%");t!==-1&&(r=r.substring(0,t));let e=r.lastIndexOf(":");if(e!==-1&&r.indexOf(".",e)!==-1){let n=r.substring(e+1),o=(0,ad.ip2long)(n),s=r.substring(0,e+1)+"0:0";return Cc(s)&~0xffffffffn|BigInt(o)}return Cc(r)}function Cc(r){let t=r.indexOf("::"),e;if(t!==-1){let o=r.substring(0,t),s=r.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");e=[...i,...Array(c).fill("0"),...a]}else e=r.split(":");if(e.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+e.length);let n=0n;for(let o=0;o<8;o++){let s=e[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Ie(r){if(r<0n||r>Ws)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(r&0xffffn)),r>>=16n;let e=-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&&(e=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(e=o,n=s),e!==-1&&e+n===8&&e>0)return t.slice(0,e).map(a=>a.toString(16)).join(":")+"::";if(e===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(e>0){let i=t.slice(0,e).map(c=>c.toString(16)),a=t.slice(e+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var Js=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;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=Qs(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Ie(this.netBigint),this.mask=Ie(this.maskBigint),this.hostmask=Ie(~this.maskBigint&Ws),this.first=this.base,this.last=Ie(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.last):(Qs(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(Ie(this.netBigint+e*BigInt(t)),this.bitmask)}forEach(t){let e=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;e<=o;)t(Ie(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};er.Netmask6Impl=Js});var kc=fo(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.long2ip=ce.ip2long=ce.Netmask=void 0;var jn=Xs();Object.defineProperty(ce,"ip2long",{enumerable:!0,get:function(){return jn.ip2long}});Object.defineProperty(ce,"long2ip",{enumerable:!0,get:function(){return jn.long2ip}});var cd=Oc(),ti=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new cd.Netmask6Impl(t,e):this._impl=new jn.Netmask4Impl(t,e),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 r(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new r(t))),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let e=this._impl.next(t);return new r(e.base,e.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ce.Netmask=ti});var Ah={};bt(Ah,{autoNATv2:()=>_h});var qt=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 tn=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 fr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var lo=Symbol.for("@libp2p/peer-id");function _i(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Ai(...r){let t=[];for(let e of r)_i(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(t.map(async e=>{await e.start()})),await Promise.all(t.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function Ii(...r){let t=[];for(let e of r)_i(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(t.map(async e=>{await e.stop()})),await Promise.all(t.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}function yu(r){return typeof r?.handleEvent=="function"}function bu(r){return(r!==!0&&r!==!1&&r?.once)??!1}var Le=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){let o=bu(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==e),this.#t.set(i.type,a))}yu(e)?e.handleEvent(i):e(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:o})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var en=Symbol.for("@libp2p/service-capabilities"),rn=Symbol.for("@libp2p/service-dependencies");var yo={};bt(yo,{base58btc:()=>Z,base58flickr:()=>Iu});var rp=new Uint8Array(0);function Ti(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function St(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return fe(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return fe(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Di(r){let t=new Uint8Array(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}var Bi=4096;function Li(r){let t=r.length;if(t<=Bi)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.subarray(n,n+=Bi));return e}function xu(r){return r?.buffer instanceof ArrayBuffer}function fe(r){return xu(r)?r:r.slice()}function wu(r,t,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,e){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=r.length,l=r.charAt(0),d=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function S(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,A=0,R=0,D=g.length;R!==D&&g[R]===0;)R++,w++;for(var P=(D-R)*p+1>>>0,C=new Uint8Array(P);R!==D;){for(var I=g[R],F=0,N=P-1;(I!==0||F<A)&&N!==-1;N--,F++)I+=256*C[N]>>>0,C[N]=I%f>>>0,I=I/f>>>0;if(I!==0)throw new Error("Non-zero carry");A=F,R++}for(var k=P-A;k!==P&&C[k]===0;)k++;for(var h=l.repeat(w);k<P;++k)h+=r.charAt(C[k]);return h}function v(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var A=0,R=0;g[w]===l;)A++,w++;for(var D=(g.length-w)*d+1>>>0,P=new Uint8Array(D);g[w];){var C=n[g.charCodeAt(w)];if(C===255)return;for(var I=0,F=D-1;(C!==0||I<R)&&F!==-1;F--,I++)C+=f*P[F]>>>0,P[F]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");R=I,w++}if(g[w]!==" "){for(var N=D-R;N!==D&&P[N]===0;)N++;for(var k=new Uint8Array(A+(D-N)),h=A;N!==D;)k[h++]=P[N++];return k}}}function m(g){var w=v(g);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:S,decodeUnsafe:v,decode:m}}var Eu=wu,Su=Eu,Ci=Su;var ho=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},po=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Oi(this,t)}},mo=class{decoders;constructor(t){this.decoders=t}or(t){return Oi(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Oi(r,t){return new mo({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var go=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new ho(t,e,n),this.decoder=new po(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Re({name:r,prefix:t,encode:e,decode:n}){return new go(r,t,e,n)}function Xt({name:r,prefix:t,alphabet:e,caseInsensitive:n=!1}){let{encode:o,decode:s}=Ci(e,r,n);return Re({prefix:t,name:r,encode:o,decode:i=>St(s(i))})}function vu(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function _u(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Au(r,t){let e={};for(let n=0;n<r.length;++n)if(e[r[n]]=n,t){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(e[o]=n),s!==r[n]&&(e[s]=n)}return e}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n,caseInsensitive:o=!1}){let s=Au(n,o);return Re({prefix:t,name:r,encode(i){return _u(i,n,e)},decode(i){return vu(i,s,e,r)}})}var Z=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Iu=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bo={};bt(bo,{base32:()=>Wt,base32hex:()=>Lu,base32hexpad:()=>Cu,base32hexpadupper:()=>Ou,base32hexupper:()=>Ru,base32pad:()=>Tu,base32padupper:()=>Du,base32upper:()=>Bu,base32z:()=>ku});var Wt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Bu=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Tu=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Du=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Lu=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Ru=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Cu=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Ou=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),ku=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xo={};bt(xo,{base36:()=>lr,base36upper:()=>Pu});var lr=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Pu=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Fu=Fi,ki=128,Nu=127,Uu=~Nu,Mu=Math.pow(2,31);function Fi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Mu;)t[e++]=r&255|ki,r/=128;for(;r&Uu;)t[e++]=r&255|ki,r>>>=7;return t[e]=r|0,Fi.bytes=e-n+1,t}var Ku=wo,zu=128,Pi=127;function wo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw wo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Pi)<<o:(i&Pi)*Math.pow(2,o),o+=7}while(i>=zu);return wo.bytes=s-n,e}var qu=Math.pow(2,7),Vu=Math.pow(2,14),Hu=Math.pow(2,21),$u=Math.pow(2,28),ju=Math.pow(2,35),Gu=Math.pow(2,42),Zu=Math.pow(2,49),Yu=Math.pow(2,56),Xu=Math.pow(2,63),Wu=function(r){return r<qu?1:r<Vu?2:r<Hu?3:r<$u?4:r<ju?5:r<Gu?6:r<Zu?7:r<Yu?8:r<Xu?9:10},Qu={encode:Fu,decode:Ku,encodingLength:Wu},Ju=Qu,dr=Ju;function hr(r,t=0){let e=dr.decode(r,t),n=dr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[e,n]}function Ce(r,t,e=0){return dr.encode(r,t,e),t}function Oe(r){return dr.encodingLength(r)}function Pe(r,t){let e=t.byteLength,n=Oe(r),o=n+Oe(e),s=new Uint8Array(o+e);return Ce(r,s,0),Ce(e,s,n),s.set(t,o),new ke(r,e,t,s)}function pr(r){let t=St(r),[e,n]=hr(t),[o,s]=hr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ke(e,o,i,t)}function Ni(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ti(r.bytes,e.bytes)}}var ke=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=fe(n),this.bytes=fe(o)}};function Ui(r,t){let{bytes:e,version:n}=r;return n===0?ef(e,Eo(r),t??Z.encoder):rf(e,Eo(r),t??Wt.encoder)}var Mi=new WeakMap;function Eo(r){let t=Mi.get(r);if(t==null){let e=new Map;return Mi.set(r,e),e}return t}var ct=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=fe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==mr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==nf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Pe(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ni(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Ki(n,o,s.bytes))}else if(e[of]===!0){let{version:n,multihash:o,code:s}=e,i=pr(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==mr)throw new Error(`Version 0 CID must use dag-pb (code: ${mr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ki(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,mr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=St(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ke(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,d]=hr(t.subarray(e));return e+=d,l},o=n(),s=mr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,e){let[n,o]=tf(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Eo(s).set(n,t),s}};function tf(r,t){switch(r[0]){case"Q":{let e=t??Z;return[Z.prefix,e.decode(`${Z.prefix}${r}`)]}case Z.prefix:{let e=t??Z;return[Z.prefix,e.decode(r)]}case Wt.prefix:{let e=t??Wt;return[Wt.prefix,e.decode(r)]}case lr.prefix:{let e=t??lr;return[lr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function ef(r,t,e){let{prefix:n}=e;if(n!==Z.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function rf(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var mr=112,nf=18;function Ki(r,t,e){let n=Oe(r),o=n+Oe(t),s=new Uint8Array(o+e.byteLength);return Ce(r,s,0),Ce(t,s,n),s.set(e,o),s}var of=Symbol.for("@ipld/js-cid/CID");var So={};bt(So,{identity:()=>Bt});var zi=0,sf="identity",qi=St;function af(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Pe(zi,qi(r))}var Bt={code:zi,name:sf,encode:qi,digest:af};function ut(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function cf(r){return r.buffer instanceof ArrayBuffer}function Tt(r){return cf(r)?r:r.slice()}async function Vi(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Tt(t),Tt(e.subarray()));return n?.signal?.throwIfAborted(),s}function gt(r=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function uf(r){return r?.buffer instanceof ArrayBuffer}function vo(r){if(uf(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ft(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return vo(e)}var $i=Symbol.for("@achingbrain/uint8arraylist");function Hi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function on(r){return!!r?.[$i]}var et=class r{bufs;length;[$i]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(on(n)){e+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(on(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Hi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Hi(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(on(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Ft(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Ft(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=e>a&&e<=c;if(u&&f){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!on(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let 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=e;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){f=Math.max(1,d-a[p]);break}}if(f===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=gt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=gt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=gt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=gt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=gt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!ut(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var _o={};bt(_o,{base10:()=>ff});var ff=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Ao={};bt(Ao,{base16:()=>lf,base16upper:()=>df});var lf=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),df=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Io={};bt(Io,{base2:()=>hf});var hf=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Bo={};bt(Bo,{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}"),pf=ji.reduce((r,t,e)=>(r[e]=t,r),[]),mf=ji.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function gf(r){return r.reduce((t,e)=>(t+=pf[e],t),"")}function yf(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=mf[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var bf=Re({prefix:"\u{1F680}",name:"base256emoji",encode:gf,decode:yf});var Do={};bt(Do,{base64:()=>xf,base64pad:()=>wf,base64url:()=>To,base64urlpad:()=>Ef});var xf=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),wf=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),To=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ef=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Lo={};bt(Lo,{base8:()=>Sf});var Sf=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ro={};bt(Ro,{identity:()=>vf});var vf=Re({prefix:"\0",name:"identity",encode:r=>Li(St(r)),decode:r=>St(Di(r))});var zp=new TextEncoder,qp=new TextDecoder;var ko={};bt(ko,{sha256:()=>gr,sha512:()=>Bf});var If=20;function Oo({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Co(r,t,e,n,o)}var Co=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??If,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Gi(n,this.code,e?.truncate):n.then(o=>Gi(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Gi(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Pe(t,r)}function Yi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var gr=Oo({name:"sha2-256",code:18,encode:Yi("SHA-256")}),Bf=Oo({name:"sha2-512",code:19,encode:Yi("SHA-512")});var yr={...Ro,...Io,...Lo,..._o,...Ao,...bo,...xo,...yo,...Do,...Bo},t0={...ko,...So};function Wi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Xi=Wi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Po=Wi("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Tf={utf8:Xi,"utf-8":Xi,hex:yr.base16,latin1:Po,ascii:Po,binary:Po,...yr},sn=Tf;function V(r,t="utf8"){let e=sn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function X(r,t="utf8"){let e=sn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Df=parseInt("11111",2),Fo=parseInt("10000000",2),Lf=parseInt("01111111",2),Qi={0:br,1:br,2:Rf,3:kf,4:Pf,5:Of,6:Cf,16:br,22:br,48:br};function No(r,t={offset:0}){let e=r[t.offset]&Df;if(t.offset++,Qi[e]!=null)return Qi[e](r,t);throw new Error("No decoder for tag "+e)}function xr(r,t){let e=0;if((r[t.offset]&Fo)===Fo){let n=r[t.offset]&Lf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=r.byteLength)throw new Error("invalid DER element length");o+=r[t.offset].toString(16).padStart(2,"0")}e=parseInt(o,16)}else e=r[t.offset],t.offset++;if(!Number.isInteger(e)||e<0||e>r.byteLength-t.offset)throw new Error("invalid DER element length");return e}function br(r,t){xr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=No(r,t);if(n===null)break;e.push(n)}return e}function Rf(r,t){let e=xr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Cf(r,t){let e=xr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Of(r,t){return t.offset++,null}function kf(r,t){let e=xr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Pf(r,t){let e=xr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Ff(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new et;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Uo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Ff(r.byteLength);return new et(Uint8Array.from([t.byteLength|Fo]),t)}function Ji(r){let t=new et,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new et(Uint8Array.from([2]),Uo(t),t)}function ta(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),Uo(e),e)}function an(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),Uo(e),e)}var Nf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Uf=Uint8Array.from([6,5,43,129,4,0,34]),Mf=Uint8Array.from([6,5,43,129,4,0,35]),Kf={ext:!0,kty:"EC",crv:"P-256"},zf={ext:!0,kty:"EC",crv:"P-384"},qf={ext:!0,kty:"EC",crv:"P-521"},Mo=32,Ko=48,zo=66;function ea(r){let t=No(r);return ra(t)}function ra(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Mo*2+1)return n=X(t.subarray(e,e+Mo),"base64url"),o=X(t.subarray(e+Mo),"base64url"),new Fe({...Kf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ko*2+1)return n=X(t.subarray(e,e+Ko),"base64url"),o=X(t.subarray(e+Ko),"base64url"),new Fe({...zf,key_ops:["verify"],x:n,y:o});if(t.byteLength===zo*2+1)return n=X(t.subarray(e,e+zo),"base64url"),o=X(t.subarray(e+zo),"base64url"),new Fe({...qf,key_ops:["verify"],x:n,y:o});throw new ht(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function na(r){return an([Ji(Uint8Array.from([1])),an([Vf(r.crv)],160),an([ta(new et(Uint8Array.from([4]),V(r.x??"","base64url"),V(r.y??"","base64url")))],161)]).subarray()}function Vf(r){if(r==="P-256")return Nf;if(r==="P-384")return Uf;if(r==="P-521")return Mf;throw new ht(`Invalid curve ${r}`)}var Fe=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 Bt.digest(Ne(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}async verify(t,e,n){return Vi(this.jwk,e,t,n)}};function qo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Qt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${r}`)}}function xt(r,t,e=""){let n=qo(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return r}function cn(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Qt(r.outputLen),Qt(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ue(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function un(r,t){xt(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new RangeError('"digestInto() output" expected to be of length >='+e)}function Ht(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function fn(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Dt(r,t){return r<<32-t|r>>>t}var sa=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Hf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ln(r){if(xt(r),sa)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Hf[r[e]];return t}var Vt={_0:48,_9:57,A:65,F:70,a:97,f:102};function oa(r){if(r>=Vt._0&&r<=Vt._9)return r-Vt._0;if(r>=Vt.A&&r<=Vt.F)return r-(Vt.A-10);if(r>=Vt.a&&r<=Vt.f)return r-(Vt.a-10)}function wr(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(sa)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=oa(r.charCodeAt(s)),a=oa(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Vo(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];xt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Ho(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function ia(r=32){Qt(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var $o=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function aa(r,t,e){return r&t^~r&e}function ca(r,t,e){return r&t^r&e^t&e}var Er=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=fn(this.buffer)}update(t){Ue(this),xt(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=fn(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ue(this),un(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Ht(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=fn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},$t=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var dn=BigInt(4294967295),ua=BigInt(32);function $f(r,t=!1){return t?{h:Number(r&dn),l:Number(r>>ua&dn)}:{h:Number(r>>ua&dn)|0,l:Number(r&dn)|0}}function fa(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=$f(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var jo=(r,t,e)=>r>>>e,Go=(r,t,e)=>r<<32-e|t>>>e,de=(r,t,e)=>r>>>e|t<<32-e,he=(r,t,e)=>r<<32-e|t>>>e,Sr=(r,t,e)=>r<<64-e|t>>>e-32,vr=(r,t,e)=>r>>>e-32|t<<64-e;function Nt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var la=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),da=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ha=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),pa=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ma=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ga=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Gf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jt=new Uint32Array(64),Zo=class extends Er{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)Jt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=Jt[l-15],p=Jt[l-2],S=Dt(d,7)^Dt(d,18)^d>>>3,v=Dt(p,17)^Dt(p,19)^p>>>10;Jt[l]=v+Jt[l-7]+S+Jt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Dt(a,6)^Dt(a,11)^Dt(a,25),p=f+d+aa(a,c,u)+Gf[l]+Jt[l]|0,v=(Dt(n,2)^Dt(n,13)^Dt(n,22))+ca(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+v|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(){Ht(Jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ht(this.buffer)}},Yo=class extends Zo{A=$t[0]|0;B=$t[1]|0;C=$t[2]|0;D=$t[3]|0;E=$t[4]|0;F=$t[5]|0;G=$t[6]|0;H=$t[7]|0;constructor(){super(32)}};var ya=fa(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Zf=ya[0],Yf=ya[1],te=new Uint32Array(80),ee=new Uint32Array(80),Xo=class extends Er{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:p,Gl:S,Hh:v,Hl:m}=this;return[t,e,n,o,s,i,a,c,u,f,l,d,p,S,v,m]}set(t,e,n,o,s,i,a,c,u,f,l,d,p,S,v,m){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=S|0,this.Hh=v|0,this.Hl=m|0}process(t,e){for(let A=0;A<16;A++,e+=4)te[A]=t.getUint32(e),ee[A]=t.getUint32(e+=4);for(let A=16;A<80;A++){let R=te[A-15]|0,D=ee[A-15]|0,P=de(R,D,1)^de(R,D,8)^jo(R,D,7),C=he(R,D,1)^he(R,D,8)^Go(R,D,7),I=te[A-2]|0,F=ee[A-2]|0,N=de(I,F,19)^Sr(I,F,61)^jo(I,F,6),k=he(I,F,19)^vr(I,F,61)^Go(I,F,6),h=ha(C,k,ee[A-7],ee[A-16]),y=pa(h,P,N,te[A-7],te[A-16]);te[A]=y|0,ee[A]=h|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:S,Gh:v,Gl:m,Hh:g,Hl:w}=this;for(let A=0;A<80;A++){let R=de(l,d,14)^de(l,d,18)^Sr(l,d,41),D=he(l,d,14)^he(l,d,18)^vr(l,d,41),P=l&p^~l&v,C=d&S^~d&m,I=ma(w,D,C,Yf[A],ee[A]),F=ga(I,g,R,P,Zf[A],te[A]),N=I|0,k=de(n,o,28)^Sr(n,o,34)^Sr(n,o,39),h=he(n,o,28)^vr(n,o,34)^vr(n,o,39),y=n&s^n&a^s&a,E=o&i^o&c^i&c;g=v|0,w=m|0,v=p|0,m=S|0,p=l|0,S=d|0,{h:l,l:d}=Nt(u|0,f|0,F|0,N|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let x=la(N,h,E);n=da(x,F,k,y),o=x|0}({h:n,l:o}=Nt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Nt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Nt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Nt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Nt(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:S}=Nt(this.Fh|0,this.Fl|0,p|0,S|0),{h:v,l:m}=Nt(this.Gh|0,this.Gl|0,v|0,m|0),{h:g,l:w}=Nt(this.Hh|0,this.Hl|0,g|0,w|0),this.set(n,o,s,i,a,c,u,f,l,d,p,S,v,m,g,w)}roundClean(){Ht(te,ee)}destroy(){this.destroyed=!0,Ht(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Wo=class extends Xo{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var ba=Ho(()=>new Yo,$o(1));var hn=Ho(()=>new Wo,$o(3));var K=(r,t,e)=>xt(r,t,e),Jo=Qt,Me=ln,Q=(...r)=>Vo(...r),Ke=r=>wr(r),pe=qo,_r=r=>ia(r),mn=BigInt(0),Qo=BigInt(1);function Lt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function gn(r){if(typeof r=="bigint"){if(!pn(r))throw new RangeError("positive bigint expected, got "+r)}else Jo(r);return r}function Rt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+r)}}function Ar(r){let t=gn(r).toString(16);return t.length&1?"0"+t:t}function xa(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?mn:BigInt("0x"+r)}function me(r){return xa(ln(r))}function Ut(r){return xa(ln(Ir(xt(r)).reverse()))}function yn(r,t){if(Qt(t),t===0)throw new RangeError("zero length");r=gn(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return wr(e.padStart(t*2,"0"))}function ts(r,t){return yn(r,t).reverse()}function wa(r,t){if(r=K(r),t=K(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Ir(r){return Uint8Array.from(K(r))}function bn(r){if(typeof r!="string")throw new TypeError("ascii string expected, got "+typeof r);return Uint8Array.from(r,(t,e)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${r[e]}" with code ${n} at position ${e}`);return n})}var pn=r=>typeof r=="bigint"&&mn<=r;function Xf(r,t,e){return pn(r)&&pn(t)&&pn(e)&&t<=r&&r<e}function ze(r,t,e,n){if(!Xf(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function qe(r){if(r<mn)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>mn;r>>=Qo,t+=1);return t}var Br=r=>(Qo<<BigInt(r))-Qo;function Ea(r,t,e){if(Qt(r,"hashLen"),Qt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...m)=>e(u,Q(c,...m)),p=(m=o)=>{u=d(s,m),c=d(),m.length!==0&&(u=d(i,m),c=d())},S=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,g=[];for(;m<t;){c=d();let w=c.slice();g.push(w),m+=c.length}return Q(...g)};return(m,g)=>{l(),p(m);let w;for(;(w=g(S()))===void 0;)p();return l(),w}}function Ct(r,t={},e={}){if(Object.prototype.toString.call(r)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(r,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=r[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}var es=()=>{throw new Error("not implemented")};var st=BigInt(0),j=BigInt(1),ge=BigInt(2),Aa=BigInt(3),Ia=BigInt(4),Ba=BigInt(5),Wf=BigInt(7),Ta=BigInt(8),Qf=BigInt(9),Da=BigInt(16);function Y(r,t){if(t<=st)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=st?e:t+e}function H(r,t,e){if(t<st)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >st;)n*=n,n%=e;return n}function Sa(r,t){if(r===st)throw new Error("invert: expected non-zero number");if(t<=st)throw new Error("invert: expected positive modulus, got "+t);let e=Y(r,t),n=t,o=st,s=j,i=j,a=st;for(;e!==st;){let u=n/e,f=n-e*u,l=o-i*u,d=s-a*u;n=e,e=f,o=i,s=a,i=l,a=d}if(n!==j)throw new Error("invert: does not exist");return Y(o,t)}function rs(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function La(r,t){let e=r,n=(e.ORDER+j)/Ia,o=e.pow(t,n);return rs(e,o,t),o}function Jf(r,t){let e=r,n=(e.ORDER-Ba)/Ta,o=e.mul(t,ge),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,ge),s),c=e.mul(i,e.sub(a,e.ONE));return rs(e,c,t),c}function tl(r){let t=Ve(r),e=Ra(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Wf)/Da;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),p=u.mul(f,s),S=u.eql(u.sqr(l),c),v=u.eql(u.sqr(d),c);f=u.cmov(f,l,S),l=u.cmov(p,d,v);let m=u.eql(u.sqr(l),c),g=u.cmov(f,l,m);return rs(u,g,c),g})}function Ra(r){if(r<Aa)throw new Error("sqrt is not defined for small field");let t=r-j,e=0;for(;t%ge===st;)t/=ge,e++;let n=ge,o=Ve(r);for(;va(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return La;let s=o.pow(n,t),i=(t+j)/ge;return function(c,u){let f=c;if(f.is0(u))return u;if(va(f,u)!==1)throw new Error("Cannot find square root");let l=e,d=f.mul(f.ONE,s),p=f.pow(u,t),S=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))return f.ZERO;let v=1,m=f.sqr(p);for(;!f.eql(m,f.ONE);)if(v++,m=f.sqr(m),v===l)throw new Error("Cannot find square root");let g=j<<BigInt(l-v-1),w=f.pow(d,g);l=v,d=f.sqr(w),p=f.mul(p,d),S=f.mul(S,w)}return S}}function el(r){return r%Ia===Aa?La:r%Ta===Ba?Jf:r%Da===Qf?tl(r):Ra(r)}var jt=(r,t)=>(Y(r,t)&j)===j,rl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ns(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=rl.reduce((n,o)=>(n[o]="function",n),t);if(Ct(r,e),Rt(r.BYTES,"BYTES"),Rt(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=j)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function nl(r,t,e){let n=r;if(e<st)throw new Error("invalid exponent, negatives unsupported");if(e===st)return n.ONE;if(e===j)return t;let o=n.ONE,s=t;for(;e>st;)e&j&&(o=n.mul(o,s)),s=n.sqr(s),e>>=j;return o}function Tr(r,t,e=!1){let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function va(r,t){let e=r,n=(e.ORDER-j)/ge,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),a=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ol(r,t){if(t!==void 0&&Jo(t),r<=st)throw new Error("invalid n length: expected positive n, got "+r);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=qe(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${t})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var _a=new WeakMap,xn=class{ORDER;BITS;BYTES;isLE;ZERO=st;ONE=j;_lengths;_mod;constructor(t,e={}){if(t<=j)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=ol(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 Y(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return st<=t&&t<this.ORDER}is0(t){return t===st}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&j)===j}neg(t){return Y(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Y(t*t,this.ORDER)}add(t,e){return Y(t+e,this.ORDER)}sub(t,e){return Y(t-e,this.ORDER)}mul(t,e){return Y(t*e,this.ORDER)}pow(t,e){return nl(this,t,e)}div(t,e){return Y(t*Sa(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Sa(t,this.ORDER)}sqrt(t){let e=_a.get(this);return e||_a.set(this,e=el(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?ts(t,this.BYTES):yn(t,this.BYTES)}fromBytes(t,e=!1){K(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?Ut(t):me(t);if(a&&(c=Y(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Tr(this,t)}cmov(t,e,n){return Lt(n,"condition"),n?e:t}};Object.freeze(xn.prototype);function Ve(r,t={}){return new xn(r,t)}function Ca(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=j)throw new Error("field order must be greater than 1");let t=qe(r-j);return Math.ceil(t/8)}function os(r){let t=Ca(r);return t+Math.ceil(t/2)}function ss(r,t,e=!1){K(r);let n=r.length,o=Ca(t),s=Math.max(os(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Ut(r):me(r),a=Y(i,t-j)+j;return e?ts(a,o):yn(a,o)}var He=BigInt(0),ye=BigInt(1);function Dr(r,t){let e=t.negate();return r?e:t}function be(r,t){let e=Tr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Fa(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function is(r,t){Fa(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=Br(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Oa(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ye);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,p=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:p,offsetF:u}}var as=new WeakMap,Na=new WeakMap;function cs(r){return Na.get(r)||1}function ka(r){if(r!==He)throw new Error("invalid wNAF")}var $e=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>He;)e&ye&&(n=n.add(o)),o=o.double(),e>>=ye;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=is(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=is(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:p}=Oa(n,a,i);n=c,f?s=s.add(Dr(d,e[p])):o=o.add(Dr(l,e[u]))}return ka(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=is(t,this.bits);for(let i=0;i<s.windows&&n!==He;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Oa(n,i,s);if(n=a,!u){let l=e[c];o=o.add(f?l.negate():l)}}return ka(n),o}getPrecomputes(t,e,n){let o=as.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),as.set(e,o))),o}cached(t,e,n){let o=cs(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=cs(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Fa(e,this.bits),Na.set(t,e),as.delete(t)}hasCache(t){return cs(t)!==1}};function Ua(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>He||n>He;)e&ye&&(s=s.add(o)),n&ye&&(i=i.add(o)),o=o.double(),e>>=ye,n>>=ye;return{p1:s,p2:i}}function Pa(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ns(t),t}else return Ve(r,{isLE:e})}function wn(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>He))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Pa(t.p,e.Fp,n),s=Pa(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function En(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var re=BigInt(0),rt=BigInt(1),us=BigInt(2),sl=BigInt(8);function il(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Ma(r,t={}){let e=t,n=wn("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Ct(e,{},{uvRatio:"function"});let c=us<<BigInt(s.BYTES*8)-rt,u=v=>o.create(v),f=e.uvRatio===void 0?(v,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,m))}}catch{return{isValid:!1,value:re}}}:e.uvRatio;if(!il(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(v,m,g=!1){let w=g?rt:re;return ze("coordinate "+v,m,w,c),m}function d(v){if(!(v instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,rt,u(i.Gx*i.Gy));static ZERO=new p(re,rt,rt,re);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,g,w,A){this.X=l("x",m),this.Y=l("y",g),this.Z=l("z",w,!0),this.T=l("t",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:g,y:w}=m||{};return l("x",g),l("y",w),new p(g,w,rt,u(g*w))}static fromBytes(m,g=!1){let w=o.BYTES,{a:A,d:R}=i;m=Ir(K(m,w,"point")),Lt(g,"zip215");let D=Ir(m),P=m[w-1];D[w-1]=P&-129;let C=Ut(D),I=g?c:o.ORDER;ze("point.y",C,re,I);let F=u(C*C),N=u(F-rt),k=u(R*F-A),{isValid:h,value:y}=f(N,k);if(!h)throw new Error("bad point: invalid y coordinate");let E=(y&rt)===rt,x=(P&128)!==0;if(!g&&y===re&&x)throw new Error("bad point: x=0 and x_0=1");return x!==E&&(y=u(-y)),p.fromAffine({x:y,y:C})}static fromHex(m,g=!1){return p.fromBytes(Ke(m),g)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,g=!0){return S.createCache(this,m),g||this.multiply(us),this}assertValidity(){let m=this,{a:g,d:w}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:A,Y:R,Z:D,T:P}=m,C=u(A*A),I=u(R*R),F=u(D*D),N=u(F*F),k=u(C*g),h=u(F*u(k+I)),y=u(N+u(w*u(C*I)));if(h!==y)throw new Error("bad point: equation left != right (1)");let E=u(A*R),x=u(D*P);if(E!==x)throw new Error("bad point: equation left != right (2)")}equals(m){d(m);let{X:g,Y:w,Z:A}=this,{X:R,Y:D,Z:P}=m,C=u(g*P),I=u(R*A),F=u(w*P),N=u(D*A);return C===I&&F===N}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:m}=i,{X:g,Y:w,Z:A}=this,R=u(g*g),D=u(w*w),P=u(us*u(A*A)),C=u(m*R),I=g+w,F=u(u(I*I)-R-D),N=C+D,k=N-P,h=C-D,y=u(F*k),E=u(N*h),x=u(F*h),b=u(k*N);return new p(y,E,b,x)}add(m){d(m);let{a:g,d:w}=i,{X:A,Y:R,Z:D,T:P}=this,{X:C,Y:I,Z:F,T:N}=m,k=u(A*C),h=u(R*I),y=u(P*w*N),E=u(D*F),x=u((A+R)*(C+I)-k-h),b=E-y,_=E+y,T=u(h-g*k),B=u(x*b),L=u(_*T),O=u(x*T),M=u(b*_);return new p(B,L,M,O)}subtract(m){return d(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:g,f:w}=S.cached(this,m,A=>be(p,A));return be(p,[g,w])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===re?p.ZERO:this.is0()||m===rt?this:S.unsafe(this,m,g=>be(p,g))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.unsafe(this,i.n).is0()}toAffine(m){let g=this,w=m,{X:A,Y:R,Z:D}=g,P=g.is0();w==null&&(w=P?sl:o.inv(D));let C=u(A*w),I=u(R*w),F=o.mul(D,w);if(P)return{x:re,y:rt};if(F!==rt)throw new Error("invZ was invalid");return{x:C,y:I}}clearCofactor(){return a===rt?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:g}=this.toAffine(),w=o.toBytes(g);return w[w.length-1]|=m&rt?128:0,w}toHex(){return Me(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let S=new $e(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Sn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){es()}static fromHex(t){es()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Me(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.ep.precompute(t,e),this}};function Ka(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;Ct(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Rt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?_r:o.randomBytes,d=o.adjustScalarBytes===void 0?h=>h:o.adjustScalarBytes,p=o.domain===void 0?(h,y,E)=>{if(Lt(E,"phflag"),y.length||E)throw new Error("Contexts/pre-hash are not supported");return h}:o.domain;function S(h){return c.create(Ut(h))}function v(h){let y=C.secretKey;K(h,C.secretKey,"secretKey");let E=K(n(h),2*y,"hashedSecretKey"),x=d(E.slice(0,y)),b=E.slice(y,2*y),_=S(x);return{head:x,prefix:b,scalar:_}}function m(h){let{head:y,prefix:E,scalar:x}=v(h),b=i.multiply(x),_=b.toBytes();return{head:y,prefix:E,scalar:x,point:b,pointBytes:_}}function g(h){return m(h).pointBytes}function w(h=Uint8Array.of(),...y){let E=Q(...y);return S(n(p(E,K(h,void 0,"context"),!!s)))}function A(h,y,E={}){h=K(h,void 0,"message"),s&&(h=s(h));let{prefix:x,scalar:b,pointBytes:_}=m(y),T=w(E.context,x,h),B=i.multiply(T).toBytes(),L=w(E.context,B,_,h),O=c.create(T+L*b);if(!c.isValid(O))throw new Error("sign failed: invalid s");let M=Q(B,c.toBytes(O));return K(M,C.signature,"result")}let R={zip215:o.zip215};function D(h,y,E,x=R){let{context:b}=x,_=x.zip215===void 0?!!R.zip215:x.zip215,T=C.signature;h=K(h,T,"signature"),y=K(y,void 0,"message"),E=K(E,C.publicKey,"publicKey"),_!==void 0&&Lt(_,"zip215"),s&&(y=s(y));let B=T/2,L=h.subarray(0,B),O=Ut(h.subarray(B,T)),M,z,U;try{M=r.fromBytes(E,_),z=r.fromBytes(L,_),U=i.multiplyUnsafe(O)}catch{return!1}if(!_&&M.isSmallOrder())return!1;let W=w(b,L,E,y);return z.add(M.multiplyUnsafe(W)).subtract(U).clearCofactor().is0()}let P=a.BYTES,C={secretKey:P,publicKey:P,signature:2*P,seed:P};function I(h){return h=h===void 0?l(C.seed):h,K(h,C.seed,"seed")}function F(h){return pe(h)&&h.length===C.secretKey}function N(h,y){try{return!!r.fromBytes(h,y===void 0?R.zip215:y)}catch{return!1}}let k={getExtendedPublicKey:m,randomSecretKey:I,isValidSecretKey:F,isValidPublicKey:N,toMontgomery(h){let{y}=r.fromBytes(h),E=C.publicKey,x=E===32;if(!x&&E!==57)throw new Error("only defined for 25519 and 448");let b=x?a.div(rt+y,rt-y):a.div(y-rt,y+rt);return a.toBytes(b)},toMontgomerySecret(h){let y=C.secretKey;K(h,y);let E=n(h.subarray(0,y));return d(E).subarray(0,y)}};return Object.freeze(C),Object.freeze(k),Object.freeze({keygen:En(I,g),getPublicKey:g,sign:A,verify:D,utils:k,Point:r,lengths:C})}function Lr(r,t){if(Rt(r),Rt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(r<0||r>2**(8*t)-1)throw new Error("invalid I2OSP input: "+r);let e=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)e[n]=r&255,r>>>=8;return new Uint8Array(e)}function al(r,t){let e=new Uint8Array(r.length);for(let n=0;n<r.length;n++)e[n]=r[n]^t[n];return e}function cl(r){if(!pe(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?bn(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function fs(r,t,e,n){K(r),Rt(e),t=cl(t),t.length>255&&(t=n(Q(bn("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(e/o);if(e>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=Q(t,Lr(t.length,1)),c=new Uint8Array(s),u=Lr(e,2),f=new Array(i),l=n(Q(c,r,u,Lr(0,1),a));f[0]=n(Q(l,Lr(1,1),a));for(let p=1;p<i;p++){let S=[al(l,f[p-1]),Lr(p+1,1),a];f[p]=n(Q(...S))}return Q(...f).slice(0,e)}var za="HashToScalar-";var ul=BigInt(0),Gt=BigInt(1),qa=BigInt(2);var fl=BigInt(5),ll=BigInt(8),je=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ps={p:je,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ll,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function dl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=je,a=r*r%s*r%s,c=H(a,qa,s)*a%s,u=H(c,Gt,s)*r%s,f=H(u,fl,s)*u%s,l=H(f,t,s)*f%s,d=H(l,e,s)*l%s,p=H(d,n,s)*d%s,S=H(p,o,s)*p%s,v=H(S,o,s)*p%s,m=H(v,t,s)*f%s;return{pow_p_5_8:H(m,qa,s)*r%s,b2:a}}function hl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ls=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ms(r,t){let e=je,n=Y(t*t*t,e),o=Y(n*n*t,e),s=dl(r*o).pow_p_5_8,i=Y(r*n*s,e),a=Y(t*i*i,e),c=i,u=Y(i*ls,e),f=a===r,l=a===Y(-r,e),d=a===Y(-r*ls,e);return f&&(i=c),(l||d)&&(i=u),jt(i,e)&&(i=Y(-i,e)),{isValid:f||l,value:i}}var oe=Ma(ps,{uvRatio:ms}),ne=oe.Fp,$a=oe.Fn;function pl(r){return Ka(oe,hn,Object.assign({adjustScalarBytes:hl,zip215:!0},r))}var ja=pl({});var ds=ls,ml=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),gl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),yl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),bl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Va=r=>ms(Gt,r),xl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),hs=r=>ne.create(Ut(r)&xl);function Ha(r){let{d:t}=ps,e=je,n=g=>ne.create(g),o=n(ds*r*r),s=n((o+Gt)*yl),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=ms(s,a),f=n(u*r);jt(f,e)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-Gt)*bl-a),d=u*u,p=n((u+u)*a),S=n(l*ml),v=n(Gt-d),m=n(Gt+d);return new oe(n(p*m),n(v*S),n(S*m),n(p*v))}var se=class r extends Sn{static BASE=new r(oe.BASE);static ZERO=new r(oe.ZERO);static Fp=ne;static Fn=$a;constructor(t){super(t)}static fromAffine(t){return new r(oe.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){xt(t,32);let{a:e,d:n}=ps,o=je,s=R=>ne.create(R),i=hs(t);if(!wa(ne.toBytes(i),t)||jt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Gt+e*a),u=s(Gt-e*a),f=s(c*c),l=s(u*u),d=s(e*n*f-l),{isValid:p,value:S}=Va(s(d*l)),v=s(S*u),m=s(S*v*d),g=s((i+i)*v);jt(g,o)&&(g=s(-g));let w=s(c*m),A=s(g*w);if(!p||jt(A,o)||w===ul)throw new Error("invalid ristretto255 encoding 2");return new r(new oe(g,w,Gt,A))}static fromHex(t){return r.fromBytes(wr(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=je,i=m=>ne.create(m),a=i(i(n+e)*i(n-e)),c=i(t*e),u=i(c*c),{value:f}=Va(i(a*u)),l=i(f*a),d=i(f*c),p=i(l*d*o),S;if(jt(o*p,s)){let m=i(e*ds),g=i(t*ds);t=m,e=g,S=i(l*gl)}else S=d;jt(t*p,s)&&(e=i(-e));let v=i((n-e)*S);return jt(v,s)&&(v=i(-v)),ne.toBytes(v)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ne.create(u),a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Object.freeze(se.BASE);Object.freeze(se.ZERO);Object.freeze(se.prototype);Object.freeze(se);var wl=Object.freeze({Point:se,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=fs(r,e,64,hn);return wl.deriveToCurve(n)},hashToScalar(r,t={DST:za}){let e=fs(r,t.DST,64,hn);return $a.create(Ut(e))},deriveToCurve(r){xt(r,64);let t=hs(r.subarray(0,32)),e=Ha(t),n=hs(r.subarray(32,64)),o=Ha(n);return new se(e.add(o))}});var Rr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},vn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _n={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new vn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var An=32;var gs,El=(async()=>{try{return await _n.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sl(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await _n.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await _n.get().subtle.verify({name:"Ed25519"},n,Tt(t),Tt(e instanceof Uint8Array?e:e.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function vl(r,t,e){return ja.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Ga(r,t,e){return gs==null&&(gs=await El),gs?Sl(r,t,e):vl(r,t,e)}function In(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Bn=class{type="Ed25519";raw;constructor(t){this.raw=ys(t,An)}toMultihash(){return Bt.digest(Ne(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Ga(this.raw,e,t);return In(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ya(r){return r=ys(r,An),new Bn(r)}function ys(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new ht(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Al=Math.pow(2,7),Il=Math.pow(2,14),Bl=Math.pow(2,21),bs=Math.pow(2,28),xs=Math.pow(2,35),ws=Math.pow(2,42),Es=Math.pow(2,49),q=128,lt=127;function yt(r){if(r<Al)return 1;if(r<Il)return 2;if(r<Bl)return 3;if(r<bs)return 4;if(r<xs)return 5;if(r<ws)return 6;if(r<Es)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ge(r,t,e=0){switch(yt(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Tl(r,t,e=0){switch(yt(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Ss(r,t){let e=r[t],n=0;if(n+=e&lt,e<q||(e=r[t+1],n+=(e&lt)<<7,e<q)||(e=r[t+2],n+=(e&lt)<<14,e<q)||(e=r[t+3],n+=(e&lt)<<21,e<q)||(e=r[t+4],n+=(e&lt)*bs,e<q)||(e=r[t+5],n+=(e&lt)*xs,e<q)||(e=r[t+6],n+=(e&lt)*ws,e<q)||(e=r[t+7],n+=(e&lt)*Es,e<q))return n;throw new RangeError("Could not decode varint")}function Dl(r,t){let e=r.get(t),n=0;if(n+=e&lt,e<q||(e=r.get(t+1),n+=(e&lt)<<7,e<q)||(e=r.get(t+2),n+=(e&lt)<<14,e<q)||(e=r.get(t+3),n+=(e&lt)<<21,e<q)||(e=r.get(t+4),n+=(e&lt)*bs,e<q)||(e=r.get(t+5),n+=(e&lt)*xs,e<q)||(e=r.get(t+6),n+=(e&lt)*ws,e<q)||(e=r.get(t+7),n+=(e&lt)*Es,e<q))return n;throw new RangeError("Could not decode varint")}function Xa(r,t,e=0){return t==null&&(t=ft(yt(r))),t instanceof Uint8Array?Ge(r,t,e):Tl(r,t,e)}function Cr(r,t=0){return r instanceof Uint8Array?Ss(r,t):Dl(r,t)}var vs=new Float32Array([-0]),ie=new Uint8Array(vs.buffer);function Qa(r,t,e){vs[0]=r,t[e]=ie[0],t[e+1]=ie[1],t[e+2]=ie[2],t[e+3]=ie[3]}function Ja(r,t){return ie[0]=r[t],ie[1]=r[t+1],ie[2]=r[t+2],ie[3]=r[t+3],vs[0]}var _s=new Float64Array([-0]),dt=new Uint8Array(_s.buffer);function tc(r,t,e){_s[0]=r,t[e]=dt[0],t[e+1]=dt[1],t[e+2]=dt[2],t[e+3]=dt[3],t[e+4]=dt[4],t[e+5]=dt[5],t[e+6]=dt[6],t[e+7]=dt[7]}function ec(r,t){return dt[0]=r[t],dt[1]=r[t+1],dt[2]=r[t+2],dt[3]=r[t+3],dt[4]=r[t+4],dt[5]=r[t+5],dt[6]=r[t+6],dt[7]=r[t+7],_s[0]}var Ll=BigInt(Number.MAX_SAFE_INTEGER),Rl=BigInt(Number.MIN_SAFE_INTEGER),wt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return xe;if(t<Ll&&t>Rl)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>rc&&(o=0n,++n>rc&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return xe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):xe}},xe=new wt(0,0);xe.toBigInt=function(){return 0n};xe.zzEncode=xe.zzDecode=function(){return this};xe.length=function(){return 1};var rc=4294967296n;function nc(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function oc(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function As(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Ot(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Tn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Is=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Tt(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ot(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ot(this,4);return Tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ot(this,4);return Tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ot(this,4);let t=Ja(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ot(this,4);let t=ec(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Ot(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return oc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ot(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ot(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new wt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Ot(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Ot(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ot(this,8);let t=Tn(this.buf,this.pos+=4),e=Tn(this.buf,this.pos+=4);return new wt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ss(this.buf,this.pos);return this.pos+=yt(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 Or(r){return new Is(r instanceof Uint8Array?r:r.subarray())}function vt(r,t,e){let n=Or(r);return t.decode(n,void 0,e)}function Bs(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var we=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ts(){}var Ls=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cl=Bs();function Ol(r){return globalThis.Buffer!=null?ft(r):Cl(r)}var Pr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(Ts,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new we(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Rs((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(Dn,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=wt.fromBigInt(t);return this._push(Dn,e.length(),e)}uint64Number(t){return this._push(Ge,yt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=wt.fromBigInt(t).zzEncode();return this._push(Dn,e.length(),e)}sint64Number(t){let e=wt.fromNumber(t).zzEncode();return this._push(Dn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ds,1,t?1:0)}fixed32(t){return this._push(kr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=wt.fromBigInt(t);return this._push(kr,4,e.lo)._push(kr,4,e.hi)}fixed64Number(t){let e=wt.fromNumber(t);return this._push(kr,4,e.lo)._push(kr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Qa,4,t)}double(t){return this._push(tc,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ds,1,0):this.uint32(e)._push(Pl,e,t)}string(t){let e=nc(t);return e!==0?this.uint32(e)._push(As,e,t):this._push(Ds,1,0)}fork(){return this.states=new Ls(this),this.head=this.tail=new we(Ts,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new we(Ts,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Ol(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ds(r,t,e){t[e]=r&255}function kl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Rs=class extends we{next;constructor(t,e){super(kl,t,e),this.next=void 0}};function Dn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function kr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Pl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Pr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Fl,t,r),this},Pr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Nl,t,r),this});function Fl(r,t,e){t.set(r,e)}function Nl(r,t,e){r.length<40?As(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(V(r),e)}function Cs(){return new Pr}function _t(r,t){let e=Cs();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*At(r,t,e){let n=Or(r);yield*t.stream(n,void 0,"$",e)}var Ln={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Rn(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function Ee(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return Rn("enum",Ln.VARINT,e,n,o)}function It(r,t,e){return Rn("message",Ln.LENGTH_DELIMITED,r,t,e)}var Fr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var pt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(pt||(pt={}));var Os;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Os||(Os={}));(function(r){r.codec=()=>Ee(Os)})(pt||(pt={}));var Nr;(function(r){let t;r.codec=()=>(t==null&&(t=It((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 e(s){return _t(s,r.codec())}r.encode=e;function n(s,i){return vt(s,r.codec(),i)}r.decode=n;function o(s,i){return At(s,r.codec(),i)}r.stream=o})(Nr||(Nr={}));var ks;(function(r){let t;r.codec=()=>(t==null&&(t=It((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 e(s){return _t(s,r.codec())}r.encode=e;function n(s,i){return vt(s,r.codec(),i)}r.decode=n;function o(s,i){return At(s,r.codec(),i)}r.stream=o})(ks||(ks={}));var Cn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(cn(t),xt(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Ht(o)}update(t){return Ue(this),this.iHash.update(t),this}digestInto(t){Ue(this),un(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ic=(()=>{let r=((t,e,n)=>new Cn(t,e).update(n).digest());return r.create=(t,e)=>new Cn(t,e),r})();var ac=(r,t)=>(r+(r>=0?t:-t)/cc)/t;function Ml(r,t,e){ze("scalar",r,Mt,e);let[[n,o],[s,i]]=t,a=ac(i*r,e),c=ac(-o*r,e),u=r-a*n-c*s,f=-a*o-c*i,l=u<Mt,d=f<Mt;l&&(u=-u),d&&(f=-f);let p=Br(Math.ceil(qe(e)/2))+ae;if(u<Mt||u>=p||f<Mt||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Fs(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Ps(r,t){Ct(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Lt(e.lowS,"lowS"),Lt(e.prehash,"prehash"),e.format!==void 0&&Fs(e.format),e}var Ns=class extends Error{constructor(t=""){super(t)}},kt={Err:Ns,_tlv:{encode:(r,t)=>{let{Err:e}=kt;if(Rt(r,"tag"),r<0||r>255)throw new e("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Ar(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Ar(o.length/2|128):"";return Ar(r)+s+o+t},decode(r,t){let{Err:e}=kt;t=K(t,void 0,"DER data");let n=0;if(r<0||r>255)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=kt;if(gn(r),r<Mt)throw new t("integer: negative integers are not allowed");let e=Ar(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=kt;if(r.length<1)throw new t("invalid signature integer: empty");if(r[0]&128)throw new t("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return me(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=kt,o=K(r,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:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=kt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};Object.freeze(kt._tlv);Object.freeze(kt._int);Object.freeze(kt);var Mt=BigInt(0),ae=BigInt(1),cc=BigInt(2),On=BigInt(3),Kl=BigInt(4);function uc(r,t={}){let e=wn("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;Ct(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=t;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 f=lc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(k,h,y){if(u&&h.is0())return Uint8Array.of(0);let{x:E,y:x}=h.toAffine(),b=n.toBytes(E);if(Lt(y,"isCompressed"),y){l();let _=!n.isOdd(x);return Q(fc(_),b)}else return Q(Uint8Array.of(4),b,n.toBytes(x))}function p(k){K(k,void 0,"Point");let{publicKey:h,publicKeyUncompressed:y}=f,E=k.length,x=k[0],b=k.subarray(1);if(u&&E===1&&x===0)return{x:n.ZERO,y:n.ZERO};if(E===h&&(x===2||x===3)){let _=n.fromBytes(b);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let T=m(_),B;try{B=n.sqrt(T)}catch(M){let z=M instanceof Error?": "+M.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}l();let L=n.isOdd(B);return(x&1)===1!==L&&(B=n.neg(B)),{x:_,y:B}}else if(E===y&&x===4){let _=n.BYTES,T=n.fromBytes(b.subarray(0,_)),B=n.fromBytes(b.subarray(_,_*2));if(!g(T,B))throw new Error("bad point: is not on curve");return{x:T,y:B}}else throw new Error(`bad point: got length ${E}, expected compressed=${h} or uncompressed=${y}`)}let S=t.toBytes===void 0?d:t.toBytes,v=t.fromBytes===void 0?p:t.fromBytes;function m(k){let h=n.sqr(k),y=n.mul(h,k);return n.add(n.add(y,n.mul(k,s.a)),s.b)}function g(k,h){let y=n.sqr(h),E=m(k);return n.eql(y,E)}if(!g(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let w=n.mul(n.pow(s.a,On),Kl),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(w,A)))throw new Error("bad curve params: a or b");function R(k,h,y=!1){if(!n.isValid(h)||y&&n.is0(h))throw new Error(`bad point coordinate ${k}`);return h}function D(k){if(!(k instanceof I))throw new Error("Weierstrass Point expected")}function P(k){if(!c||!c.basises)throw new Error("no endo");return Ml(k,c.basises,o.ORDER)}function C(k,h,y,E,x){return y=new I(n.mul(y.X,k),y.Y,y.Z),h=Dr(E,h),y=Dr(x,y),h.add(y)}class I{static BASE=new I(s.Gx,s.Gy,n.ONE);static ZERO=new I(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,y,E){this.X=R("x",h),this.Y=R("y",y,!0),this.Z=R("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:y,y:E}=h||{};if(!h||!n.isValid(y)||!n.isValid(E))throw new Error("invalid affine point");if(h instanceof I)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(E)?I.ZERO:new I(y,E,n.ONE)}static fromBytes(h){let y=I.fromAffine(v(K(h,void 0,"point")));return y.assertValidity(),y}static fromHex(h){return I.fromBytes(Ke(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,y=!0){return N.createCache(this,h),y||this.multiply(On),this}assertValidity(){let h=this;if(h.is0()){if(t.allowInfinityPoint&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}let{x:y,y:E}=h.toAffine();if(!n.isValid(y)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!g(y,E))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){D(h);let{X:y,Y:E,Z:x}=this,{X:b,Y:_,Z:T}=h,B=n.eql(n.mul(y,T),n.mul(b,x)),L=n.eql(n.mul(E,T),n.mul(_,x));return B&&L}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:y}=s,E=n.mul(y,On),{X:x,Y:b,Z:_}=this,T=n.ZERO,B=n.ZERO,L=n.ZERO,O=n.mul(x,x),M=n.mul(b,b),z=n.mul(_,_),U=n.mul(x,b);return U=n.add(U,U),L=n.mul(x,_),L=n.add(L,L),T=n.mul(h,L),B=n.mul(E,z),B=n.add(T,B),T=n.sub(M,B),B=n.add(M,B),B=n.mul(T,B),T=n.mul(U,T),L=n.mul(E,L),z=n.mul(h,z),U=n.sub(O,z),U=n.mul(h,U),U=n.add(U,L),L=n.add(O,O),O=n.add(L,O),O=n.add(O,z),O=n.mul(O,U),B=n.add(B,O),z=n.mul(b,_),z=n.add(z,z),O=n.mul(z,U),T=n.sub(T,O),L=n.mul(z,M),L=n.add(L,L),L=n.add(L,L),new I(T,B,L)}add(h){D(h);let{X:y,Y:E,Z:x}=this,{X:b,Y:_,Z:T}=h,B=n.ZERO,L=n.ZERO,O=n.ZERO,M=s.a,z=n.mul(s.b,On),U=n.mul(y,b),W=n.mul(E,_),J=n.mul(x,T),tt=n.add(y,E),G=n.add(b,_);tt=n.mul(tt,G),G=n.add(U,W),tt=n.sub(tt,G),G=n.add(y,x);let mt=n.add(b,T);return G=n.mul(G,mt),mt=n.add(U,J),G=n.sub(G,mt),mt=n.add(E,x),B=n.add(_,T),mt=n.mul(mt,B),B=n.add(W,J),mt=n.sub(mt,B),O=n.mul(M,G),B=n.mul(z,J),O=n.add(B,O),B=n.sub(W,O),O=n.add(W,O),L=n.mul(B,O),W=n.add(U,U),W=n.add(W,U),J=n.mul(M,J),G=n.mul(z,G),W=n.add(W,J),J=n.sub(U,J),J=n.mul(M,J),G=n.add(G,J),U=n.mul(W,G),L=n.add(L,U),U=n.mul(mt,G),B=n.mul(tt,B),B=n.sub(B,U),U=n.mul(tt,W),O=n.mul(mt,O),O=n.add(O,U),new I(B,L,O)}subtract(h){return D(h),this.add(h.negate())}is0(){return this.equals(I.ZERO)}multiply(h){let{endo:y}=t;if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let E,x,b=_=>N.cached(this,_,T=>be(I,T));if(y){let{k1neg:_,k1:T,k2neg:B,k2:L}=P(h),{p:O,f:M}=b(T),{p:z,f:U}=b(L);x=M.add(U),E=C(y.beta,O,z,_,B)}else{let{p:_,f:T}=b(h);E=_,x=T}return be(I,[E,x])[0]}multiplyUnsafe(h){let{endo:y}=t,E=this,x=h;if(!o.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Mt||E.is0())return I.ZERO;if(x===ae)return E;if(N.hasCache(this))return this.multiply(x);if(y){let{k1neg:b,k1:_,k2neg:T,k2:B}=P(x),{p1:L,p2:O}=Ua(I,E,_,B);return C(y.beta,L,O,b,T)}else return N.unsafe(E,x)}toAffine(h){let y=this,E=h,{X:x,Y:b,Z:_}=y;if(n.eql(_,n.ONE))return{x,y:b};let T=y.is0();E==null&&(E=T?n.ONE:n.inv(_));let B=n.mul(x,E),L=n.mul(b,E),O=n.mul(_,E);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:B,y:L}}isTorsionFree(){let{isTorsionFree:h}=t;return i===ae?!0:h?h(I,this):N.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===ae?this:h?h(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ae?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Lt(h,"isCompressed"),this.assertValidity(),S(I,this,h)}toHex(h=!0){return Me(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let F=o.BITS,N=new $e(I,t.endo?Math.ceil(F/2):F);return F>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function fc(r){return Uint8Array.of(r?2:3)}function lc(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function zl(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?_r:t.randomBytes,o=Object.assign(lc(r.Fp,e),{seed:Math.max(os(e.ORDER),16)});function s(p){try{let S=e.fromBytes(p);return e.isValidNot0(S)}catch{return!1}}function i(p,S){let{publicKey:v,publicKeyUncompressed:m}=o;try{let g=p.length;return S===!0&&g!==v||S===!1&&g!==m?!1:!!r.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,ss(K(p,o.seed,"seed"),e.ORDER)}function c(p,S=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(S)}function u(p){let{secretKey:S,publicKey:v,publicKeyUncompressed:m}=o,g=e._lengths;if(!pe(p))return;let w=K(p,void 0,"key").length,A=w===v||w===m,R=w===S||!!g?.includes(w);if(!(A&&R))return A}function f(p,S,v=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(S)===!1)throw new Error("second arg must be public key");let m=e.fromBytes(p);return r.fromBytes(S).multiply(m).toBytes(v)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=En(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:r,utils:l,lengths:o})}function dc(r,t,e={}){let n=t;cn(n),Ct(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?_r:e.randomBytes,s=e.hmac===void 0?(x,b)=>ic(n,x,b):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:p,lengths:S}=zl(r,e),v={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},m=c*cc+ae<i.ORDER;function g(x){let b=c>>ae;return x>b}function w(x,b){if(!a.isValidNot0(b))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return b}function A(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(x,b){Fs(b);let _=S.signature,T=b==="compact"?_:b==="recovered"?_+1:void 0;return K(x,T)}class D{r;s;recovery;constructor(b,_,T){if(this.r=w("r",b),this.s=w("s",_),T!=null){if(A(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(b,_=v.format){R(b,_);let T;if(_==="der"){let{r:M,s:z}=kt.toSig(K(b));return new D(M,z)}_==="recovered"&&(T=b[0],_="compact",b=b.subarray(1));let B=S.signature/2,L=b.subarray(0,B),O=b.subarray(B,B*2);return new D(a.fromBytes(L),a.fromBytes(O),T)}static fromHex(b,_){return this.fromBytes(Ke(b),_)}assertRecovery(){let{recovery:b}=this;if(b==null)throw new Error("invalid recovery id: must be present");return b}addRecoveryBit(b){return new D(this.r,this.s,b)}recoverPublicKey(b){let{r:_,s:T}=this,B=this.assertRecovery(),L=B===2||B===3?_+c:_;if(!i.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(L),M=r.fromBytes(Q(fc((B&1)===0),O)),z=a.inv(L),U=C(K(b,void 0,"msgHash")),W=a.create(-U*z),J=a.create(T*z),tt=r.BASE.multiplyUnsafe(W).add(M.multiplyUnsafe(J));if(tt.is0())throw new Error("invalid recovery: point at infinify");return tt.assertValidity(),tt}hasHighS(){return g(this.s)}toBytes(b=v.format){if(Fs(b),b==="der")return Ke(kt.hexFromSig(this));let{r:_,s:T}=this,B=a.toBytes(_),L=a.toBytes(T);return b==="recovered"?(A(),Q(Uint8Array.of(this.assertRecovery()),B,L)):Q(B,L)}toHex(b){return Me(this.toBytes(b))}}Object.freeze(D.prototype),Object.freeze(D);let P=e.bits2int===void 0?function(b){if(b.length>8192)throw new Error("input is too large");let _=me(b),T=b.length*8-u;return T>0?_>>BigInt(T):_}:e.bits2int,C=e.bits2int_modN===void 0?function(b){return a.create(P(b))}:e.bits2int_modN,I=Br(u);function F(x){return ze("num < 2^"+u,x,Mt,I),a.toBytes(x)}function N(x,b){return K(x,void 0,"message"),b?K(n(x),void 0,"prehashed message"):x}function k(x,b,_){let{lowS:T,prehash:B,extraEntropy:L}=Ps(_,v);x=N(x,B);let O=C(x),M=a.fromBytes(b);if(!a.isValidNot0(M))throw new Error("invalid private key");let z=[F(M),F(O)];if(L!=null&&L!==!1){let tt=L===!0?o(S.secretKey):L;z.push(K(tt,void 0,"extraEntropy"))}let U=Q(...z),W=O;function J(tt){let G=P(tt);if(!a.isValidNot0(G))return;let mt=a.inv(G),De=r.BASE.multiply(G).toAffine(),ur=a.create(De.x);if(ur===Mt)return;let Wr=a.create(mt*a.create(W+ur*M));if(Wr===Mt)return;let Ei=(De.x===ur?0:2)|Number(De.y&ae),Si=Wr;return T&&g(Wr)&&(Si=a.neg(Wr),Ei^=1),new D(ur,Si,m?void 0:Ei)}return{seed:U,k2sig:J}}function h(x,b,_={}){let{seed:T,k2sig:B}=k(x,b,_);return Ea(n.outputLen,a.BYTES,s)(T,B).toBytes(_.format)}function y(x,b,_,T={}){let{lowS:B,prehash:L,format:O}=Ps(T,v);if(_=K(_,void 0,"publicKey"),b=N(b,L),!pe(x)){let M=x instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+M)}R(x,O);try{let M=D.fromBytes(x,O),z=r.fromBytes(_);if(B&&M.hasHighS())return!1;let{r:U,s:W}=M,J=C(b),tt=a.inv(W),G=a.create(J*tt),mt=a.create(U*tt),De=r.BASE.multiplyUnsafe(G).add(z.multiplyUnsafe(mt));return De.is0()?!1:a.create(De.x)===U}catch{return!1}}function E(x,b,_={}){let{prehash:T}=Ps(_,v);return b=N(b,T),D.fromBytes(x,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:p,lengths:S,Point:r,sign:h,verify:y,recoverPublicKey:E,Signature:D,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")},ql={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var hc=BigInt(2);function Vl(r){let t=Ms.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,f=u*u*r%t,l=H(f,e,t)*f%t,d=H(l,e,t)*f%t,p=H(d,hc,t)*u%t,S=H(p,o,t)*p%t,v=H(S,s,t)*S%t,m=H(v,a,t)*v%t,g=H(m,c,t)*m%t,w=H(g,a,t)*v%t,A=H(w,e,t)*f%t,R=H(A,i,t)*S%t,D=H(R,n,t)*u%t,P=H(D,hc,t);if(!Us.eql(Us.sqr(P),r))throw new Error("Cannot find square root");return P}var Us=Ve(Ms.p,{sqrt:Vl}),Hl=uc(Ms,{Fp:Us,endo:ql}),Ze=dc(Hl,ba);function pc(r,t,e,n){let o=gr.digest(e instanceof Uint8Array?e:e.subarray());if(In(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ze.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Rr(String(s))});try{return n?.signal?.throwIfAborted(),Ze.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new Rr(String(s))}}var kn=class{type="secp256k1";raw;_key;constructor(t){this._key=gc(t),this.raw=mc(this._key)}toMultihash(){return Bt.digest(Ne(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,e,n){return pc(this._key,e,t,n)}};function yc(r){return new kn(r)}function mc(r){return Ze.Point.fromBytes(r).toBytes()}function gc(r){try{return Ze.Point.fromBytes(r),r}catch(t){throw new Jr(String(t))}}function bc(r){let{Type:t,Data:e}=Nr.decode(r.digest),n=e??new Uint8Array;switch(t){case pt.Ed25519:return Ya(n);case pt.secp256k1:return yc(n);case pt.ECDSA:return ea(n);default:throw new fr}}function Ne(r){return Nr.encode({Type:pt[r.type],Data:r.raw})}var xc=Symbol.for("nodejs.util.inspect.custom"),$l=114,Ur=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[lo]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1($l,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ut(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ut(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[xc](){return`PeerId(${this.toString()})`}},Pn=class extends Ur{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Fn=class extends Ur{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Nn=class extends Ur{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},jl=2336,Un=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(V(this.url))}[xc](){return`PeerId(${this.url})`}[lo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(jl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=X(t)),t.toString()===this.toString())}};function wc(r){if(Zl(r))return new Pn({multihash:r});if(Gl(r))try{let t=bc(r);if(t.type==="Ed25519")return new Fn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Nn({multihash:r,publicKey:t})}catch{let e=X(r.digest);return new Un(new URL(e))}throw new tn("Supplied PeerID Multihash is invalid")}function Gl(r){return r.code===Bt.code}function Zl(r){return r.code===gr.code}function Ks(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Mn(r){let t=pr(Z.decode(`z${r}`));return wc(t)}var Kn=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Ks(this.set.entries(),t=>{let e=Mn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Mn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ks(this.set.values(),t=>Mn(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function zs(){return new Kn}var qs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ec={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Sc=new globalThis.TextEncoder;function Yl(r,t){let e=qs[t],n=Ec[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Xl(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=qs[t],o=Ec[t],s=r;for(;s.length>0;){let i=Sc.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function Vs(r,{size:t=32,utf8Buffer:e}={}){if(!qs[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return Xl(r,t,e);r=Sc.encode(r)}return Yl(r,t)}var Mr={hash:r=>Number(Vs(r,{size:32})),hashV:(r,t)=>Wl(Mr.hash(r,t))};function Wl(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),V(t,"base16")}var Hs=64,Pt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Hs)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=gt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ut(this.fp,t.fp):!1}};function Se(r,t){return Math.floor(Math.random()*(t-r))+r}var ve=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Pt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Pt))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof Pt))throw new TypeError("Invalid Fingerprint");let e=Se(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Pt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Ql=500,Kr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Mr,this.seed=t.seed??Se(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=V(t));let e=new Pt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ve(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ve(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[Se(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ve(this.bucketSize));for(let a=0;a<Ql;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ve(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=V(t));let e=new Pt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=V(t));let e=new Pt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Jl={1:.5,2:.84,4:.95,8:.98};function td(r=.001){return r>.002?2:r>1e-5?4:8}function vc(r,t=.001){let e=td(t),n=Jl[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Hs);return{filterSize:o,bucketSize:e,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??Mr,this.seed=t.seed??Se(0,Math.pow(2,10)),this.filterSeries=[new Kr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=V(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new Kr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=V(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=V(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function $s(r,t=.001,e){return new zn({...vc(r,t),...e??{}})}function zr(r){let t=r.getComponents(),e={},n=0;return t[n]?.name==="ip6zone"&&(e.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(e.type=t[n].name,e.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(e.type=t[n].name,e.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(e.protocol=t[n].name==="tcp"?"tcp":"udp",e.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(e.type==="ip4"?e.cidr=parseInt(`${t[n].value}`):e.type==="ip6"&&(e.cidr=`${t[n].value}`),n++),e.type==null||e.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e)}function Ye(r){let t=zr(r);if(t==null)throw new ht(`Multiaddr ${r} 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 e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let 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,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var _c=45,ed=15,Xe=new qn;function Vn(r){if(!(r.length>ed))return Xe.new(r).parseWith(()=>Xe.readIPv4Addr())}function Hn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>_c))return Xe.new(r).parseWith(()=>Xe.readIPv6Addr())}function We(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>_c)return;let e=Xe.new(r).parseWith(()=>Xe.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function Ac(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function Ic(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function js(r){switch(r.length){case _e:return r.join(".");case Ae:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Bc(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function Tc(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var _e=4,Ae=16,lb=parseInt("0xFFFF",16),rd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function qr(r,t){t.length===Ae&&r.length===_e&&Ac(t,0,11)&&(t=t.slice(12)),t.length===_e&&r.length===Ae&&Ic(r,rd,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function Dc(r,t){if(typeof t=="string"&&(t=We(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Gs(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=_e,o=Vn(t);if(o==null&&(n=Ae,o=Hn(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=Zs(s,8*n);return{network:qr(o,i),mask:i}}function Zs(r,t){if(t!==8*_e&&t!==8*Ae)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var Vr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Gs(t));else{let n=We(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=We(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Zs(o,8*n.length);this.network=qr(n,this.mask)}}contains(t){return Dc({network:this.network,mask:this.mask},t)}toString(){let t=Bc(this.mask),e=t!==-1?String(t):Tc(this.mask);return js(this.network)+"/"+e}};function Lc(r,t){return new Vr(r).contains(t)}function Rc(r){try{let t=Ye(r);return t.type==="ip6"?Lc("2000::/3",t.host):!1}catch{return!1}}function Qe(r){return!!Vn(r)}function $n(r){return!!Hn(r)}var Pc=mu(kc(),1),ud=["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"],fd=ud.map(r=>new Pc.Netmask(r));function ei(r){for(let t of fd)if(t.contains(r))return!0;return!1}function ld(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function dd(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return ei(o)}function hd(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function pd(r){let t=r.split(":"),e=t[t.length-1];return ei(e)}function md(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Gn(r){if(Qe(r))return ei(r);if(ld(r))return dd(r);if(hd(r))return pd(r);if($n(r))return md(r)}function Fc(r){try{let t=Ye(r);switch(t.type){case"ip4":case"ip6":return Gn(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var it=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Zt=class extends Error{static name="ValidationError";name="ValidationError"},Zn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Yn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function ni(r){return t=>X(t,r)}function oi(r){return t=>V(t,r)}function rr(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Be(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Nc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Be(n);return Ft([e,o],e.length+o.length)}function Uc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Wt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Be(n);return Ft([e,o],e.length+o.length)}function si(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=X(t,"base32"),o=rr(e);return`${n}:${o}`}var ii=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new it("Invalid byte value in IP address");t[n]=o}),t},Mc=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Qe(e[n]),i;s&&(i=ii(e[n]),e[n]=X(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,X(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new it("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Kc=function(r){if(r.byteLength!==4)throw new it("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},zc=function(r){if(r.byteLength!==16)throw new it("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new it(`Invalid IPv6 address "${e}"`)}};function qc(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new it(`Invalid IPv6 address "${r}"`)}}var ri=Object.values(yr).map(r=>r.decoder),gd=(function(){let r=ri[0].or(ri[1]);return ri.slice(2).forEach(t=>r=r.or(t)),r})();function Vc(r){return gd.decode(r)}function Hc(r){return t=>r.encoder.encode(t)}function yd(r){if(parseInt(r).toString()!==r)throw new Zt("Value must be an integer")}function bd(r){if(r<0)throw new Zt("Value must be a positive integer, or zero")}function xd(r){return t=>{if(t>r)throw new Zt(`Value must be smaller than or equal to ${r}`)}}function wd(...r){return t=>{for(let e of r)e(t)}}var Hr=wd(yd,bd,xd(65535));var nt=-1,ai=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new Yn(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Yt=new ai,sh=[{code:4,name:"ip4",size:32,valueToBytes:ii,bytesToValue:Kc,validate:r=>{if(!Qe(r))throw new Zt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Be,bytesToValue:rr,validate:Hr},{code:273,name:"udp",size:16,valueToBytes:Be,bytesToValue:rr,validate:Hr},{code:33,name:"dccp",size:16,valueToBytes:Be,bytesToValue:rr,validate:Hr},{code:41,name:"ip6",size:128,valueToBytes:Mc,bytesToValue:zc,stringToValue:qc,validate:r=>{if(!$n(r))throw new Zt(`Invalid IPv6 address "${r}"`)}},{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:Be,bytesToValue:rr,validate:Hr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:nt,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:nt,bytesToValue:ni("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?oi("base58btc")(r):ct.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:si,valueToBytes:Nc},{code:445,name:"onion3",size:296,bytesToValue:si,valueToBytes:Uc},{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:Hc(To),valueToBytes:Vc},{code:480,name:"http"},{code:481,name:"http-path",size:nt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:nt}];sh.forEach(r=>{Yt.addProtocol(r)});function $c(r){let t=[],e=0;for(;e<r.length;){let n=Cr(r,e),o=Yt.getProtocol(n),s=yt(n),i=ih(o,r,e+s),a=0;i>0&&o.size===nt&&(a=yt(i));let c=s+a+i,u={code:n,name:o.name,bytes:Tt(r.subarray(e,e+c))};if(i>0){let f=e+s+a,l=r.subarray(f,f+i);u.value=o.bytesToValue?.(l)??X(l)}t.push(u),e+=c}return t}function jc(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Yt.getProtocol(n.code),s=yt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===nt&&(c=yt(a)));let u=new Uint8Array(s+c+a),f=0;Ge(n.code,u,f),f+=s,i!=null&&(o.size===nt&&(Ge(a,u,f),f+=c),u.set(i,f)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return Ft(e,t)}function Gc(r){if(r.charAt(0)!=="/")throw new it('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=Yt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new it(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new it(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new it("Incomplete multiaddr");return t}function Zc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Yt.getProtocol(t.code);if(e==null)throw new it(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function ih(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Cr(t,e)}var ah=Symbol.for("nodejs.util.inspect.custom"),fi=Symbol.for("@multiformats/multiaddr");function ch(r){if(r==null&&(r="/"),Yc(r))return r.getComponents();if(r instanceof Uint8Array)return $c(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Gc(r);if(Array.isArray(r))return r;throw new it("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Xn=class r{[fi]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=ch(t),e.validate!==!1&&uh(this)}get bytes(){return this.#r==null&&(this.#r=jc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Zc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Zn(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return ut(this.bytes,t.bytes)}[ah](){return`Multiaddr(${this.toString()})`}};function uh(r){r.getComponents().forEach(t=>{let e=Yt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function Yc(r){return!!r?.[fi]}function Xc(r){return new Xn(r)}function nr(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Wn=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}},or=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Wn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Wn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var li=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Qn(r={}){return fh(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function fh(r,t){t=t??{};let e=t.onEnd,n=new or,o,s,i,a=nr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,g)=>{s=w=>{s=null,n.push(w);try{m(r(n))}catch(A){g(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=nr()})}},u=m=>s!=null?s(m):(n.push(m),o),f=m=>(n=new or,s!=null?s({error:m}):(n.push({error:m}),o)),l=m=>{if(i)return o;if(t?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:m})},d=m=>i?o:(i=!0,m!=null?f(m):u({done:!0})),p=()=>(n=new or,d(),{done:!0}),S=m=>(d(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:S,push:l,end:d,get readableLength(){return n.size},onEmpty:async m=>{let g=m?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let w,A;g!=null&&(w=new Promise((R,D)=>{A=()=>{D(new li)},g.addEventListener("abort",A)}));try{await Promise.race([a.promise,w])}finally{A!=null&&g!=null&&g?.removeEventListener("abort",A)}}},e==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(m){return v.throw(m),e!=null&&(e(m),e=void 0),{done:!0}},return(){return v.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(m){return v.end(m),e!=null&&(e(m),e=void 0),o},get readableLength(){return v.readableLength},onEmpty:m=>v.onEmpty(m)},o}var di=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Wc=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function hi(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,f=new Promise((l,d)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){d(Wc(i));return}if(i&&(c=()=>{d(Wc(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,d),e===Number.POSITIVE_INFINITY)return;let p=new di;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(S){d(S)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?d(o):(p.message=o??`Promise timed out after ${e} milliseconds`,d(p))},e)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var lh=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function dh(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=lh(r),l=async(...p)=>{let S=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(S))return}catch(v){n(),i(v);return}c.push(S),e.count===c.length&&(n(),s(c))},d=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)f(p,l);for(let p of e.rejectionEvents)a.includes(p)||f(p,d)};for(let p of a)u(p,l);for(let p of e.rejectionEvents)a.includes(p)||u(p,d);e.signal&&e.signal.addEventListener("abort",()=>{d(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=hi(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function sr(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=dh(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function $r(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Jn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Te=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function hh(r){return r.reason}async function jr(r,t,e){if(t==null)return r;let n=e?.translateError??hh;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([r,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=nr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new qt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function ph(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var eo=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,e){this.id=ph(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new qt),this.cleanup())}async join(t){let e=new to(t);return this.recipients.push(e),t?.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await jr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:e=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(e)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var ro=class extends Le{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=$r(this.emitEmpty.bind(this),1),this.emitIdle=$r(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Jn;let n=new eo(t,e);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(e).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new qt)}),this.clear()}async onEmpty(t){this.size!==0&&await sr(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await sr(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await sr(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=Qn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new qt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function Gr(r){let t=new globalThis.AbortController;function e(){let s=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}var mh=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 gh(r){return typeof r?.closeRead=="function"}function yh(r){return typeof r?.close=="function"}function pi(r){return gh(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:yh(r)?r.status!=="open":!1}function bh(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function xh(r,t){let e=t?.maxBufferSize??mh,n=new et,o,s=!1;if(!bh(r))throw new ht("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>e){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(s===!0)throw new no("Stream was unwrapped");if(pi(r)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Te(`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 jr(o.promise,f?.signal),pi(r)){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(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Te(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(f)}let p=n.sublist(0,d);return n.consume(d),p},async write(f,l){if(s===!0)throw new no("Stream was unwrapped");r.send(f)||await sr(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return u}function wh(r,t={}){let e=xh(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=yt(t.maxDataLength));let n=t?.lengthDecoder??Cr,o=t?.lengthEncoder??Xa;return{async read(i){let a=-1,c=new et;for(;;){let f=await e.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 e.read({...i,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new Te(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Te(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new et(o(i.byteLength),i),a)},async writeV(i,a){let c=new et(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function ir(r,t){let e=wh(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var oo=class extends ro{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Qc(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal},f;e?.timeout!=null&&(f=Gr([o.signal,AbortSignal.timeout(e.timeout)]),u.signal=f),s=!0,Promise.resolve().then(async()=>{await r(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=$r(i,e?.debounce??100),c=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{e??={},e.timeout=u},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var bi=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Jc(r){let{name:t,metrics:e}=r,n;return e!=null?n=new bi({name:t,metrics:e}):n=new Map,n}var xi="libp2p",wi="autonat";var tu="dial-request",eu="dial-back",ru=200n*1024n,nu=4096;var ar;(function(r){let t;r.codec=()=>(t==null&&(t=It((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),Zr.codec().encode(s.dialRequest,i)),s.dialResponse!=null&&(i.uint32(18),zt.codec().encode(s.dialResponse,i)),s.dialDataRequest!=null&&(i.uint32(26),Yr.codec().encode(s.dialDataRequest,i)),s.dialDataResponse!=null&&(i.uint32(34),Xr.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=Zr.codec().decode(s,s.uint32(),{limits:a.limits?.dialRequest});break}case 2:{c.dialResponse=zt.codec().decode(s,s.uint32(),{limits:a.limits?.dialResponse});break}case 3:{c.dialDataRequest=Yr.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataRequest});break}case 4:{c.dialDataResponse=Xr.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*Zr.codec().stream(s,s.uint32(),`${a}.dialRequest`,{limits:c.limits?.dialRequest});break}case 2:{yield*zt.codec().stream(s,s.uint32(),`${a}.dialResponse`,{limits:c.limits?.dialResponse});break}case 3:{yield*Yr.codec().stream(s,s.uint32(),`${a}.dialDataRequest`,{limits:c.limits?.dialDataRequest});break}case 4:{yield*Xr.codec().stream(s,s.uint32(),`${a}.dialDataResponse`,{limits:c.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}})),t);function e(s){return _t(s,r.codec())}r.encode=e;function n(s,i){return vt(s,r.codec(),i)}r.decode=n;function o(s,i){return At(s,r.codec(),i)}r.stream=o})(ar||(ar={}));var Zr;(function(r){let t;r.codec=()=>(t==null&&(t=It((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 Fr('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 Fr('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 e(s){return _t(s,r.codec())}r.encode=e;function n(s,i){return vt(s,r.codec(),i)}r.decode=n;function o(s,i){return At(s,r.codec(),i)}r.stream=o})(Zr||(Zr={}));var Yr;(function(r){let t;r.codec=()=>(t==null&&(t=It((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 e(s){return _t(s,r.codec())}r.encode=e;function n(s,i){return vt(s,r.codec(),i)}r.decode=n;function o(s,i){return At(s,r.codec(),i)}r.stream=o})(Yr||(Yr={}));var at;(function(r){r.UNUSED="UNUSED",r.E_DIAL_ERROR="E_DIAL_ERROR",r.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",r.OK="OK"})(at||(at={}));var so;(function(r){r[r.UNUSED=0]="UNUSED",r[r.E_DIAL_ERROR=100]="E_DIAL_ERROR",r[r.E_DIAL_BACK_ERROR=101]="E_DIAL_BACK_ERROR",r[r.OK=200]="OK"})(so||(so={}));(function(r){r.codec=()=>Ee(so)})(at||(at={}));var zt;(function(r){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=r.ResponseStatus||(r.ResponseStatus={}));let e;(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"})(e||(e={})),(function(a){a.codec=()=>Ee(e)})(t=r.ResponseStatus||(r.ResponseStatus={}));let n;r.codec=()=>(n==null&&(n=It((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&e[a.status]!==0&&(c.uint32(8),r.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),at.codec().encode(a.dialStatus,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:at.UNUSED},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{f.status=r.ResponseStatus.codec().decode(a);break}case 2:{f.addrIdx=a.uint32();break}case 3:{f.dialStatus=at.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:r.ResponseStatus.codec().decode(a)};break}case 2:{yield{field:`${u}.addrIdx`,value:a.uint32()};break}case 3:{yield{field:`${u}.dialStatus`,value:at.codec().decode(a)};break}default:{a.skipType(d&7);break}}}})),n);function o(a){return _t(a,r.codec())}r.encode=o;function s(a,c){return vt(a,r.codec(),c)}r.decode=s;function i(a,c){return At(a,r.codec(),c)}r.stream=i})(zt||(zt={}));var Xr;(function(r){let t;r.codec=()=>(t==null&&(t=It((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:gt(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 e(s){return _t(s,r.codec())}r.encode=e;function n(s,i){return vt(s,r.codec(),i)}r.decode=n;function o(s,i){return At(s,r.codec(),i)}r.stream=o})(Xr||(Xr={}));var cr;(function(r){let t;r.codec=()=>(t==null&&(t=It((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 e(s){return _t(s,r.codec())}r.encode=e;function n(s,i){return vt(s,r.codec(),i)}r.decode=n;function o(s,i){return At(s,r.codec(),i)}r.stream=o})(cr||(cr={}));var ue;(function(r){let t;(function(a){a.OK="OK"})(t=r.DialBackStatus||(r.DialBackStatus={}));let e;(function(a){a[a.OK=0]="OK"})(e||(e={})),(function(a){a.codec=()=>Ee(e)})(t=r.DialBackStatus||(r.DialBackStatus={}));let n;r.codec=()=>(n==null&&(n=It((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.status!=null&&e[a.status]!==0&&(c.uint32(8),r.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=r.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:r.DialBackStatus.codec().decode(a)}:a.skipType(d&7)}})),n);function o(a){return _t(a,r.codec())}r.encode=o;function s(a,c){return vt(a,r.codec(),c)}r.decode=s;function i(a,c){return At(a,r.codec(),c)}r.stream=i})(ue||(ue={}));function io(r,t){return Math.round(Math.random()*(t-r)+r)}var Sh=4,vh=8,ao=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;safeDispatchEvent;constructor(t,e){this.components=t,this.safeDispatchEvent=e.safeDispatchEvent,this.log=t.logger.forComponent("libp2p:auto-nat-v2:client"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.connectionThreshold=e.connectionThreshold??80,this.maxMessageSize=e.maxMessageSize??8192,this.dialResults=Jc({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=Qc(this.findRandomPeers.bind(this),6e4),this.addressFilter=$s(1024),this.queue=new oo({concurrency:3,maxSize:50}),this.maxDialDataBytes=e.maxDialDataBytes??ru,this.dialDataChunkSize=e.dialDataChunkSize??nu,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[en]=["@libp2p/autonat"];get[rn](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.components.registrar.register(this.dialRequestProtocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),await this.components.registrar.handle(this.dialBackProtocol,(t,e)=>{this.handleDialBackStream(t,e).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 e=Gr([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleDialBackStream(t,e){let n=AbortSignal.timeout(this.timeout);let o=ir(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read(cr,{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:ue.DialBackStatus.OK},ue),await t.close({signal:n})}catch(s){this.log.error("error handling incoming dial back stream - %e",s),t.abort(s)}}getUnverifiedMultiaddrs(t,e){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=zr(s.multiaddr);return!(a==null||a.type==="ip6"&&(!e||!Rc(s.multiaddr))||Fc(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:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:a})=>zr(a)?.type==="ip6"),o=zr(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=Gr([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,e,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=ir(i).pb(ar);await a.write({dialRequest:{addrs:s.map(c=>c.bytes),nonce:n}},o);for(let c=0;c<s.length;c++){let u=await a.read(o);if(u.dialDataRequest!=null){if(u.dialDataRequest.numBytes>this.maxDialDataBytes){this.log("too many dial data byte requested by %p - %s/%s",t.remotePeer,u.dialDataRequest.numBytes,this.maxDialDataBytes);continue}this.log("sending %d bytes to %p as anti-amplification attack protection",u.dialDataRequest.numBytes,t.remotePeer);let p=new Uint8Array(this.dialDataChunkSize),S=BigInt(this.dialDataChunkSize);for(let v=0n;v<u.dialDataRequest.numBytes;v+=S)await a.write({dialDataResponse:{data:p}},o);u=await a.read(o)}if(u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}if(u.dialResponse.status!==zt.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(e)){this.log.trace("%a results already included network segment %s",l,e);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(e),u.dialResponse.dialStatus===at.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===at.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===at.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===Sh&&this.confirmAddress(d),d.failure===vh&&this.unconfirmAddress(d)}}finally{try{await i.close(o)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,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,e){this.safeDispatchEvent(`address:${e}`,{detail:{addr:t.multiaddr,type:t.type,success:t.success,failure:t.failure}})}getNetworkSegment(t){let e=Ye(t);switch(e.type){case"ip4":return e.host.split(".")[0].padStart(3,"0");case"ip6":return e.host.split(":")[0].padStart(4,"0");default:throw new 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,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:server"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.maxMessageSize=e.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,e){let n=AbortSignal.timeout(this.timeout);let o=ir(t,{maxDataLength:this.maxMessageSize}).pb(ar),s=cu(e.remoteAddr);if(s==null)throw new Et(`Could not find IP address in connection address "${e.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=Xc(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:zt.ResponseStatus.E_DIAL_REFUSED,dialStatus:at.UNUSED}},{signal:n});continue}let f=cu(c);if(f==null)throw new Et(`Could not find IP address in requested address "${c}"`);if(Gn(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:zt.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,e,n){let o=io(3e4,1e5);await t.write({dialDataRequest:{addrIdx:e,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,e,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),at.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=ir(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:e},cr,n),(await i.read(ue,n)).status!==ue.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),at.E_DIAL_BACK_ERROR}return at.OK}};function cu(r){return r.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var uo=class extends Le{client;server;constructor(t,e){super();let n=`/${e.protocolPrefix??xi}/${wi}/${"2"}/${tu}`,o=`/${e.protocolPrefix??xi}/${wi}/${"2"}/${eu}`;this.client=new ao(t,{...e,dialRequestProtocol:n,dialBackProtocol:o,safeDispatchEvent:this.safeDispatchEvent.bind(this)}),this.server=new co(t,{...e,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[en]=["@libp2p/autonat"];get[rn](){return["@libp2p/identify"]}async start(){await Ai(this.client,this.server)}async stop(){await Ii(this.client,this.server)}};function _h(r={}){return t=>new uo(t,r)}return gu(Ah);})();
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}function Kr(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??Rh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;return Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})]).finally(()=>{o!=null&&t.removeEventListener("abort",o)})}var 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:
@@ -7,6 +7,7 @@
7
7
  @noble/curves/abstract/curve.js:
8
8
  @noble/curves/abstract/edwards.js:
9
9
  @noble/curves/ed25519.js:
10
+ @noble/curves/abstract/der.js:
10
11
  @noble/curves/abstract/weierstrass.js:
11
12
  @noble/curves/secp256k1.js:
12
13
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)