@libp2p/autonat-v2 2.0.20-29797a5bb → 2.0.20-5b8813abc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +9 -9
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 Rf=Object.create;var gn=Object.defineProperty;var Of=Object.getOwnPropertyDescriptor;var kf=Object.getOwnPropertyNames;var Pf=Object.getPrototypeOf,Ff=Object.prototype.hasOwnProperty;var ko=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),V=(r,t)=>{for(var e in t)gn(r,e,{get:t[e],enumerable:!0})},ga=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kf(t))!Ff.call(r,o)&&o!==e&&gn(r,o,{get:()=>t[o],enumerable:!(n=Of(t,o))||n.enumerable});return r};var Nf=(r,t,e)=>(e=r!=null?Rf(Pf(r)):{},ga(t||!r||!r.__esModule?gn(e,"default",{value:r,enumerable:!0}):e,r)),Uf=r=>ga(gn({},"__esModule",{value:!0}),r);var qi=ko(fr=>{"use strict";Object.defineProperty(fr,"__esModule",{value:!0});fr.Netmask4Impl=void 0;fr.ip2long=ur;fr.long2ip=Nt;function Nt(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 Rp=48,Op=97,kp=65;function Pp(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)-Rp)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-Op)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.charCodeAt(o)-kp)>>>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 ur(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]=Pp(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 Ki=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=ur(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=(ur(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=Nt(this.netLong),this.mask=Nt(this.maskLong),this.hostmask=Nt(~this.maskLong),this.first=this.bitmask<=30?Nt(this.netLong+1):this.base,this.last=this.bitmask<=30?Nt(this.netLong+this.size-2):Nt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Nt(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):(ur(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(Nt(this.netLong+this.size*t),this.mask)}forEach(t){let e=ur(this.first),n=ur(this.last),o=0;for(;e<=n;)t(Nt(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};fr.Netmask4Impl=Ki});var Wu=ko(lr=>{"use strict";Object.defineProperty(lr,"__esModule",{value:!0});lr.Netmask6Impl=void 0;lr.ip6bigint=Hi;lr.bigint2ip6=De;var Fp=qi(),Vi=(1n<<128n)-1n;function Hi(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,Fp.ip2long)(n),s=r.substring(0,e+1)+"0:0";return Xu(s)&~0xffffffffn|BigInt(o)}return Xu(r)}function Xu(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 De(r){if(r<0n||r>Vi)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 $i=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=Vi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Hi(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=De(this.netBigint),this.mask=De(this.maskBigint),this.hostmask=De(~this.maskBigint&Vi),this.first=this.base,this.last=De(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):(Hi(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(De(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(De(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};lr.Netmask6Impl=$i});var Qu=ko(fe=>{"use strict";Object.defineProperty(fe,"__esModule",{value:!0});fe.long2ip=fe.ip2long=fe.Netmask=void 0;var po=qi();Object.defineProperty(fe,"ip2long",{enumerable:!0,get:function(){return po.ip2long}});Object.defineProperty(fe,"long2ip",{enumerable:!0,get:function(){return po.long2ip}});var Np=Wu(),ji=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 Np.Netmask6Impl(t,e):this._impl=new po.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 po.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()}};fe.Netmask=ji});var em={};V(em,{autoNATv2:()=>tm});var Mt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var dt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},bn=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var yn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var yt=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var wr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Po=Symbol.for("@libp2p/peer-id");function ba(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function ya(...r){let t=[];for(let e of r)ba(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 xa(...r){let t=[];for(let e of r)ba(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 Mf(r){return typeof r?.handleEvent=="function"}function zf(r){return(r!==!0&&r!==!1&&r?.once)??!1}var xn=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=zf(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))}Mf(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 wn=Symbol.for("@libp2p/service-capabilities"),En=Symbol.for("@libp2p/service-dependencies");var zo={};V(zo,{base58btc:()=>Y,base58flickr:()=>Gf});var Rm=new Uint8Array(0);function wa(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 zt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ea(r){return new TextEncoder().encode(r)}function va(r){return new TextDecoder().decode(r)}function Kf(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var y=0,h=0,b=0,E=m.length;b!==E&&m[b]===0;)b++,y++;for(var S=(E-b)*f+1>>>0,T=new Uint8Array(S);b!==E;){for(var B=m[b],O=0,L=S-1;(B!==0||O<h)&&L!==-1;L--,O++)B+=256*T[L]>>>0,T[L]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");h=O,b++}for(var I=S-h;I!==S&&T[I]===0;)I++;for(var P=c.repeat(y);I<S;++I)P+=r.charAt(T[I]);return P}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var y=0;if(m[y]!==" "){for(var h=0,b=0;m[y]===c;)h++,y++;for(var E=(m.length-y)*u+1>>>0,S=new Uint8Array(E);m[y];){var T=e[m.charCodeAt(y)];if(T===255)return;for(var B=0,O=E-1;(T!==0||B<b)&&O!==-1;O--,B++)T+=a*S[O]>>>0,S[O]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");b=B,y++}if(m[y]!==" "){for(var L=E-b;L!==E&&S[L]===0;)L++;for(var I=new Uint8Array(h+(E-L)),P=h;L!==E;)I[P++]=S[L++];return I}}}function p(m){var y=d(m);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:p}}var qf=Kf,Vf=qf,_a=Vf;var Fo=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")}},No=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 Aa(this,t)}},Uo=class{decoders;constructor(t){this.decoders=t}or(t){return Aa(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 Aa(r,t){return new Uo({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Mo=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 Fo(t,e,n),this.decoder=new No(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ke({name:r,prefix:t,encode:e,decode:n}){return new Mo(r,t,e,n)}function Xt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=_a(e,r);return ke({prefix:t,name:r,encode:n,decode:s=>zt(o(s))})}function Hf(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 $f(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 jf(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=jf(n);return ke({prefix:t,name:r,encode(s){return $f(s,n,e)},decode(s){return Hf(s,o,e,r)}})}var Y=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Gf=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ko={};V(Ko,{base32:()=>Wt,base32hex:()=>Wf,base32hexpad:()=>Jf,base32hexpadupper:()=>tl,base32hexupper:()=>Qf,base32pad:()=>Yf,base32padupper:()=>Xf,base32upper:()=>Zf,base32z:()=>el});var Wt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Zf=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yf=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xf=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wf=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qf=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Jf=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tl=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),el=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var qo={};V(qo,{base36:()=>Er,base36upper:()=>rl});var Er=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rl=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nl=Ta,Ia=128,ol=127,sl=~ol,il=Math.pow(2,31);function Ta(r,t,e){t=t||[],e=e||0;for(var n=e;r>=il;)t[e++]=r&255|Ia,r/=128;for(;r&sl;)t[e++]=r&255|Ia,r>>>=7;return t[e]=r|0,Ta.bytes=e-n+1,t}var al=Vo,cl=128,Ba=127;function Vo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Vo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ba)<<o:(i&Ba)*Math.pow(2,o),o+=7}while(i>=cl);return Vo.bytes=s-n,e}var ul=Math.pow(2,7),fl=Math.pow(2,14),ll=Math.pow(2,21),dl=Math.pow(2,28),hl=Math.pow(2,35),pl=Math.pow(2,42),ml=Math.pow(2,49),gl=Math.pow(2,56),bl=Math.pow(2,63),yl=function(r){return r<ul?1:r<fl?2:r<ll?3:r<dl?4:r<hl?5:r<pl?6:r<ml?7:r<gl?8:r<bl?9:10},xl={encode:nl,decode:al,encodingLength:yl},wl=xl,vr=wl;function Sr(r,t=0){return[vr.decode(r,t),vr.decode.bytes]}function Pe(r,t,e=0){return vr.encode(r,t,e),t}function Fe(r){return vr.encodingLength(r)}function Ue(r,t){let e=t.byteLength,n=Fe(r),o=n+Fe(e),s=new Uint8Array(o+e);return Pe(r,s,0),Pe(e,s,n),s.set(t,o),new Ne(r,e,t,s)}function _r(r){let t=zt(r),[e,n]=Sr(t),[o,s]=Sr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ne(e,o,i,t)}function Da(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&wa(r.bytes,e.bytes)}}var Ne=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ca(r,t){let{bytes:e,version:n}=r;return n===0?vl(e,Ho(r),t??Y.encoder):Sl(e,Ho(r),t??Wt.encoder)}var La=new WeakMap;function Ho(r){let t=La.get(r);if(t==null){let e=new Map;return La.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=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ar)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==_l)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=Ue(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&&Da(t.multihash,n.multihash)}toString(t){return Ca(this,t)}toJSON(){return{"/":Ca(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??Ra(n,o,s.bytes))}else if(e[Al]===!0){let{version:n,multihash:o,code:s}=e,i=_r(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!==Ar)throw new Error(`Version 0 CID must use dag-pb (code: ${Ar}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ra(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ar,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=zt(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 Ne(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]=Sr(t.subarray(e));return e+=d,l},o=n(),s=Ar;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]=El(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 Ho(s).set(n,t),s}};function El(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case Wt.prefix:{let e=t??Wt;return[Wt.prefix,e.decode(r)]}case Er.prefix:{let e=t??Er;return[Er.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 vl(r,t,e){let{prefix:n}=e;if(n!==Y.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 Sl(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 Ar=112,_l=18;function Ra(r,t,e){let n=Fe(r),o=n+Fe(t),s=new Uint8Array(o+e.byteLength);return Pe(r,s,0),Pe(t,s,n),s.set(e,o),s}var Al=Symbol.for("@ipld/js-cid/CID");var $o={};V($o,{identity:()=>_t});var Oa=0,Il="identity",ka=zt;function Bl(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 Ue(Oa,ka(r))}var _t={code:Oa,name:Il,encode:ka,digest:Bl};function At(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 Tl(r){return r.buffer instanceof ArrayBuffer}function Me(r){return Tl(r)?r:r.slice()}async function Pa(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,Me(t),Me(e.subarray()));return n?.signal?.throwIfAborted(),s}function Kt(r=0){return new Uint8Array(r)}function Ir(r=0){return new Uint8Array(r)}function jo(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=Ir(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function Fa(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Ua=Symbol.for("@achingbrain/uint8arraylist");function Na(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 Sn(r){return!!r?.[Ua]}var et=class r{bufs;length;[Ua]=!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(Sn(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(Sn(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=Na(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Na(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(Sn(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 jo(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:jo(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(!Sn(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=Ir(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=Kt(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=Kt(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=Kt(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=Ir(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=Kt(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=Kt(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=Kt(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=Kt(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=Kt(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(!Fa(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 Wo={};V(Wo,{base10:()=>Fl});var lg=new Uint8Array(0);function Ma(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 qt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return he(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return he(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function za(r){return new TextEncoder().encode(r)}function Ka(r){return new TextDecoder().decode(r)}function Dl(r){return r?.buffer instanceof ArrayBuffer}function he(r){return Dl(r)?r:r.slice()}function Cl(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var y=0,h=0,b=0,E=m.length;b!==E&&m[b]===0;)b++,y++;for(var S=(E-b)*f+1>>>0,T=new Uint8Array(S);b!==E;){for(var B=m[b],O=0,L=S-1;(B!==0||O<h)&&L!==-1;L--,O++)B+=256*T[L]>>>0,T[L]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");h=O,b++}for(var I=S-h;I!==S&&T[I]===0;)I++;for(var P=c.repeat(y);I<S;++I)P+=r.charAt(T[I]);return P}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var y=0;if(m[y]!==" "){for(var h=0,b=0;m[y]===c;)h++,y++;for(var E=(m.length-y)*u+1>>>0,S=new Uint8Array(E);m[y];){var T=e[m.charCodeAt(y)];if(T===255)return;for(var B=0,O=E-1;(T!==0||B<b)&&O!==-1;O--,B++)T+=a*S[O]>>>0,S[O]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");b=B,y++}if(m[y]!==" "){for(var L=E-b;L!==E&&S[L]===0;)L++;for(var I=new Uint8Array(h+(E-L)),P=h;L!==E;)I[P++]=S[L++];return I}}}function p(m){var y=d(m);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:p}}var Ll=Cl,Rl=Ll,Va=Rl;var Go=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")}},Zo=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 Ha(this,t)}},Yo=class{decoders;constructor(t){this.decoders=t}or(t){return Ha(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 Ha(r,t){return new Yo({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Xo=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 Go(t,e,n),this.decoder=new Zo(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ze({name:r,prefix:t,encode:e,decode:n}){return new Xo(r,t,e,n)}function Qt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Va(e,r);return ze({prefix:t,name:r,encode:n,decode:s=>qt(o(s))})}function Ol(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 kl(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 Pl(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Pl(n);return ze({prefix:t,name:r,encode(s){return kl(s,n,e)},decode(s){return Ol(s,o,e,r)}})}var Fl=Qt({prefix:"9",name:"base10",alphabet:"0123456789"});var Qo={};V(Qo,{base16:()=>Nl,base16upper:()=>Ul});var Nl=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ul=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jo={};V(Jo,{base2:()=>Ml});var Ml=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ts={};V(ts,{base256emoji:()=>Hl});var $a=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}"),zl=$a.reduce((r,t,e)=>(r[e]=t,r),[]),Kl=$a.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function ql(r){return r.reduce((t,e)=>(t+=zl[e],t),"")}function Vl(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Kl[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Hl=ze({prefix:"\u{1F680}",name:"base256emoji",encode:ql,decode:Vl});var es={};V(es,{base32:()=>Ke,base32hex:()=>Zl,base32hexpad:()=>Xl,base32hexpadupper:()=>Wl,base32hexupper:()=>Yl,base32pad:()=>jl,base32padupper:()=>Gl,base32upper:()=>$l,base32z:()=>Ql});var Ke=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$l=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jl=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gl=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zl=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yl=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xl=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wl=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ql=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var rs={};V(rs,{base36:()=>Br,base36upper:()=>Jl});var Br=Qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Jl=Qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ns={};V(ns,{base58btc:()=>Ot,base58flickr:()=>td});var Ot=Qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),td=Qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var os={};V(os,{base64:()=>ed,base64pad:()=>rd,base64url:()=>nd,base64urlpad:()=>od});var ed=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),rd=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),nd=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),od=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ss={};V(ss,{base8:()=>sd});var sd=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var is={};V(is,{identity:()=>id});var id=ze({prefix:"\0",name:"identity",encode:r=>Ka(r),decode:r=>za(r)});var Bg=new TextEncoder,Tg=new TextDecoder;var cs={};V(cs,{identity:()=>Dd});var ud=Za,ja=128,fd=127,ld=~fd,dd=Math.pow(2,31);function Za(r,t,e){t=t||[],e=e||0;for(var n=e;r>=dd;)t[e++]=r&255|ja,r/=128;for(;r&ld;)t[e++]=r&255|ja,r>>>=7;return t[e]=r|0,Za.bytes=e-n+1,t}var hd=as,pd=128,Ga=127;function as(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw as.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ga)<<o:(i&Ga)*Math.pow(2,o),o+=7}while(i>=pd);return as.bytes=s-n,e}var md=Math.pow(2,7),gd=Math.pow(2,14),bd=Math.pow(2,21),yd=Math.pow(2,28),xd=Math.pow(2,35),wd=Math.pow(2,42),Ed=Math.pow(2,49),vd=Math.pow(2,56),Sd=Math.pow(2,63),_d=function(r){return r<md?1:r<gd?2:r<bd?3:r<yd?4:r<xd?5:r<wd?6:r<Ed?7:r<vd?8:r<Sd?9:10},Ad={encode:ud,decode:hd,encodingLength:_d},Id=Ad,Tr=Id;function Dr(r,t=0){return[Tr.decode(r,t),Tr.decode.bytes]}function qe(r,t,e=0){return Tr.encode(r,t,e),t}function Ve(r){return Tr.encodingLength(r)}function $e(r,t){let e=t.byteLength,n=Ve(r),o=n+Ve(e),s=new Uint8Array(o+e);return qe(r,s,0),qe(e,s,n),s.set(t,o),new He(r,e,t,s)}function Ya(r){let t=qt(r),[e,n]=Dr(t),[o,s]=Dr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new He(e,o,i,t)}function Xa(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ma(r.bytes,e.bytes)}}var He=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=he(n),this.bytes=he(o)}};var Wa=0,Bd="identity",Qa=qt;function Td(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 $e(Wa,Qa(r))}var Dd={code:Wa,name:Bd,encode:Qa,digest:Td};var ls={};V(ls,{sha256:()=>Ld,sha512:()=>Rd});var Cd=20;function fs({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new us(r,t,e,n,o)}var us=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Cd,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?Ja(n,this.code,e?.truncate):n.then(o=>Ja(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ja(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 $e(t,r)}function ec(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ld=fs({name:"sha2-256",code:18,encode:ec("SHA-256")}),Rd=fs({name:"sha2-512",code:19,encode:ec("SHA-512")});function rc(r,t){let{bytes:e,version:n}=r;return n===0?kd(e,ds(r),t??Ot.encoder):Pd(e,ds(r),t??Ke.encoder)}var nc=new WeakMap;function ds(r){let t=nc.get(r);if(t==null){let e=new Map;return nc.set(r,e),e}return t}var An=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=he(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!==Lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Fd)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=$e(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&&Xa(t.multihash,n.multihash)}toString(t){return rc(this,t)}toJSON(){return{"/":rc(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??oc(n,o,s.bytes))}else if(e[Nd]===!0){let{version:n,multihash:o,code:s}=e,i=Ya(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!==Lr)throw new Error(`Version 0 CID must use dag-pb (code: ${Lr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=oc(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Lr,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=qt(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 He(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]=Dr(t.subarray(e));return e+=d,l},o=n(),s=Lr;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]=Od(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 ds(s).set(n,t),s}};function Od(r,t){switch(r[0]){case"Q":{let e=t??Ot;return[Ot.prefix,e.decode(`${Ot.prefix}${r}`)]}case Ot.prefix:{let e=t??Ot;return[Ot.prefix,e.decode(r)]}case Ke.prefix:{let e=t??Ke;return[Ke.prefix,e.decode(r)]}case Br.prefix:{let e=t??Br;return[Br.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 kd(r,t,e){let{prefix:n}=e;if(n!==Ot.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 Pd(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 Lr=112,Fd=18;function oc(r,t,e){let n=Ve(r),o=n+Ve(t),s=new Uint8Array(o+e.byteLength);return qe(r,s,0),qe(t,s,n),s.set(e,o),s}var Nd=Symbol.for("@ipld/js-cid/CID");var hs={...is,...Jo,...ss,...Wo,...Qo,...es,...rs,...ns,...os,...ts},Xg={...ls,...cs};function In(r=0){return new Uint8Array(r)}function ps(r=0){return new Uint8Array(r)}function ic(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var sc=ic("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ms=ic("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=ps(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ud={utf8:sc,"utf-8":sc,hex:hs.base16,latin1:ms,ascii:ms,binary:ms,...hs},Bn=Ud;function ut(r,t="utf8"){let e=Bn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function xt(r,t="utf8"){let e=Bn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Md=parseInt("11111",2),gs=parseInt("10000000",2),zd=parseInt("01111111",2),ac={0:Rr,1:Rr,2:Kd,3:Hd,4:$d,5:Vd,6:qd,16:Rr,22:Rr,48:Rr};function bs(r,t={offset:0}){let e=r[t.offset]&Md;if(t.offset++,ac[e]!=null)return ac[e](r,t);throw new Error("No decoder for tag "+e)}function Or(r,t){let e=0;if((r[t.offset]&gs)===gs){let n=r[t.offset]&zd,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Rr(r,t){Or(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=bs(r,t);if(n===null)break;e.push(n)}return e}function Kd(r,t){let e=Or(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 qd(r,t){let e=Or(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 Vd(r,t){return t.offset++,null}function Hd(r,t){let e=Or(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 $d(r,t){let e=Or(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function jd(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 ys(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=jd(r.byteLength);return new et(Uint8Array.from([t.byteLength|gs]),t)}function cc(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]),ys(t),t)}function uc(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),ys(e),e)}function Tn(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),ys(e),e)}var Gd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Zd=Uint8Array.from([6,5,43,129,4,0,34]),Yd=Uint8Array.from([6,5,43,129,4,0,35]),Xd={ext:!0,kty:"EC",crv:"P-256"},Wd={ext:!0,kty:"EC",crv:"P-384"},Qd={ext:!0,kty:"EC",crv:"P-521"},xs=32,ws=48,Es=66;function fc(r){let t=bs(r);return lc(t)}function lc(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===xs*2+1)return n=xt(t.subarray(e,e+xs),"base64url"),o=xt(t.subarray(e+xs),"base64url"),new je({...Xd,key_ops:["verify"],x:n,y:o});if(t.byteLength===ws*2+1)return n=xt(t.subarray(e,e+ws),"base64url"),o=xt(t.subarray(e+ws),"base64url"),new je({...Wd,key_ops:["verify"],x:n,y:o});if(t.byteLength===Es*2+1)return n=xt(t.subarray(e,e+Es),"base64url"),o=xt(t.subarray(e+Es),"base64url"),new je({...Qd,key_ops:["verify"],x:n,y:o});throw new dt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function dc(r){return Tn([cc(Uint8Array.from([1])),Tn([Jd(r.crv)],160),Tn([uc(new et(Uint8Array.from([4]),ut(r.x??"","base64url"),ut(r.y??"","base64url")))],161)]).subarray()}function Jd(r){if(r==="P-256")return Gd;if(r==="P-384")return Zd;if(r==="P-521")return Yd;throw new dt(`Invalid curve ${r}`)}var je=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=dc(this.jwk)),this._raw}toMultihash(){return _t.digest(Ge(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}async verify(t,e,n){return Pa(this.jwk,e,t,n)}};function vs(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Jt(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 gt(r,t,e=""){let n=vs(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 Dn(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Jt(r.outputLen),Jt(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ze(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 Cn(r,t){gt(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 Ln(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var pc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",th=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Rn(r){if(gt(r),pc)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=th[r[e]];return t}var Vt={_0:48,_9:57,A:65,F:70,a:97,f:102};function hc(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 kr(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(pc)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=hc(r.charCodeAt(s)),a=hc(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 Ss(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];gt(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 _s(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 mc(r=32){Jt(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 As=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function gc(r,t,e){return r&t^~r&e}function bc(r,t,e){return r&t^r&e^t&e}var Pr=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=Ln(this.buffer)}update(t){Ze(this),gt(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=Ln(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){Ze(this),Cn(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=Ln(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 On=BigInt(4294967295),yc=BigInt(32);function eh(r,t=!1){return t?{h:Number(r&On),l:Number(r>>yc&On)}:{h:Number(r>>yc&On)|0,l:Number(r&On)|0}}function xc(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}=eh(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Is=(r,t,e)=>r>>>e,Bs=(r,t,e)=>r<<32-e|t>>>e,pe=(r,t,e)=>r>>>e|t<<32-e,me=(r,t,e)=>r<<32-e|t>>>e,Fr=(r,t,e)=>r<<64-e|t>>>e-32,Nr=(r,t,e)=>r>>>e-32|t<<64-e;function kt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var wc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ec=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,vc=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Sc=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,_c=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ac=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var nh=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]),te=new Uint32Array(64),Ts=class extends Pr{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)te[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=te[l-15],p=te[l-2],m=It(d,7)^It(d,18)^d>>>3,y=It(p,17)^It(p,19)^p>>>10;te[l]=y+te[l-7]+m+te[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=It(a,6)^It(a,11)^It(a,25),p=f+d+gc(a,c,u)+nh[l]+te[l]|0,y=(It(n,2)^It(n,13)^It(n,22))+bc(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+y|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(te)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ht(this.buffer)}},Ds=class extends Ts{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 Ic=xc(["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))),oh=Ic[0],sh=Ic[1],ee=new Uint32Array(80),re=new Uint32Array(80),Cs=class extends Pr{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:m,Hh:y,Hl:h}=this;return[t,e,n,o,s,i,a,c,u,f,l,d,p,m,y,h]}set(t,e,n,o,s,i,a,c,u,f,l,d,p,m,y,h){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=m|0,this.Hh=y|0,this.Hl=h|0}process(t,e){for(let S=0;S<16;S++,e+=4)ee[S]=t.getUint32(e),re[S]=t.getUint32(e+=4);for(let S=16;S<80;S++){let T=ee[S-15]|0,B=re[S-15]|0,O=pe(T,B,1)^pe(T,B,8)^Is(T,B,7),L=me(T,B,1)^me(T,B,8)^Bs(T,B,7),I=ee[S-2]|0,P=re[S-2]|0,q=pe(I,P,19)^Fr(I,P,61)^Is(I,P,6),F=me(I,P,19)^Nr(I,P,61)^Bs(I,P,6),g=vc(L,F,re[S-7],re[S-16]),x=Sc(g,O,q,ee[S-7],ee[S-16]);ee[S]=x|0,re[S]=g|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:m,Gh:y,Gl:h,Hh:b,Hl:E}=this;for(let S=0;S<80;S++){let T=pe(l,d,14)^pe(l,d,18)^Fr(l,d,41),B=me(l,d,14)^me(l,d,18)^Nr(l,d,41),O=l&p^~l&y,L=d&m^~d&h,I=_c(E,B,L,sh[S],re[S]),P=Ac(I,b,T,O,oh[S],ee[S]),q=I|0,F=pe(n,o,28)^Fr(n,o,34)^Fr(n,o,39),g=me(n,o,28)^Nr(n,o,34)^Nr(n,o,39),x=n&s^n&a^s&a,_=o&i^o&c^i&c;b=y|0,E=h|0,y=p|0,h=m|0,p=l|0,m=d|0,{h:l,l:d}=kt(u|0,f|0,P|0,q|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=wc(q,g,_);n=Ec(v,P,F,x),o=v|0}({h:n,l:o}=kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=kt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=kt(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:m}=kt(this.Fh|0,this.Fl|0,p|0,m|0),{h:y,l:h}=kt(this.Gh|0,this.Gl|0,y|0,h|0),{h:b,l:E}=kt(this.Hh|0,this.Hl|0,b|0,E|0),this.set(n,o,s,i,a,c,u,f,l,d,p,m,y,h,b,E)}roundClean(){Ht(ee,re)}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)}},Ls=class extends Cs{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 Bc=_s(()=>new Ds,As(1));var kn=_s(()=>new Ls,As(3));var M=(r,t,e)=>gt(r,t,e),Os=Jt,Ye=Rn,Q=(...r)=>Ss(...r),Xe=r=>kr(r),ge=vs,Ur=r=>mc(r),Fn=BigInt(0),Rs=BigInt(1);function Bt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function Nn(r){if(typeof r=="bigint"){if(!Pn(r))throw new RangeError("positive bigint expected, got "+r)}else Os(r);return r}function Tt(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 Mr(r){let t=Nn(r).toString(16);return t.length&1?"0"+t:t}function Tc(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?Fn:BigInt("0x"+r)}function be(r){return Tc(Rn(r))}function Pt(r){return Tc(Rn(zr(gt(r)).reverse()))}function Un(r,t){if(Jt(t),t===0)throw new RangeError("zero length");r=Nn(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return kr(e.padStart(t*2,"0"))}function ks(r,t){return Un(r,t).reverse()}function Dc(r,t){if(r=M(r),t=M(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 zr(r){return Uint8Array.from(M(r))}function Mn(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"&&Fn<=r;function ih(r,t,e){return Pn(r)&&Pn(t)&&Pn(e)&&t<=r&&r<e}function We(r,t,e,n){if(!ih(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Qe(r){if(r<Fn)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>Fn;r>>=Rs,t+=1);return t}var Kr=r=>(Rs<<BigInt(r))-Rs;function Cc(r,t,e){if(Jt(r,"hashLen"),Jt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=h=>new Uint8Array(h),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=(...h)=>e(u,Q(c,...h)),p=(h=o)=>{u=d(s,h),c=d(),h.length!==0&&(u=d(i,h),c=d())},m=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let h=0,b=[];for(;h<t;){c=d();let E=c.slice();b.push(E),h+=c.length}return Q(...b)};return(h,b)=>{l(),p(h);let E;for(;(E=b(m()))===void 0;)p();return l(),E}}function Dt(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 Ps=()=>{throw new Error("not implemented")};var st=BigInt(0),G=BigInt(1),ye=BigInt(2),kc=BigInt(3),Pc=BigInt(4),Fc=BigInt(5),ah=BigInt(7),Nc=BigInt(8),ch=BigInt(9),Uc=BigInt(16);function X(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 Lc(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=X(r,t),n=t,o=st,s=G,i=G,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!==G)throw new Error("invert: does not exist");return X(o,t)}function Fs(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Mc(r,t){let e=r,n=(e.ORDER+G)/Pc,o=e.pow(t,n);return Fs(e,o,t),o}function uh(r,t){let e=r,n=(e.ORDER-Fc)/Nc,o=e.mul(t,ye),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,ye),s),c=e.mul(i,e.sub(a,e.ONE));return Fs(e,c,t),c}function fh(r){let t=Je(r),e=zc(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+ah)/Uc;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),m=u.eql(u.sqr(l),c),y=u.eql(u.sqr(d),c);f=u.cmov(f,l,m),l=u.cmov(p,d,y);let h=u.eql(u.sqr(l),c),b=u.cmov(f,l,h);return Fs(u,b,c),b})}function zc(r){if(r<kc)throw new Error("sqrt is not defined for small field");let t=r-G,e=0;for(;t%ye===st;)t/=ye,e++;let n=ye,o=Je(r);for(;Rc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Mc;let s=o.pow(n,t),i=(t+G)/ye;return function(c,u){let f=c;if(f.is0(u))return u;if(Rc(f,u)!==1)throw new Error("Cannot find square root");let l=e,d=f.mul(f.ONE,s),p=f.pow(u,t),m=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))return f.ZERO;let y=1,h=f.sqr(p);for(;!f.eql(h,f.ONE);)if(y++,h=f.sqr(h),y===l)throw new Error("Cannot find square root");let b=G<<BigInt(l-y-1),E=f.pow(d,b);l=y,d=f.sqr(E),p=f.mul(p,d),m=f.mul(m,E)}return m}}function lh(r){return r%Pc===kc?Mc:r%Nc===Fc?uh:r%Uc===ch?fh(r):zc(r)}var jt=(r,t)=>(X(r,t)&G)===G,dh=["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=dh.reduce((n,o)=>(n[o]="function",n),t);if(Dt(r,e),Tt(r.BYTES,"BYTES"),Tt(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=G)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function hh(r,t,e){let n=r;if(e<st)throw new Error("invalid exponent, negatives unsupported");if(e===st)return n.ONE;if(e===G)return t;let o=n.ONE,s=t;for(;e>st;)e&G&&(o=n.mul(o,s)),s=n.sqr(s),e>>=G;return o}function qr(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 Rc(r,t){let e=r,n=(e.ORDER-G)/ye,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 ph(r,t){if(t!==void 0&&Os(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 Oc=new WeakMap,zn=class{ORDER;BITS;BYTES;isLE;ZERO=st;ONE=G;_lengths;_mod;constructor(t,e={}){if(t<=G)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}=ph(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 X(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&G)===G}neg(t){return X(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return X(t*t,this.ORDER)}add(t,e){return X(t+e,this.ORDER)}sub(t,e){return X(t-e,this.ORDER)}mul(t,e){return X(t*e,this.ORDER)}pow(t,e){return hh(this,t,e)}div(t,e){return X(t*Lc(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 Lc(t,this.ORDER)}sqrt(t){let e=Oc.get(this);return e||Oc.set(this,e=lh(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?ks(t,this.BYTES):Un(t,this.BYTES)}fromBytes(t,e=!1){M(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?Pt(t):be(t);if(a&&(c=X(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return qr(this,t)}cmov(t,e,n){return Bt(n,"condition"),n?e:t}};Object.freeze(zn.prototype);function Je(r,t={}){return new zn(r,t)}function Kc(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=G)throw new Error("field order must be greater than 1");let t=Qe(r-G);return Math.ceil(t/8)}function Us(r){let t=Kc(r);return t+Math.ceil(t/2)}function Ms(r,t,e=!1){M(r);let n=r.length,o=Kc(t),s=Math.max(Us(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Pt(r):be(r),a=X(i,t-G)+G;return e?ks(a,o):Un(a,o)}var tr=BigInt(0),xe=BigInt(1);function Vr(r,t){let e=t.negate();return r?e:t}function we(r,t){let e=qr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function $c(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function zs(r,t){$c(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=Kr(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function qc(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+=xe);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 Ks=new WeakMap,jc=new WeakMap;function qs(r){return jc.get(r)||1}function Vc(r){if(r!==tr)throw new Error("invalid wNAF")}var er=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>tr;)e&xe&&(n=n.add(o)),o=o.double(),e>>=xe;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=zs(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=zs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:p}=qc(n,a,i);n=c,f?s=s.add(Vr(d,e[p])):o=o.add(Vr(l,e[u]))}return Vc(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=zs(t,this.bits);for(let i=0;i<s.windows&&n!==tr;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=qc(n,i,s);if(n=a,!u){let l=e[c];o=o.add(f?l.negate():l)}}return Vc(n),o}getPrecomputes(t,e,n){let o=Ks.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Ks.set(e,o))),o}cached(t,e,n){let o=qs(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=qs(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){$c(e,this.bits),jc.set(t,e),Ks.delete(t)}hasCache(t){return qs(t)!==1}};function Gc(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>tr||n>tr;)e&xe&&(s=s.add(o)),n&xe&&(i=i.add(o)),o=o.double(),e>>=xe,n>>=xe;return{p1:s,p2:i}}function Hc(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 Je(r,{isLE:e})}function Kn(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>tr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Hc(t.p,e.Fp,n),s=Hc(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 qn(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var ne=BigInt(0),rt=BigInt(1),Vs=BigInt(2),mh=BigInt(8);function gh(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 Zc(r,t={}){let e=t,n=Kn("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Dt(e,{},{uvRatio:"function"});let c=Vs<<BigInt(s.BYTES*8)-rt,u=y=>o.create(y),f=e.uvRatio===void 0?(y,h)=>{try{return{isValid:!0,value:o.sqrt(o.div(y,h))}}catch{return{isValid:!1,value:ne}}}:e.uvRatio;if(!gh(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(y,h,b=!1){let E=b?rt:ne;return We("coordinate "+y,h,E,c),h}function d(y){if(!(y 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(ne,rt,rt,ne);static Fp=o;static Fn=s;X;Y;Z;T;constructor(h,b,E,S){this.X=l("x",h),this.Y=l("y",b),this.Z=l("z",E,!0),this.T=l("t",S),Object.freeze(this)}static CURVE(){return i}static fromAffine(h){if(h instanceof p)throw new Error("extended point not allowed");let{x:b,y:E}=h||{};return l("x",b),l("y",E),new p(b,E,rt,u(b*E))}static fromBytes(h,b=!1){let E=o.BYTES,{a:S,d:T}=i;h=zr(M(h,E,"point")),Bt(b,"zip215");let B=zr(h),O=h[E-1];B[E-1]=O&-129;let L=Pt(B),I=b?c:o.ORDER;We("point.y",L,ne,I);let P=u(L*L),q=u(P-rt),F=u(T*P-S),{isValid:g,value:x}=f(q,F);if(!g)throw new Error("bad point: invalid y coordinate");let _=(x&rt)===rt,v=(O&128)!==0;if(!b&&x===ne&&v)throw new Error("bad point: x=0 and x_0=1");return v!==_&&(x=u(-x)),p.fromAffine({x,y:L})}static fromHex(h,b=!1){return p.fromBytes(Xe(h),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,b=!0){return m.createCache(this,h),b||this.multiply(Vs),this}assertValidity(){let h=this,{a:b,d:E}=i;if(h.is0())throw new Error("bad point: ZERO");let{X:S,Y:T,Z:B,T:O}=h,L=u(S*S),I=u(T*T),P=u(B*B),q=u(P*P),F=u(L*b),g=u(P*u(F+I)),x=u(q+u(E*u(L*I)));if(g!==x)throw new Error("bad point: equation left != right (1)");let _=u(S*T),v=u(B*O);if(_!==v)throw new Error("bad point: equation left != right (2)")}equals(h){d(h);let{X:b,Y:E,Z:S}=this,{X:T,Y:B,Z:O}=h,L=u(b*O),I=u(T*S),P=u(E*O),q=u(B*S);return L===I&&P===q}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:h}=i,{X:b,Y:E,Z:S}=this,T=u(b*b),B=u(E*E),O=u(Vs*u(S*S)),L=u(h*T),I=b+E,P=u(u(I*I)-T-B),q=L+B,F=q-O,g=L-B,x=u(P*F),_=u(q*g),v=u(P*g),w=u(F*q);return new p(x,_,w,v)}add(h){d(h);let{a:b,d:E}=i,{X:S,Y:T,Z:B,T:O}=this,{X:L,Y:I,Z:P,T:q}=h,F=u(S*L),g=u(T*I),x=u(O*E*q),_=u(B*P),v=u((S+T)*(L+I)-F-g),w=_-x,A=_+x,C=u(g-b*F),D=u(v*w),R=u(A*C),k=u(v*C),U=u(w*A);return new p(D,R,U,k)}subtract(h){return d(h),this.add(h.negate())}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:E}=m.cached(this,h,S=>we(p,S));return we(p,[b,E])[0]}multiplyUnsafe(h){if(!s.isValid(h))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return h===ne?p.ZERO:this.is0()||h===rt?this:m.unsafe(this,h,b=>we(p,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(h){let b=this,E=h,{X:S,Y:T,Z:B}=b,O=b.is0();E==null&&(E=O?mh:o.inv(B));let L=u(S*E),I=u(T*E),P=o.mul(B,E);if(O)return{x:ne,y:rt};if(P!==rt)throw new Error("invZ was invalid");return{x:L,y:I}}clearCofactor(){return a===rt?this:this.multiplyUnsafe(a)}toBytes(){let{x:h,y:b}=this.toAffine(),E=o.toBytes(b);return E[E.length-1]|=h&rt?128:0,E}toHex(){return Ye(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=new er(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Vn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Ps()}static fromHex(t){Ps()}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 Ye(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 Yc(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;Dt(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&&(Tt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Ur:o.randomBytes,d=o.adjustScalarBytes===void 0?g=>g:o.adjustScalarBytes,p=o.domain===void 0?(g,x,_)=>{if(Bt(_,"phflag"),x.length||_)throw new Error("Contexts/pre-hash are not supported");return g}:o.domain;function m(g){return c.create(Pt(g))}function y(g){let x=L.secretKey;M(g,L.secretKey,"secretKey");let _=M(n(g),2*x,"hashedSecretKey"),v=d(_.slice(0,x)),w=_.slice(x,2*x),A=m(v);return{head:v,prefix:w,scalar:A}}function h(g){let{head:x,prefix:_,scalar:v}=y(g),w=i.multiply(v),A=w.toBytes();return{head:x,prefix:_,scalar:v,point:w,pointBytes:A}}function b(g){return h(g).pointBytes}function E(g=Uint8Array.of(),...x){let _=Q(...x);return m(n(p(_,M(g,void 0,"context"),!!s)))}function S(g,x,_={}){g=M(g,void 0,"message"),s&&(g=s(g));let{prefix:v,scalar:w,pointBytes:A}=h(x),C=E(_.context,v,g),D=i.multiply(C).toBytes(),R=E(_.context,D,A,g),k=c.create(C+R*w);if(!c.isValid(k))throw new Error("sign failed: invalid s");let U=Q(D,c.toBytes(k));return M(U,L.signature,"result")}let T={zip215:o.zip215};function B(g,x,_,v=T){let{context:w}=v,A=v.zip215===void 0?!!T.zip215:v.zip215,C=L.signature;g=M(g,C,"signature"),x=M(x,void 0,"message"),_=M(_,L.publicKey,"publicKey"),A!==void 0&&Bt(A,"zip215"),s&&(x=s(x));let D=C/2,R=g.subarray(0,D),k=Pt(g.subarray(D,C)),U,z,N;try{U=r.fromBytes(_,A),z=r.fromBytes(R,A),N=i.multiplyUnsafe(k)}catch{return!1}if(!A&&U.isSmallOrder())return!1;let W=E(w,R,_,x);return z.add(U.multiplyUnsafe(W)).subtract(N).clearCofactor().is0()}let O=a.BYTES,L={secretKey:O,publicKey:O,signature:2*O,seed:O};function I(g){return g=g===void 0?l(L.seed):g,M(g,L.seed,"seed")}function P(g){return ge(g)&&g.length===L.secretKey}function q(g,x){try{return!!r.fromBytes(g,x===void 0?T.zip215:x)}catch{return!1}}let F={getExtendedPublicKey:h,randomSecretKey:I,isValidSecretKey:P,isValidPublicKey:q,toMontgomery(g){let{y:x}=r.fromBytes(g),_=L.publicKey,v=_===32;if(!v&&_!==57)throw new Error("only defined for 25519 and 448");let w=v?a.div(rt+x,rt-x):a.div(x-rt,x+rt);return a.toBytes(w)},toMontgomerySecret(g){let x=L.secretKey;M(g,x);let _=n(g.subarray(0,x));return d(_).subarray(0,x)}};return Object.freeze(L),Object.freeze(F),Object.freeze({keygen:qn(I,b),getPublicKey:b,sign:S,verify:B,utils:F,Point:r,lengths:L})}function Hr(r,t){if(Tt(r),Tt(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 bh(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 yh(r){if(!ge(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?Mn(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function Hs(r,t,e,n){M(r),Tt(e),t=yh(t),t.length>255&&(t=n(Q(Mn("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,Hr(t.length,1)),c=new Uint8Array(s),u=Hr(e,2),f=new Array(i),l=n(Q(c,r,u,Hr(0,1),a));f[0]=n(Q(l,Hr(1,1),a));for(let p=1;p<i;p++){let m=[bh(l,f[p-1]),Hr(p+1,1),a];f[p]=n(Q(...m))}return Q(...f).slice(0,e)}var Xc="HashToScalar-";var xh=BigInt(0),Gt=BigInt(1),Wc=BigInt(2);var wh=BigInt(5),Eh=BigInt(8),rr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Zs={p:rr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Eh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function vh(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=rr,a=r*r%s*r%s,c=H(a,Wc,s)*a%s,u=H(c,Gt,s)*r%s,f=H(u,wh,s)*u%s,l=H(f,t,s)*f%s,d=H(l,e,s)*l%s,p=H(d,n,s)*d%s,m=H(p,o,s)*p%s,y=H(m,o,s)*p%s,h=H(y,t,s)*f%s;return{pow_p_5_8:H(h,Wc,s)*r%s,b2:a}}function Sh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var $s=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ys(r,t){let e=rr,n=X(t*t*t,e),o=X(n*n*t,e),s=vh(r*o).pow_p_5_8,i=X(r*n*s,e),a=X(t*i*i,e),c=i,u=X(i*$s,e),f=a===r,l=a===X(-r,e),d=a===X(-r*$s,e);return f&&(i=c),(l||d)&&(i=u),jt(i,e)&&(i=X(-i,e)),{isValid:f||l,value:i}}var se=Zc(Zs,{uvRatio:Ys}),oe=se.Fp,tu=se.Fn;function _h(r){return Yc(se,kn,Object.assign({adjustScalarBytes:Sh,zip215:!0},r))}var eu=_h({});var js=$s,Ah=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ih=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Bh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Th=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Qc=r=>Ys(Gt,r),Dh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Gs=r=>oe.create(Pt(r)&Dh);function Jc(r){let{d:t}=Zs,e=rr,n=b=>oe.create(b),o=n(js*r*r),s=n((o+Gt)*Bh),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=Ys(s,a),f=n(u*r);jt(f,e)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-Gt)*Th-a),d=u*u,p=n((u+u)*a),m=n(l*Ah),y=n(Gt-d),h=n(Gt+d);return new se(n(p*h),n(y*m),n(m*h),n(p*y))}var ie=class r extends Vn{static BASE=new r(se.BASE);static ZERO=new r(se.ZERO);static Fp=oe;static Fn=tu;constructor(t){super(t)}static fromAffine(t){return new r(se.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){gt(t,32);let{a:e,d:n}=Zs,o=rr,s=T=>oe.create(T),i=Gs(t);if(!Dc(oe.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:m}=Qc(s(d*l)),y=s(m*u),h=s(m*y*d),b=s((i+i)*y);jt(b,o)&&(b=s(-b));let E=s(c*h),S=s(b*E);if(!p||jt(S,o)||E===xh)throw new Error("invalid ristretto255 encoding 2");return new r(new se(b,E,Gt,S))}static fromHex(t){return r.fromBytes(kr(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=rr,i=h=>oe.create(h),a=i(i(n+e)*i(n-e)),c=i(t*e),u=i(c*c),{value:f}=Qc(i(a*u)),l=i(f*a),d=i(f*c),p=i(l*d*o),m;if(jt(o*p,s)){let h=i(e*js),b=i(t*js);t=h,e=b,m=i(l*Ih)}else m=d;jt(t*p,s)&&(e=i(-e));let y=i((n-e)*m);return jt(y,s)&&(y=i(-y)),oe.toBytes(y)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>oe.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(ie.BASE);Object.freeze(ie.ZERO);Object.freeze(ie.prototype);Object.freeze(ie);var Ch=Object.freeze({Point:ie,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Hs(r,e,64,kn);return Ch.deriveToCurve(n)},hashToScalar(r,t={DST:Xc}){let e=Hs(r,t.DST,64,kn);return tu.create(Pt(e))},deriveToCurve(r){gt(r,64);let t=Gs(r.subarray(0,32)),e=Jc(t),n=Gs(r.subarray(32,64)),o=Jc(n);return new ie(e.add(o))}});var $r=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Hn=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 Hn("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 jn=32;var Xs,Lh=(async()=>{try{return await $n.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Rh(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,Me(t),Me(e instanceof Uint8Array?e:e.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Oh(r,t,e){return eu.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function ru(r,t,e){return Xs==null&&(Xs=await Lh),Xs?Rh(r,t,e):Oh(r,t,e)}function Gn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Zn=class{type="Ed25519";raw;constructor(t){this.raw=Ws(t,jn)}toMultihash(){return _t.digest(Ge(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=ru(this.raw,e,t);return Gn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ou(r){return r=Ws(r,jn),new Zn(r)}function Ws(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new dt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function su(r=0){return new Uint8Array(r)}var Ph=Math.pow(2,7),Fh=Math.pow(2,14),Nh=Math.pow(2,21),Qs=Math.pow(2,28),Js=Math.pow(2,35),ti=Math.pow(2,42),ei=Math.pow(2,49),K=128,ft=127;function mt(r){if(r<Ph)return 1;if(r<Fh)return 2;if(r<Nh)return 3;if(r<Qs)return 4;if(r<Js)return 5;if(r<ti)return 6;if(r<ei)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function nr(r,t,e=0){switch(mt(r)){case 8:t[e++]=r&255|K,r/=128;case 7:t[e++]=r&255|K,r/=128;case 6:t[e++]=r&255|K,r/=128;case 5:t[e++]=r&255|K,r/=128;case 4:t[e++]=r&255|K,r>>>=7;case 3:t[e++]=r&255|K,r>>>=7;case 2:t[e++]=r&255|K,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Uh(r,t,e=0){switch(mt(r)){case 8:t.set(e++,r&255|K),r/=128;case 7:t.set(e++,r&255|K),r/=128;case 6:t.set(e++,r&255|K),r/=128;case 5:t.set(e++,r&255|K),r/=128;case 4:t.set(e++,r&255|K),r>>>=7;case 3:t.set(e++,r&255|K),r>>>=7;case 2:t.set(e++,r&255|K),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ri(r,t){let e=r[t],n=0;if(n+=e&ft,e<K||(e=r[t+1],n+=(e&ft)<<7,e<K)||(e=r[t+2],n+=(e&ft)<<14,e<K)||(e=r[t+3],n+=(e&ft)<<21,e<K)||(e=r[t+4],n+=(e&ft)*Qs,e<K)||(e=r[t+5],n+=(e&ft)*Js,e<K)||(e=r[t+6],n+=(e&ft)*ti,e<K)||(e=r[t+7],n+=(e&ft)*ei,e<K))return n;throw new RangeError("Could not decode varint")}function Mh(r,t){let e=r.get(t),n=0;if(n+=e&ft,e<K||(e=r.get(t+1),n+=(e&ft)<<7,e<K)||(e=r.get(t+2),n+=(e&ft)<<14,e<K)||(e=r.get(t+3),n+=(e&ft)<<21,e<K)||(e=r.get(t+4),n+=(e&ft)*Qs,e<K)||(e=r.get(t+5),n+=(e&ft)*Js,e<K)||(e=r.get(t+6),n+=(e&ft)*ti,e<K)||(e=r.get(t+7),n+=(e&ft)*ei,e<K))return n;throw new RangeError("Could not decode varint")}function iu(r,t,e=0){return t==null&&(t=su(mt(r))),t instanceof Uint8Array?nr(r,t,e):Uh(r,t,e)}function jr(r,t=0){return r instanceof Uint8Array?ri(r,t):Mh(r,t)}var ni=new Float32Array([-0]),ae=new Uint8Array(ni.buffer);function cu(r,t,e){ni[0]=r,t[e]=ae[0],t[e+1]=ae[1],t[e+2]=ae[2],t[e+3]=ae[3]}function uu(r,t){return ae[0]=r[t],ae[1]=r[t+1],ae[2]=r[t+2],ae[3]=r[t+3],ni[0]}var oi=new Float64Array([-0]),lt=new Uint8Array(oi.buffer);function fu(r,t,e){oi[0]=r,t[e]=lt[0],t[e+1]=lt[1],t[e+2]=lt[2],t[e+3]=lt[3],t[e+4]=lt[4],t[e+5]=lt[5],t[e+6]=lt[6],t[e+7]=lt[7]}function lu(r,t){return lt[0]=r[t],lt[1]=r[t+1],lt[2]=r[t+2],lt[3]=r[t+3],lt[4]=r[t+4],lt[5]=r[t+5],lt[6]=r[t+6],lt[7]=r[t+7],oi[0]}var zh=BigInt(Number.MAX_SAFE_INTEGER),Kh=BigInt(Number.MIN_SAFE_INTEGER),bt=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 Ee;if(t<zh&&t>Kh)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>du&&(o=0n,++n>du&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ee;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):Ee}},Ee=new bt(0,0);Ee.toBigInt=function(){return 0n};Ee.zzEncode=Ee.zzDecode=function(){return this};Ee.length=function(){return 1};var du=4294967296n;function hu(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 pu(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 si(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 Ct(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Yn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ii=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,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 Yn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return Yn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=uu(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=lu(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 Ct(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return pu(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 bt(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 Ct(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 Ct(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 Ct(this,8);let t=Yn(this.buf,this.pos+=4),e=Yn(this.buf,this.pos+=4);return new bt(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=ri(this.buf,this.pos);return this.pos+=mt(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 Gr(r){return new ii(r instanceof Uint8Array?r:r.subarray())}function wt(r,t,e){let n=Gr(r);return t.decode(n,void 0,e)}function ve(r=0){return new Uint8Array(r)}var ai={};V(ai,{base10:()=>qh});var qh=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var ci={};V(ci,{base16:()=>Vh,base16upper:()=>Hh});var Vh=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Hh=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ui={};V(ui,{base2:()=>$h});var $h=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fi={};V(fi,{base256emoji:()=>Xh});var gu=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}"),jh=gu.reduce((r,t,e)=>(r[e]=t,r),[]),Gh=gu.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Zh(r){return r.reduce((t,e)=>(t+=jh[e],t),"")}function Yh(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Gh[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Xh=ke({prefix:"\u{1F680}",name:"base256emoji",encode:Zh,decode:Yh});var di={};V(di,{base64:()=>Wh,base64pad:()=>Qh,base64url:()=>li,base64urlpad:()=>Jh});var Wh=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qh=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),li=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jh=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var hi={};V(hi,{base8:()=>tp});var tp=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var pi={};V(pi,{identity:()=>ep});var ep=ke({prefix:"\0",name:"identity",encode:r=>va(r),decode:r=>Ea(r)});var Qy=new TextEncoder,Jy=new TextDecoder;var bi={};V(bi,{sha256:()=>Zr,sha512:()=>sp});var op=20;function gi({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new mi(r,t,e,n,o)}var mi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??op,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?bu(n,this.code,e?.truncate):n.then(o=>bu(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function bu(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 Ue(t,r)}function xu(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Zr=gi({name:"sha2-256",code:18,encode:xu("SHA-256")}),sp=gi({name:"sha2-512",code:19,encode:xu("SHA-512")});var ce={...pi,...ui,...hi,...ai,...ci,...Ko,...qo,...zo,...di,...fi},lx={...bi,...$o};function Eu(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var wu=Eu("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),yi=Eu("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=ve(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ip={utf8:wu,"utf-8":wu,hex:ce.base16,latin1:yi,ascii:yi,binary:yi,...ce},vu=ip;function Su(r,t="utf8"){let e=vu[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function xi(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ve(i);o+i>t&&(n=ve(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Se=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function wi(){}var vi=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ap=xi();function cp(r){return globalThis.Buffer!=null?ve(r):ap(r)}var Xr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Se(wi,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Se(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Si((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(Xn,10,bt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=bt.fromBigInt(t);return this._push(Xn,e.length(),e)}uint64Number(t){return this._push(nr,mt(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=bt.fromBigInt(t).zzEncode();return this._push(Xn,e.length(),e)}sint64Number(t){let e=bt.fromNumber(t).zzEncode();return this._push(Xn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ei,1,t?1:0)}fixed32(t){return this._push(Yr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=bt.fromBigInt(t);return this._push(Yr,4,e.lo)._push(Yr,4,e.hi)}fixed64Number(t){let e=bt.fromNumber(t);return this._push(Yr,4,e.lo)._push(Yr,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(cu,4,t)}double(t){return this._push(fu,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ei,1,0):this.uint32(e)._push(fp,e,t)}string(t){let e=hu(t);return e!==0?this.uint32(e)._push(si,e,t):this._push(Ei,1,0)}fork(){return this.states=new vi(this),this.head=this.tail=new Se(wi,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 Se(wi,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=cp(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ei(r,t,e){t[e]=r&255}function up(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Si=class extends Se{next;constructor(t,e){super(up,t,e),this.next=void 0}};function Xn(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 Yr(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 fp(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Xr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(lp,t,r),this},Xr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(dp,t,r),this});function lp(r,t,e){t.set(r,e)}function dp(r,t,e){r.length<40?si(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Su(r),e)}function _i(){return new Xr}function Et(r,t){let e=_i();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*vt(r,t,e){let n=Gr(r);yield*t.stream(n,void 0,"$",e)}var Wn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Qn(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function _e(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 Qn("enum",Wn.VARINT,e,n,o)}function St(r,t,e){return Qn("message",Wn.LENGTH_DELIMITED,r,t,e)}var Wr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ht;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ht||(ht={}));var Ai;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Ai||(Ai={}));(function(r){r.codec=()=>_e(Ai)})(ht||(ht={}));var Qr;(function(r){let t;r.codec=()=>(t==null&&(t=St((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ht.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=ht.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:ht.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 Et(s,r.codec())}r.encode=e;function n(s,i){return wt(s,r.codec(),i)}r.decode=n;function o(s,i){return vt(s,r.codec(),i)}r.stream=o})(Qr||(Qr={}));var Ii;(function(r){let t;r.codec=()=>(t==null&&(t=St((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ht.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=ht.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:ht.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 Et(s,r.codec())}r.encode=e;function n(s,i){return wt(s,r.codec(),i)}r.decode=n;function o(s,i){return vt(s,r.codec(),i)}r.stream=o})(Ii||(Ii={}));var Jn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(Dn(t),gt(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 Ze(this),this.iHash.update(t),this}digestInto(t){Ze(this),Cn(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()}},_u=(()=>{let r=((t,e,n)=>new Jn(t,e).update(n).digest());return r.create=(t,e)=>new Jn(t,e),r})();var Au=(r,t)=>(r+(r>=0?t:-t)/Iu)/t;function pp(r,t,e){We("scalar",r,Ft,e);let[[n,o],[s,i]]=t,a=Au(i*r,e),c=Au(-o*r,e),u=r-a*n-c*s,f=-a*o-c*i,l=u<Ft,d=f<Ft;l&&(u=-u),d&&(f=-f);let p=Kr(Math.ceil(Qe(e)/2))+ue;if(u<Ft||u>=p||f<Ft||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Ti(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Bi(r,t){Dt(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Bt(e.lowS,"lowS"),Bt(e.prehash,"prehash"),e.format!==void 0&&Ti(e.format),e}var Di=class extends Error{constructor(t=""){super(t)}},Lt={Err:Di,_tlv:{encode:(r,t)=>{let{Err:e}=Lt;if(Tt(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=Mr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Mr(o.length/2|128):"";return Mr(r)+s+o+t},decode(r,t){let{Err:e}=Lt;t=M(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}=Lt;if(Nn(r),r<Ft)throw new t("integer: negative integers are not allowed");let e=Mr(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}=Lt;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 be(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Lt,o=M(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}=Lt,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(Lt._tlv);Object.freeze(Lt._int);Object.freeze(Lt);var Ft=BigInt(0),ue=BigInt(1),Iu=BigInt(2),to=BigInt(3),mp=BigInt(4);function Bu(r,t={}){let e=Kn("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;Dt(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=Du(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(F,g,x){if(u&&g.is0())return Uint8Array.of(0);let{x:_,y:v}=g.toAffine(),w=n.toBytes(_);if(Bt(x,"isCompressed"),x){l();let A=!n.isOdd(v);return Q(Tu(A),w)}else return Q(Uint8Array.of(4),w,n.toBytes(v))}function p(F){M(F,void 0,"Point");let{publicKey:g,publicKeyUncompressed:x}=f,_=F.length,v=F[0],w=F.subarray(1);if(u&&_===1&&v===0)return{x:n.ZERO,y:n.ZERO};if(_===g&&(v===2||v===3)){let A=n.fromBytes(w);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let C=h(A),D;try{D=n.sqrt(C)}catch(U){let z=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}l();let R=n.isOdd(D);return(v&1)===1!==R&&(D=n.neg(D)),{x:A,y:D}}else if(_===x&&v===4){let A=n.BYTES,C=n.fromBytes(w.subarray(0,A)),D=n.fromBytes(w.subarray(A,A*2));if(!b(C,D))throw new Error("bad point: is not on curve");return{x:C,y:D}}else throw new Error(`bad point: got length ${_}, expected compressed=${g} or uncompressed=${x}`)}let m=t.toBytes===void 0?d:t.toBytes,y=t.fromBytes===void 0?p:t.fromBytes;function h(F){let g=n.sqr(F),x=n.mul(g,F);return n.add(n.add(x,n.mul(F,s.a)),s.b)}function b(F,g){let x=n.sqr(g),_=h(F);return n.eql(x,_)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let E=n.mul(n.pow(s.a,to),mp),S=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(E,S)))throw new Error("bad curve params: a or b");function T(F,g,x=!1){if(!n.isValid(g)||x&&n.is0(g))throw new Error(`bad point coordinate ${F}`);return g}function B(F){if(!(F instanceof I))throw new Error("Weierstrass Point expected")}function O(F){if(!c||!c.basises)throw new Error("no endo");return pp(F,c.basises,o.ORDER)}function L(F,g,x,_,v){return x=new I(n.mul(x.X,F),x.Y,x.Z),g=Vr(_,g),x=Vr(v,x),g.add(x)}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(g,x,_){this.X=T("x",g),this.Y=T("y",x,!0),this.Z=T("z",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x,y:_}=g||{};if(!g||!n.isValid(x)||!n.isValid(_))throw new Error("invalid affine point");if(g instanceof I)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(_)?I.ZERO:new I(x,_,n.ONE)}static fromBytes(g){let x=I.fromAffine(y(M(g,void 0,"point")));return x.assertValidity(),x}static fromHex(g){return I.fromBytes(Xe(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,x=!0){return q.createCache(this,g),x||this.multiply(to),this}assertValidity(){let g=this;if(g.is0()){if(t.allowInfinityPoint&&n.is0(g.X)&&n.eql(g.Y,n.ONE)&&n.is0(g.Z))return;throw new Error("bad point: ZERO")}let{x,y:_}=g.toAffine();if(!n.isValid(x)||!n.isValid(_))throw new Error("bad point: x or y not field elements");if(!b(x,_))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){B(g);let{X:x,Y:_,Z:v}=this,{X:w,Y:A,Z:C}=g,D=n.eql(n.mul(x,C),n.mul(w,v)),R=n.eql(n.mul(_,C),n.mul(A,v));return D&&R}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:x}=s,_=n.mul(x,to),{X:v,Y:w,Z:A}=this,C=n.ZERO,D=n.ZERO,R=n.ZERO,k=n.mul(v,v),U=n.mul(w,w),z=n.mul(A,A),N=n.mul(v,w);return N=n.add(N,N),R=n.mul(v,A),R=n.add(R,R),C=n.mul(g,R),D=n.mul(_,z),D=n.add(C,D),C=n.sub(U,D),D=n.add(U,D),D=n.mul(C,D),C=n.mul(N,C),R=n.mul(_,R),z=n.mul(g,z),N=n.sub(k,z),N=n.mul(g,N),N=n.add(N,R),R=n.add(k,k),k=n.add(R,k),k=n.add(k,z),k=n.mul(k,N),D=n.add(D,k),z=n.mul(w,A),z=n.add(z,z),k=n.mul(z,N),C=n.sub(C,k),R=n.mul(z,U),R=n.add(R,R),R=n.add(R,R),new I(C,D,R)}add(g){B(g);let{X:x,Y:_,Z:v}=this,{X:w,Y:A,Z:C}=g,D=n.ZERO,R=n.ZERO,k=n.ZERO,U=s.a,z=n.mul(s.b,to),N=n.mul(x,w),W=n.mul(_,A),J=n.mul(v,C),tt=n.add(x,_),Z=n.add(w,A);tt=n.mul(tt,Z),Z=n.add(N,W),tt=n.sub(tt,Z),Z=n.add(x,v);let pt=n.add(w,C);return Z=n.mul(Z,pt),pt=n.add(N,J),Z=n.sub(Z,pt),pt=n.add(_,v),D=n.add(A,C),pt=n.mul(pt,D),D=n.add(W,J),pt=n.sub(pt,D),k=n.mul(U,Z),D=n.mul(z,J),k=n.add(D,k),D=n.sub(W,k),k=n.add(W,k),R=n.mul(D,k),W=n.add(N,N),W=n.add(W,N),J=n.mul(U,J),Z=n.mul(z,Z),W=n.add(W,J),J=n.sub(N,J),J=n.mul(U,J),Z=n.add(Z,J),N=n.mul(W,Z),R=n.add(R,N),N=n.mul(pt,Z),D=n.mul(tt,D),D=n.sub(D,N),N=n.mul(tt,W),k=n.mul(pt,k),k=n.add(k,N),new I(D,R,k)}subtract(g){return B(g),this.add(g.negate())}is0(){return this.equals(I.ZERO)}multiply(g){let{endo:x}=t;if(!o.isValidNot0(g))throw new RangeError("invalid scalar: out of range");let _,v,w=A=>q.cached(this,A,C=>we(I,C));if(x){let{k1neg:A,k1:C,k2neg:D,k2:R}=O(g),{p:k,f:U}=w(C),{p:z,f:N}=w(R);v=U.add(N),_=L(x.beta,k,z,A,D)}else{let{p:A,f:C}=w(g);_=A,v=C}return we(I,[_,v])[0]}multiplyUnsafe(g){let{endo:x}=t,_=this,v=g;if(!o.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===Ft||_.is0())return I.ZERO;if(v===ue)return _;if(q.hasCache(this))return this.multiply(v);if(x){let{k1neg:w,k1:A,k2neg:C,k2:D}=O(v),{p1:R,p2:k}=Gc(I,_,A,D);return L(x.beta,R,k,w,C)}else return q.unsafe(_,v)}toAffine(g){let x=this,_=g,{X:v,Y:w,Z:A}=x;if(n.eql(A,n.ONE))return{x:v,y:w};let C=x.is0();_==null&&(_=C?n.ONE:n.inv(A));let D=n.mul(v,_),R=n.mul(w,_),k=n.mul(A,_);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:D,y:R}}isTorsionFree(){let{isTorsionFree:g}=t;return i===ue?!0:g?g(I,this):q.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===ue?this:g?g(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ue?this.is0():this.clearCofactor().is0()}toBytes(g=!0){return Bt(g,"isCompressed"),this.assertValidity(),m(I,this,g)}toHex(g=!0){return Ye(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,q=new er(I,t.endo?Math.ceil(P/2):P);return P>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function Tu(r){return Uint8Array.of(r?2:3)}function Du(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function gp(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?Ur:t.randomBytes,o=Object.assign(Du(r.Fp,e),{seed:Math.max(Us(e.ORDER),16)});function s(p){try{let m=e.fromBytes(p);return e.isValidNot0(m)}catch{return!1}}function i(p,m){let{publicKey:y,publicKeyUncompressed:h}=o;try{let b=p.length;return m===!0&&b!==y||m===!1&&b!==h?!1:!!r.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Ms(M(p,o.seed,"seed"),e.ORDER)}function c(p,m=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(m)}function u(p){let{secretKey:m,publicKey:y,publicKeyUncompressed:h}=o,b=e._lengths;if(!ge(p))return;let E=M(p,void 0,"key").length,S=E===y||E===h,T=E===m||!!b?.includes(E);if(!(S&&T))return S}function f(p,m,y=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(m)===!1)throw new Error("second arg must be public key");let h=e.fromBytes(p);return r.fromBytes(m).multiply(h).toBytes(y)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=qn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:r,utils:l,lengths:o})}function Cu(r,t,e={}){let n=t;Dn(n),Dt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?Ur:e.randomBytes,s=e.hmac===void 0?(v,w)=>_u(n,v,w):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:p,lengths:m}=gp(r,e),y={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},h=c*Iu+ue<i.ORDER;function b(v){let w=c>>ue;return v>w}function E(v,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return w}function S(){if(h)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function T(v,w){Ti(w);let A=m.signature,C=w==="compact"?A:w==="recovered"?A+1:void 0;return M(v,C)}class B{r;s;recovery;constructor(w,A,C){if(this.r=E("r",w),this.s=E("s",A),C!=null){if(S(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(w,A=y.format){T(w,A);let C;if(A==="der"){let{r:U,s:z}=Lt.toSig(M(w));return new B(U,z)}A==="recovered"&&(C=w[0],A="compact",w=w.subarray(1));let D=m.signature/2,R=w.subarray(0,D),k=w.subarray(D,D*2);return new B(a.fromBytes(R),a.fromBytes(k),C)}static fromHex(w,A){return this.fromBytes(Xe(w),A)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new B(this.r,this.s,w)}recoverPublicKey(w){let{r:A,s:C}=this,D=this.assertRecovery(),R=D===2||D===3?A+c:A;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=i.toBytes(R),U=r.fromBytes(Q(Tu((D&1)===0),k)),z=a.inv(R),N=L(M(w,void 0,"msgHash")),W=a.create(-N*z),J=a.create(C*z),tt=r.BASE.multiplyUnsafe(W).add(U.multiplyUnsafe(J));if(tt.is0())throw new Error("invalid recovery: point at infinify");return tt.assertValidity(),tt}hasHighS(){return b(this.s)}toBytes(w=y.format){if(Ti(w),w==="der")return Xe(Lt.hexFromSig(this));let{r:A,s:C}=this,D=a.toBytes(A),R=a.toBytes(C);return w==="recovered"?(S(),Q(Uint8Array.of(this.assertRecovery()),D,R)):Q(D,R)}toHex(w){return Ye(this.toBytes(w))}}Object.freeze(B.prototype),Object.freeze(B);let O=e.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let A=be(w),C=w.length*8-u;return C>0?A>>BigInt(C):A}:e.bits2int,L=e.bits2int_modN===void 0?function(w){return a.create(O(w))}:e.bits2int_modN,I=Kr(u);function P(v){return We("num < 2^"+u,v,Ft,I),a.toBytes(v)}function q(v,w){return M(v,void 0,"message"),w?M(n(v),void 0,"prehashed message"):v}function F(v,w,A){let{lowS:C,prehash:D,extraEntropy:R}=Bi(A,y);v=q(v,D);let k=L(v),U=a.fromBytes(w);if(!a.isValidNot0(U))throw new Error("invalid private key");let z=[P(U),P(k)];if(R!=null&&R!==!1){let tt=R===!0?o(m.secretKey):R;z.push(M(tt,void 0,"extraEntropy"))}let N=Q(...z),W=k;function J(tt){let Z=O(tt);if(!a.isValidNot0(Z))return;let pt=a.inv(Z),Oe=r.BASE.multiply(Z).toAffine(),xr=a.create(Oe.x);if(xr===Ft)return;let mn=a.create(pt*a.create(W+xr*U));if(mn===Ft)return;let pa=(Oe.x===xr?0:2)|Number(Oe.y&ue),ma=mn;return C&&b(mn)&&(ma=a.neg(mn),pa^=1),new B(xr,ma,h?void 0:pa)}return{seed:N,k2sig:J}}function g(v,w,A={}){let{seed:C,k2sig:D}=F(v,w,A);return Cc(n.outputLen,a.BYTES,s)(C,D).toBytes(A.format)}function x(v,w,A,C={}){let{lowS:D,prehash:R,format:k}=Bi(C,y);if(A=M(A,void 0,"publicKey"),w=q(w,R),!ge(v)){let U=v instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}T(v,k);try{let U=B.fromBytes(v,k),z=r.fromBytes(A);if(D&&U.hasHighS())return!1;let{r:N,s:W}=U,J=L(w),tt=a.inv(W),Z=a.create(J*tt),pt=a.create(N*tt),Oe=r.BASE.multiplyUnsafe(Z).add(z.multiplyUnsafe(pt));return Oe.is0()?!1:a.create(Oe.x)===N}catch{return!1}}function _(v,w,A={}){let{prehash:C}=Bi(A,y);return w=q(w,C),B.fromBytes(v,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:p,lengths:m,Point:r,sign:g,verify:x,recoverPublicKey:_,Signature:B,hash:n})}var Li={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},bp={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Lu=BigInt(2);function yp(r){let t=Li.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,Lu,t)*u%t,m=H(p,o,t)*p%t,y=H(m,s,t)*m%t,h=H(y,a,t)*y%t,b=H(h,c,t)*h%t,E=H(b,a,t)*y%t,S=H(E,e,t)*f%t,T=H(S,i,t)*m%t,B=H(T,n,t)*u%t,O=H(B,Lu,t);if(!Ci.eql(Ci.sqr(O),r))throw new Error("Cannot find square root");return O}var Ci=Je(Li.p,{sqrt:yp}),xp=Bu(Li,{Fp:Ci,endo:bp}),or=Cu(xp,Bc);function Ru(r,t,e,n){let o=Zr.digest(e instanceof Uint8Array?e:e.subarray());if(Gn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),or.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new $r(String(s))});try{return n?.signal?.throwIfAborted(),or.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new $r(String(s))}}var eo=class{type="secp256k1";raw;_key;constructor(t){this._key=ku(t),this.raw=Ou(this._key)}toMultihash(){return _t.digest(Ge(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}verify(t,e,n){return Ru(this._key,e,t,n)}};function Pu(r){return new eo(r)}function Ou(r){return or.Point.fromBytes(r).toBytes()}function ku(r){try{return or.Point.fromBytes(r),r}catch(t){throw new bn(String(t))}}function Fu(r){let{Type:t,Data:e}=Qr.decode(r.digest),n=e??new Uint8Array;switch(t){case ht.Ed25519:return ou(n);case ht.secp256k1:return Pu(n);case ht.ECDSA:return fc(n);default:throw new wr}}function Ge(r){return Qr.encode({Type:ht[r.type],Data:r.raw})}var Nu=Symbol.for("nodejs.util.inspect.custom"),wp=114,Jr=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()})`}[Po]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(wp,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return At(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return At(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Nu](){return`PeerId(${this.toString()})`}},ro=class extends Jr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},no=class extends Jr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},oo=class extends Jr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ep=2336,so=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(ut(this.url))}[Nu](){return`PeerId(${this.url})`}[Po]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(Ep,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=xt(t)),t.toString()===this.toString())}};function Uu(r){if(Sp(r))return new ro({multihash:r});if(vp(r))try{let t=Fu(r);if(t.type==="Ed25519")return new no({multihash:r,publicKey:t});if(t.type==="secp256k1")return new oo({multihash:r,publicKey:t})}catch{let e=xt(r.digest);return new so(new URL(e))}throw new yn("Supplied PeerID Multihash is invalid")}function vp(r){return r.code===_t.code}function Sp(r){return r.code===Zr.code}function Ri(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 io(r){let t=_r(Y.decode(`z${r}`));return Uu(t)}var ao=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 Ri(this.set.entries(),t=>{let e=io(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=io(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ri(this.set.values(),t=>io(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 Oi(){return new ao}var ki={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Mu={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},zu=new globalThis.TextEncoder;function _p(r,t){let e=ki[t],n=Mu[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Ap(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=ki[t],o=Mu[t],s=r;for(;s.length>0;){let i=zu.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 Pi(r,{size:t=32,utf8Buffer:e}={}){if(!ki[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 Ap(r,t,e);r=zu.encode(r)}return _p(r,t)}var tn={hash:r=>Number(Pi(r,{size:32})),hashV:(r,t)=>Ip(tn.hash(r,t))};function Ip(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),ut(t,"base16")}var Fi=64,Rt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Fi)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=In(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?At(this.fp,t.fp):!1}};function Ae(r,t){return Math.floor(Math.random()*(t-r))+r}var Ie=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Rt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Rt))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 Rt))throw new TypeError("Invalid Fingerprint");let e=Ae(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Rt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Bp=500,en=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??tn,this.seed=t.seed??Ae(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=ut(t));let e=new Rt(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 Ie(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Ie(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[Ae(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Ie(this.bucketSize));for(let a=0;a<Bp;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 Ie(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=ut(t));let e=new Rt(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=ut(t));let e=new Rt(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}},Tp={1:.5,2:.84,4:.95,8:.98};function Dp(r=.001){return r>.002?2:r>1e-5?4:8}function Ku(r,t=.001){let e=Dp(t),n=Tp[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Fi);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var co=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??tn,this.seed=t.seed??Ae(0,Math.pow(2,10)),this.filterSeries=[new en({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=ut(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 en({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=ut(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=ut(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 Ni(r,t=.001,e){return new co({...Ku(r,t),...e??{}})}function rn(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 sr(r){let t=rn(r);if(t==null)throw new dt(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var uo=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 qu=45,Cp=15,ir=new uo;function fo(r){if(!(r.length>Cp))return ir.new(r).parseWith(()=>ir.readIPv4Addr())}function lo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>qu))return ir.new(r).parseWith(()=>ir.readIPv6Addr())}function ar(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>qu)return;let e=ir.new(r).parseWith(()=>ir.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 Vu(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 Hu(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 Ui(r){switch(r.length){case Be:return r.join(".");case Te:{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 $u(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 ju(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Be=4,Te=16,V2=parseInt("0xFFFF",16),Lp=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function nn(r,t){t.length===Te&&r.length===Be&&Vu(t,0,11)&&(t=t.slice(12)),t.length===Be&&r.length===Te&&Hu(r,Lp,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 Gu(r,t){if(typeof t=="string"&&(t=ar(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 Mi(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Be,o=fo(t);if(o==null&&(n=Te,o=lo(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=zi(s,8*n);return{network:nn(o,i),mask:i}}function zi(r,t){if(t!==8*Be&&t!==8*Te)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 on=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Mi(t));else{let n=ar(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=ar(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=zi(o,8*n.length);this.network=nn(n,this.mask)}}contains(t){return Gu({network:this.network,mask:this.mask},t)}toString(){let t=$u(this.mask),e=t!==-1?String(t):ju(this.mask);return Ui(this.network)+"/"+e}};function Zu(r,t){return new on(r).contains(t)}function Yu(r){try{let t=sr(r);return t.type==="ip6"?Zu("2000::/3",t.host):!1}catch{return!1}}function cr(r){return!!fo(r)}function ho(r){return!!lo(r)}var Ju=Nf(Qu(),1),Up=["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"],Mp=Up.map(r=>new Ju.Netmask(r));function Gi(r){for(let t of Mp)if(t.contains(r))return!0;return!1}function zp(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Kp(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 Gi(o)}function qp(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Vp(r){let t=r.split(":"),e=t[t.length-1];return Gi(e)}function Hp(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 mo(r){if(cr(r))return Gi(r);if(zp(r))return Kp(r);if(qp(r))return Vp(r);if(ho(r))return Hp(r)}function tf(r){try{let t=sr(r);switch(t.type){case"ip4":case"ip6":return mo(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function ef(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 go(r=0){return new Uint8Array(r)}function sn(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=go(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function nf(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var rf=nf("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Zi=nf("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=go(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),$p={utf8:rf,"utf-8":rf,hex:ce.base16,latin1:Zi,ascii:Zi,binary:Zi,...ce},bo=$p;function an(r,t="utf8"){let e=bo[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Ce(r,t="utf8"){let e=bo[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var it=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Zt=class extends Error{static name="ValidationError";name="ValidationError"},yo=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},xo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Xi(r){return t=>Ce(t,r)}function Wi(r){return t=>an(t,r)}function dr(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Le(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function of(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=an(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=Le(n);return sn([e,o],e.length+o.length)}function sf(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=Le(n);return sn([e,o],e.length+o.length)}function Qi(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=Ce(t,"base32"),o=dr(e);return`${n}:${o}`}var Ji=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},af=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=cr(e[n]),i;s&&(i=Ji(e[n]),e[n]=Ce(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,Ce(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},cf=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(".")},uf=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 ff(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 Yi=Object.values(ce).map(r=>r.decoder),jp=(function(){let r=Yi[0].or(Yi[1]);return Yi.slice(2).forEach(t=>r=r.or(t)),r})();function lf(r){return jp.decode(r)}function df(r){return t=>r.encoder.encode(t)}function Gp(r){if(parseInt(r).toString()!==r)throw new Zt("Value must be an integer")}function Zp(r){if(r<0)throw new Zt("Value must be a positive integer, or zero")}function Yp(r){return t=>{if(t>r)throw new Zt(`Value must be smaller than or equal to ${r}`)}}function Xp(...r){return t=>{for(let e of r)e(t)}}var cn=Xp(Gp,Zp,Yp(65535));var nt=-1,ta=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 xo(`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 ta,P0=[{code:4,name:"ip4",size:32,valueToBytes:Ji,bytesToValue:cf,validate:r=>{if(!cr(r))throw new Zt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Le,bytesToValue:dr,validate:cn},{code:273,name:"udp",size:16,valueToBytes:Le,bytesToValue:dr,validate:cn},{code:33,name:"dccp",size:16,valueToBytes:Le,bytesToValue:dr,validate:cn},{code:41,name:"ip6",size:128,valueToBytes:af,bytesToValue:uf,stringToValue:ff,validate:r=>{if(!ho(r))throw new Zt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:nt},{code:43,name:"ipcidr",size:8,bytesToValue:Xi("base10"),valueToBytes:Wi("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:Le,bytesToValue:dr,validate:cn},{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:Xi("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Wi("base58btc")(r):ct.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Qi,valueToBytes:of},{code:445,name:"onion3",size:296,bytesToValue:Qi,valueToBytes:sf},{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:df(li),valueToBytes:lf},{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}];P0.forEach(r=>{Yt.addProtocol(r)});function hf(r){let t=[],e=0;for(;e<r.length;){let n=jr(r,e),o=Yt.getProtocol(n),s=mt(n),i=F0(o,r,e+s),a=0;i>0&&o.size===nt&&(a=mt(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let f=e+s+a,l=r.subarray(f,f+i);u.value=o.bytesToValue?.(l)??Ce(l)}t.push(u),e+=c}return t}function pf(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Yt.getProtocol(n.code),s=mt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??an(n.value),a=i.byteLength,o.size===nt&&(c=mt(a)));let u=new Uint8Array(s+c+a),f=0;nr(n.code,u,f),f+=s,i!=null&&(o.size===nt&&(nr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return sn(e,t)}function mf(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 gf(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 F0(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:jr(t,e)}var N0=Symbol.for("nodejs.util.inspect.custom"),na=Symbol.for("@multiformats/multiaddr");function U0(r){if(r==null&&(r="/"),bf(r))return r.getComponents();if(r instanceof Uint8Array)return hf(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),mf(r);if(Array.isArray(r))return r;throw new it("Must be a string, Uint8Array, Component[], or another Multiaddr")}var wo=class r{[na]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=U0(t),e.validate!==!1&&M0(this)}get bytes(){return this.#r==null&&(this.#r=pf(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=gf(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 yo(`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 ef(this.bytes,t.bytes)}[N0](){return`Multiaddr(${this.toString()})`}};function M0(r){r.getComponents().forEach(t=>{let e=Yt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function bf(r){return!!r?.[na]}function yf(r){return new wo(r)}function hr(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Eo=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}},pr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Eo(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 Eo(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 oa=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function vo(r={}){return z0(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 z0(r,t){t=t??{};let e=t.onEnd,n=new pr,o,s,i,a=hr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,b)=>{s=E=>{s=null,n.push(E);try{h(r(n))}catch(S){b(S)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=hr()})}},u=h=>s!=null?s(h):(n.push(h),o),f=h=>(n=new pr,s!=null?s({error:h}):(n.push({error:h}),o)),l=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:h})},d=h=>i?o:(i=!0,h!=null?f(h):u({done:!0})),p=()=>(n=new pr,d(),{done:!0}),m=h=>(d(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:m,push:l,end:d,get readableLength(){return n.size},onEmpty:async h=>{let b=h?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let E,S;b!=null&&(E=new Promise((T,B)=>{S=()=>{B(new oa)},b.addEventListener("abort",S)}));try{await Promise.race([a.promise,E])}finally{S!=null&&b!=null&&b?.removeEventListener("abort",S)}}},e==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(h){return y.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return y.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(h){return y.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return y.readableLength},onEmpty:h=>y.onEmpty(h)},o}var sa=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},xf=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function ia(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(xf(i));return}if(i&&(c=()=>{d(xf(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,d),e===Number.POSITIVE_INFINITY)return;let p=new sa;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){d(m)}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 K0=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 q0(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}=K0(r),l=async(...p)=>{let m=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(m))return}catch(y){n(),i(y);return}c.push(m),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=ia(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function mr(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=q0(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function un(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 So=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Re=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function V0(r){return r.reason}async function fn(r,t,e){if(t==null)return r;let n=e?.translateError??V0;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 _o=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=hr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Mt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function H0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ao=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,e){this.id=H0(),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 Mt),this.cleanup())}async join(t){let e=new _o(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 fn(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 Io=class extends xn{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=un(this.emitEmpty.bind(this),1),this.emitIdle=un(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 So;let n=new Ao(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 Mt)}),this.clear()}async onEmpty(t){this.size!==0&&await mr(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await mr(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await mr(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=vo({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 Mt("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 ln(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 $0=4194304,Bo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ca=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ua=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},fa=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function j0(r){return typeof r?.closeRead=="function"}function G0(r){return typeof r?.close=="function"}function aa(r){return j0(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:G0(r)?r.status!=="open":!1}function Z0(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Y0(r,t){let e=t?.maxBufferSize??$0,n=new et,o,s=!1;if(!Z0(r))throw new dt("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 Bo("Stream was unwrapped");if(aa(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 Re(`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 fn(o.promise,f?.signal),aa(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(aa(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Re(`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 Bo("Stream was unwrapped");r.send(f)||await mr(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 X0(r,t={}){let e=Y0(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=mt(t.maxDataLength));let n=t?.lengthDecoder??jr,o=t?.lengthEncoder??iu;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 ca("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new fa(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ua(`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 Re(`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 Re(`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 gr(r,t){let e=X0(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var To=class extends Io{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function wf(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal},f;e?.timeout!=null&&(f=ln([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=un(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 la=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 Ef(r){let{name:t,metrics:e}=r,n;return e!=null?n=new la({name:t,metrics:e}):n=new Map,n}var da="libp2p",ha="autonat";var vf="dial-request",Sf="dial-back",_f=200n*1024n,Af=4096;var br;(function(r){let t;r.codec=()=>(t==null&&(t=St((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),dn.codec().encode(s.dialRequest,i)),s.dialResponse!=null&&(i.uint32(18),Ut.codec().encode(s.dialResponse,i)),s.dialDataRequest!=null&&(i.uint32(26),hn.codec().encode(s.dialDataRequest,i)),s.dialDataResponse!=null&&(i.uint32(34),pn.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=dn.codec().decode(s,s.uint32(),{limits:a.limits?.dialRequest});break}case 2:{c.dialResponse=Ut.codec().decode(s,s.uint32(),{limits:a.limits?.dialResponse});break}case 3:{c.dialDataRequest=hn.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataRequest});break}case 4:{c.dialDataResponse=pn.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*dn.codec().stream(s,s.uint32(),`${a}.dialRequest`,{limits:c.limits?.dialRequest});break}case 2:{yield*Ut.codec().stream(s,s.uint32(),`${a}.dialResponse`,{limits:c.limits?.dialResponse});break}case 3:{yield*hn.codec().stream(s,s.uint32(),`${a}.dialDataRequest`,{limits:c.limits?.dialDataRequest});break}case 4:{yield*pn.codec().stream(s,s.uint32(),`${a}.dialDataResponse`,{limits:c.limits?.dialDataResponse});break}default:{s.skipType(f&7);break}}}})),t);function e(s){return Et(s,r.codec())}r.encode=e;function n(s,i){return wt(s,r.codec(),i)}r.decode=n;function o(s,i){return vt(s,r.codec(),i)}r.stream=o})(br||(br={}));var dn;(function(r){let t;r.codec=()=>(t==null&&(t=St((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 Wr('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 Wr('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 Et(s,r.codec())}r.encode=e;function n(s,i){return wt(s,r.codec(),i)}r.decode=n;function o(s,i){return vt(s,r.codec(),i)}r.stream=o})(dn||(dn={}));var hn;(function(r){let t;r.codec=()=>(t==null&&(t=St((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 Et(s,r.codec())}r.encode=e;function n(s,i){return wt(s,r.codec(),i)}r.decode=n;function o(s,i){return vt(s,r.codec(),i)}r.stream=o})(hn||(hn={}));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 Do;(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"})(Do||(Do={}));(function(r){r.codec=()=>_e(Do)})(at||(at={}));var Ut;(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=()=>_e(e)})(t=r.ResponseStatus||(r.ResponseStatus={}));let n;r.codec=()=>(n==null&&(n=St((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&&Do[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 Et(a,r.codec())}r.encode=o;function s(a,c){return wt(a,r.codec(),c)}r.decode=s;function i(a,c){return vt(a,r.codec(),c)}r.stream=i})(Ut||(Ut={}));var pn;(function(r){let t;r.codec=()=>(t==null&&(t=St((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:In(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 Et(s,r.codec())}r.encode=e;function n(s,i){return wt(s,r.codec(),i)}r.decode=n;function o(s,i){return vt(s,r.codec(),i)}r.stream=o})(pn||(pn={}));var yr;(function(r){let t;r.codec=()=>(t==null&&(t=St((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 Et(s,r.codec())}r.encode=e;function n(s,i){return wt(s,r.codec(),i)}r.decode=n;function o(s,i){return vt(s,r.codec(),i)}r.stream=o})(yr||(yr={}));var le;(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=()=>_e(e)})(t=r.DialBackStatus||(r.DialBackStatus={}));let n;r.codec=()=>(n==null&&(n=St((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 Et(a,r.codec())}r.encode=o;function s(a,c){return wt(a,r.codec(),c)}r.decode=s;function i(a,c){return vt(a,r.codec(),c)}r.stream=i})(le||(le={}));function Co(r,t){return Math.round(Math.random()*(t-r)+r)}var Q0=4,J0=8,Lo=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;constructor(t,e){this.components=t,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=Ef({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=wf(this.findRandomPeers.bind(this),6e4),this.addressFilter=Ni(1024),this.queue=new To({concurrency:3,maxSize:50}),this.maxDialDataBytes=e.maxDialDataBytes??_f,this.dialDataChunkSize=e.dialDataChunkSize??Af,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[wn]=["@libp2p/autonat"];get[En](){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=ln([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=gr(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read(yr,{signal:n});if(!this.nonces.has(s.nonce))throw new yt("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:le.DialBackStatus.OK},le),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=rn(s.multiaddr);return!(a==null||a.type==="ip6"&&(!e||!Yu(s.multiaddr))||tf(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:Oi(),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})=>rn(a)?.type==="ip6"),o=rn(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=ln([a.signal,AbortSignal.timeout(this.timeout)]),u=BigInt(Co(0,Number.MAX_SAFE_INTEGER));this.nonces.add(u);try{await this.askPeerToVerify(t,s,u,a)}finally{c.clear(),this.nonces.delete(u)}},{peerId:t.remotePeer}).catch(a=>{this.log.error("error from %p verifying addresses - %e",t.remotePeer,a)})}}async askPeerToVerify(t,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=gr(i).pb(br);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),m=BigInt(this.dialDataChunkSize);for(let y=0n;y<u.dialDataRequest.numBytes;y+=m)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!==Ut.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),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),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===Q0&&this.confirmAddress(d),d.failure===J0&&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}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}getNetworkSegment(t){let e=sr(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 dt(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};var Ro=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=gr(t,{maxDataLength:this.maxMessageSize}).pb(br),s=Cf(e.remoteAddr);if(s==null)throw new yt(`Could not find IP address in connection address "${e.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new yt("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new yt("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=yf(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:Ut.ResponseStatus.E_DIAL_REFUSED,dialStatus:at.UNUSED}},{signal:n});continue}let f=Cf(c);if(f==null)throw new yt(`Could not find IP address in requested address "${c}"`);if(mo(f))throw new yt(`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:Ut.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=Co(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 yt("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=gr(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:e},yr,n),(await i.read(le,n)).status!==le.DialBackStatus.OK)throw new yt("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 Cf(r){return r.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var Oo=class{client;server;constructor(t,e){let n=`/${e.protocolPrefix??da}/${ha}/${"2"}/${vf}`,o=`/${e.protocolPrefix??da}/${ha}/${"2"}/${Sf}`;this.client=new Lo(t,{...e,dialRequestProtocol:n,dialBackProtocol:o}),this.server=new Ro(t,{...e,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[wn]=["@libp2p/autonat"];get[En](){return["@libp2p/identify"]}async start(){await ya(this.client,this.server)}async stop(){await xa(this.client,this.server)}};function tm(r={}){return t=>new Oo(t,r)}return Uf(em);})();
|
|
2
|
+
"use strict";var Libp2PAutonatV2=(()=>{var zf=Object.create;var wn=Object.defineProperty;var Kf=Object.getOwnPropertyDescriptor;var qf=Object.getOwnPropertyNames;var Vf=Object.getPrototypeOf,Hf=Object.prototype.hasOwnProperty;var ko=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),V=(r,t)=>{for(var e in t)wn(r,e,{get:t[e],enumerable:!0})},Ea=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of qf(t))!Hf.call(r,o)&&o!==e&&wn(r,o,{get:()=>t[o],enumerable:!(n=Kf(t,o))||n.enumerable});return r};var $f=(r,t,e)=>(e=r!=null?zf(Vf(r)):{},Ea(t||!r||!r.__esModule?wn(e,"default",{value:r,enumerable:!0}):e,r)),jf=r=>Ea(wn({},"__esModule",{value:!0}),r);var Ui=ko(dr=>{"use strict";Object.defineProperty(dr,"__esModule",{value:!0});dr.Netmask4Impl=void 0;dr.ip2long=lr;dr.long2ip=Mt;function Mt(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 Mp=48,zp=97,Kp=65;function qp(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)-Mp)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-zp)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.charCodeAt(o)-Kp)>>>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 lr(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]=qp(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 Ni=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=lr(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=(lr(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 r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):(lr(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(Mt(this.netLong+this.size*t),this.mask)}forEach(t){let e=lr(this.first),n=lr(this.last),o=0;for(;e<=n;)t(Mt(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};dr.Netmask4Impl=Ni});var sf=ko(hr=>{"use strict";Object.defineProperty(hr,"__esModule",{value:!0});hr.Netmask6Impl=void 0;hr.ip6bigint=zi;hr.bigint2ip6=Fe;var Vp=Ui(),Mi=(1n<<128n)-1n;function zi(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,Vp.ip2long)(n),s=r.substring(0,e+1)+"0:0";return of(s)&~0xffffffffn|BigInt(o)}return of(r)}function of(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 Fe(r){if(r<0n||r>Mi)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 Ki=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=Mi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=zi(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Fe(this.netBigint),this.mask=Fe(this.maskBigint),this.hostmask=Fe(~this.maskBigint&Mi),this.first=this.base,this.last=Fe(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):(zi(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(Fe(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(Fe(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};hr.Netmask6Impl=Ki});var af=ko(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});pe.long2ip=pe.ip2long=pe.Netmask=void 0;var yo=Ui();Object.defineProperty(pe,"ip2long",{enumerable:!0,get:function(){return yo.ip2long}});Object.defineProperty(pe,"long2ip",{enumerable:!0,get:function(){return yo.long2ip}});var Hp=sf(),qi=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 Hp.Netmask6Impl(t,e):this._impl=new yo.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 yo.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()}};pe.Netmask=qi});var Em={};V(Em,{autoNATv2:()=>wm});var Kt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var mt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},En=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Sn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var St=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var vr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Po=Symbol.for("@libp2p/peer-id");function Sa(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function va(...r){let t=[];for(let e of r)Sa(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 _a(...r){let t=[];for(let e of r)Sa(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 Gf(r){return typeof r?.handleEvent=="function"}function Zf(r){return(r!==!0&&r!==!1&&r?.once)??!1}var vn=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=Zf(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))}Gf(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 _n=Symbol.for("@libp2p/service-capabilities"),An=Symbol.for("@libp2p/service-dependencies");var Ko={};V(Ko,{base58btc:()=>W,base58flickr:()=>rl});var Qm=new Uint8Array(0);function Aa(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 qt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ge(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ge(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Ia(r){return new TextEncoder().encode(r)}function Ba(r){return new TextDecoder().decode(r)}function Yf(r){return r?.buffer instanceof ArrayBuffer}function ge(r){return Yf(r)?r:r.slice()}function Xf(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var b=0,h=0,y=0,E=m.length;y!==E&&m[y]===0;)y++,b++;for(var v=(E-y)*f+1>>>0,T=new Uint8Array(v);y!==E;){for(var B=m[y],O=0,L=v-1;(B!==0||O<h)&&L!==-1;L--,O++)B+=256*T[L]>>>0,T[L]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");h=O,y++}for(var I=v-h;I!==v&&T[I]===0;)I++;for(var k=c.repeat(b);I<v;++I)k+=r.charAt(T[I]);return k}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var h=0,y=0;m[b]===c;)h++,b++;for(var E=(m.length-b)*u+1>>>0,v=new Uint8Array(E);m[b];){var T=e[m.charCodeAt(b)];if(T===255)return;for(var B=0,O=E-1;(T!==0||B<y)&&O!==-1;O--,B++)T+=a*v[O]>>>0,v[O]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");y=B,b++}if(m[b]!==" "){for(var L=E-y;L!==E&&v[L]===0;)L++;for(var I=new Uint8Array(h+(E-L)),k=h;L!==E;)I[k++]=v[L++];return I}}}function p(m){var b=d(m);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:p}}var Wf=Xf,Qf=Wf,Da=Qf;var No=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")}},Uo=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 Ca(this,t)}},Mo=class{decoders;constructor(t){this.decoders=t}or(t){return Ca(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 Ca(r,t){return new Mo({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var zo=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 No(t,e,n),this.decoder=new Uo(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ue({name:r,prefix:t,encode:e,decode:n}){return new zo(r,t,e,n)}function Jt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Da(e,r);return Ue({prefix:t,name:r,encode:n,decode:s=>qt(o(s))})}function Jf(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 tl(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 el(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=el(n);return Ue({prefix:t,name:r,encode(s){return tl(s,n,e)},decode(s){return Jf(s,o,e,r)}})}var W=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rl=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qo={};V(qo,{base32:()=>te,base32hex:()=>il,base32hexpad:()=>cl,base32hexpadupper:()=>ul,base32hexupper:()=>al,base32pad:()=>ol,base32padupper:()=>sl,base32upper:()=>nl,base32z:()=>fl});var te=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),nl=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ol=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),sl=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),il=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),al=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),cl=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ul=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fl=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Vo={};V(Vo,{base36:()=>_r,base36upper:()=>ll});var _r=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ll=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var dl=Oa,La=128,hl=127,pl=~hl,ml=Math.pow(2,31);function Oa(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ml;)t[e++]=r&255|La,r/=128;for(;r&pl;)t[e++]=r&255|La,r>>>=7;return t[e]=r|0,Oa.bytes=e-n+1,t}var gl=Ho,yl=128,Ra=127;function Ho(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ho.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ra)<<o:(i&Ra)*Math.pow(2,o),o+=7}while(i>=yl);return Ho.bytes=s-n,e}var bl=Math.pow(2,7),xl=Math.pow(2,14),wl=Math.pow(2,21),El=Math.pow(2,28),Sl=Math.pow(2,35),vl=Math.pow(2,42),_l=Math.pow(2,49),Al=Math.pow(2,56),Il=Math.pow(2,63),Bl=function(r){return r<bl?1:r<xl?2:r<wl?3:r<El?4:r<Sl?5:r<vl?6:r<_l?7:r<Al?8:r<Il?9:10},Tl={encode:dl,decode:gl,encodingLength:Bl},Dl=Tl,Ar=Dl;function Ir(r,t=0){return[Ar.decode(r,t),Ar.decode.bytes]}function Me(r,t,e=0){return Ar.encode(r,t,e),t}function ze(r){return Ar.encodingLength(r)}function qe(r,t){let e=t.byteLength,n=ze(r),o=n+ze(e),s=new Uint8Array(o+e);return Me(r,s,0),Me(e,s,n),s.set(t,o),new Ke(r,e,t,s)}function Br(r){let t=qt(r),[e,n]=Ir(t),[o,s]=Ir(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 Fa(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Aa(r.bytes,e.bytes)}}var Ke=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=ge(n),this.bytes=ge(o)}};function ka(r,t){let{bytes:e,version:n}=r;return n===0?Ll(e,$o(r),t??W.encoder):Rl(e,$o(r),t??te.encoder)}var Pa=new WeakMap;function $o(r){let t=Pa.get(r);if(t==null){let e=new Map;return Pa.set(r,e),e}return t}var lt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=ge(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!==Tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ol)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=qe(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&&Fa(t.multihash,n.multihash)}toString(t){return ka(this,t)}toJSON(){return{"/":ka(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??Na(n,o,s.bytes))}else if(e[Fl]===!0){let{version:n,multihash:o,code:s}=e,i=Br(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!==Tr)throw new Error(`Version 0 CID must use dag-pb (code: ${Tr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Na(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Tr,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=qt(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]=Ir(t.subarray(e));return e+=d,l},o=n(),s=Tr;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]=Cl(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 $o(s).set(n,t),s}};function Cl(r,t){switch(r[0]){case"Q":{let e=t??W;return[W.prefix,e.decode(`${W.prefix}${r}`)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}case te.prefix:{let e=t??te;return[te.prefix,e.decode(r)]}case _r.prefix:{let e=t??_r;return[_r.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 Ll(r,t,e){let{prefix:n}=e;if(n!==W.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 Rl(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 Tr=112,Ol=18;function Na(r,t,e){let n=ze(r),o=n+ze(t),s=new Uint8Array(o+e.byteLength);return Me(r,s,0),Me(t,s,n),s.set(e,o),s}var Fl=Symbol.for("@ipld/js-cid/CID");var jo={};V(jo,{identity:()=>Bt});var Ua=0,kl="identity",Ma=qt;function Pl(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 qe(Ua,Ma(r))}var Bt={code:Ua,name:kl,encode:Ma,digest:Pl};function xt(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 Nl(r){return r.buffer instanceof ArrayBuffer}function Vt(r){return Nl(r)?r:r.slice()}async function za(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,Vt(t),Vt(e.subarray()));return n?.signal?.throwIfAborted(),s}function Ht(r=0){return new Uint8Array(r)}function Dr(r=0){return new Uint8Array(r)}function Go(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=Dr(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function Ka(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Va=Symbol.for("@achingbrain/uint8arraylist");function qa(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 Bn(r){return!!r?.[Va]}var ot=class r{bufs;length;[Va]=!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(Bn(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(Bn(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=qa(this.bufs,t);return e.buf[e.index]}set(t,e){let n=qa(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(Bn(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 Go(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Go(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(!Bn(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=Dr(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=Ht(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=Ht(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=Ht(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=Dr(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=Ht(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=Ht(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=Ht(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=Ht(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=Ht(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(!Ka(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 Zo={};V(Zo,{base10:()=>Ul});var Ul=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Yo={};V(Yo,{base16:()=>Ml,base16upper:()=>zl});var Ml=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),zl=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xo={};V(Xo,{base2:()=>Kl});var Kl=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Wo={};V(Wo,{base256emoji:()=>jl});var Ha=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}"),ql=Ha.reduce((r,t,e)=>(r[e]=t,r),[]),Vl=Ha.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Hl(r){return r.reduce((t,e)=>(t+=ql[e],t),"")}function $l(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Vl[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var jl=Ue({prefix:"\u{1F680}",name:"base256emoji",encode:Hl,decode:$l});var Jo={};V(Jo,{base64:()=>Gl,base64pad:()=>Zl,base64url:()=>Qo,base64urlpad:()=>Yl});var Gl=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zl=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qo=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yl=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ts={};V(ts,{base8:()=>Xl});var Xl=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var es={};V(es,{identity:()=>Wl});var Wl=Ue({prefix:"\0",name:"identity",encode:r=>Ba(r),decode:r=>Ia(r)});var Mg=new TextEncoder,zg=new TextDecoder;var os={};V(os,{sha256:()=>Cr,sha512:()=>ed});var td=20;function ns({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new rs(r,t,e,n,o)}var rs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??td,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?$a(n,this.code,e?.truncate):n.then(o=>$a(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function $a(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 qe(t,r)}function Ga(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Cr=ns({name:"sha2-256",code:18,encode:Ga("SHA-256")}),ed=ns({name:"sha2-512",code:19,encode:Ga("SHA-512")});var Lr={...es,...Xo,...ts,...Zo,...Yo,...qo,...Vo,...Ko,...Jo,...Wo},Qg={...os,...jo};function Rr(r=0){return new Uint8Array(r)}function be(r=0){return new Uint8Array(r)}function Ya(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Za=Ya("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ss=Ya("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=be(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),rd={utf8:Za,"utf-8":Za,hex:Lr.base16,latin1:ss,ascii:ss,binary:ss,...Lr},Tn=rd;function G(r,t="utf8"){let e=Tn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function J(r,t="utf8"){let e=Tn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var nd=parseInt("11111",2),is=parseInt("10000000",2),od=parseInt("01111111",2),Xa={0:Or,1:Or,2:sd,3:cd,4:ud,5:ad,6:id,16:Or,22:Or,48:Or};function as(r,t={offset:0}){let e=r[t.offset]&nd;if(t.offset++,Xa[e]!=null)return Xa[e](r,t);throw new Error("No decoder for tag "+e)}function Fr(r,t){let e=0;if((r[t.offset]&is)===is){let n=r[t.offset]&od,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Or(r,t){Fr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=as(r,t);if(n===null)break;e.push(n)}return e}function sd(r,t){let e=Fr(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 id(r,t){let e=Fr(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 ad(r,t){return t.offset++,null}function cd(r,t){let e=Fr(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 ud(r,t){let e=Fr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function fd(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ot;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function cs(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=fd(r.byteLength);return new ot(Uint8Array.from([t.byteLength|is]),t)}function Wa(r){let t=new ot,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ot(Uint8Array.from([2]),cs(t),t)}function Qa(r){let t=Uint8Array.from([0]),e=new ot(t,r);return new ot(Uint8Array.from([3]),cs(e),e)}function Dn(r,t=48){let e=new ot;for(let n of r)e.append(n);return new ot(Uint8Array.from([t]),cs(e),e)}var ld=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),dd=Uint8Array.from([6,5,43,129,4,0,34]),hd=Uint8Array.from([6,5,43,129,4,0,35]),pd={ext:!0,kty:"EC",crv:"P-256"},md={ext:!0,kty:"EC",crv:"P-384"},gd={ext:!0,kty:"EC",crv:"P-521"},us=32,fs=48,ls=66;function Ja(r){let t=as(r);return tc(t)}function tc(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===us*2+1)return n=J(t.subarray(e,e+us),"base64url"),o=J(t.subarray(e+us),"base64url"),new Ve({...pd,key_ops:["verify"],x:n,y:o});if(t.byteLength===fs*2+1)return n=J(t.subarray(e,e+fs),"base64url"),o=J(t.subarray(e+fs),"base64url"),new Ve({...md,key_ops:["verify"],x:n,y:o});if(t.byteLength===ls*2+1)return n=J(t.subarray(e,e+ls),"base64url"),o=J(t.subarray(e+ls),"base64url"),new Ve({...gd,key_ops:["verify"],x:n,y:o});throw new mt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ec(r){return Dn([Wa(Uint8Array.from([1])),Dn([yd(r.crv)],160),Dn([Qa(new ot(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function yd(r){if(r==="P-256")return ld;if(r==="P-384")return dd;if(r==="P-521")return hd;throw new mt(`Invalid curve ${r}`)}var Ve=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ec(this.jwk)),this._raw}toMultihash(){return Bt.digest(He(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}async verify(t,e,n){return za(this.jwk,e,t,n)}};function ds(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function ee(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 wt(r,t,e=""){let n=ds(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(ee(r.outputLen),ee(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function $e(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 Ln(r,t){wt(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 jt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Rn(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Tt(r,t){return r<<32-t|r>>>t}var nc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",bd=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function On(r){if(wt(r),nc)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=bd[r[e]];return t}var $t={_0:48,_9:57,A:65,F:70,a:97,f:102};function rc(r){if(r>=$t._0&&r<=$t._9)return r-$t._0;if(r>=$t.A&&r<=$t.F)return r-($t.A-10);if(r>=$t.a&&r<=$t.f)return r-($t.a-10)}function kr(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(nc)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=rc(r.charCodeAt(s)),a=rc(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 hs(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];wt(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 ps(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 oc(r=32){ee(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 ms=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function sc(r,t,e){return r&t^~r&e}function ic(r,t,e){return r&t^r&e^t&e}var Pr=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=Rn(this.buffer)}update(t){$e(this),wt(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=Rn(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){$e(this),Ln(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,jt(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=Rn(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()}},Gt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Fn=BigInt(4294967295),ac=BigInt(32);function xd(r,t=!1){return t?{h:Number(r&Fn),l:Number(r>>ac&Fn)}:{h:Number(r>>ac&Fn)|0,l:Number(r&Fn)|0}}function cc(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}=xd(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var gs=(r,t,e)=>r>>>e,ys=(r,t,e)=>r<<32-e|t>>>e,xe=(r,t,e)=>r>>>e|t<<32-e,we=(r,t,e)=>r<<32-e|t>>>e,Nr=(r,t,e)=>r<<64-e|t>>>e-32,Ur=(r,t,e)=>r>>>e-32|t<<64-e;function kt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var uc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),fc=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,lc=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),dc=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,hc=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),pc=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Ed=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]),re=new Uint32Array(64),bs=class extends Pr{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)re[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=re[l-15],p=re[l-2],m=Tt(d,7)^Tt(d,18)^d>>>3,b=Tt(p,17)^Tt(p,19)^p>>>10;re[l]=b+re[l-7]+m+re[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=Tt(a,6)^Tt(a,11)^Tt(a,25),p=f+d+sc(a,c,u)+Ed[l]+re[l]|0,b=(Tt(n,2)^Tt(n,13)^Tt(n,22))+ic(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){jt(re)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),jt(this.buffer)}},xs=class extends bs{A=Gt[0]|0;B=Gt[1]|0;C=Gt[2]|0;D=Gt[3]|0;E=Gt[4]|0;F=Gt[5]|0;G=Gt[6]|0;H=Gt[7]|0;constructor(){super(32)}};var mc=cc(["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))),Sd=mc[0],vd=mc[1],ne=new Uint32Array(80),oe=new Uint32Array(80),ws=class extends Pr{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:m,Hh:b,Hl:h}=this;return[t,e,n,o,s,i,a,c,u,f,l,d,p,m,b,h]}set(t,e,n,o,s,i,a,c,u,f,l,d,p,m,b,h){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=m|0,this.Hh=b|0,this.Hl=h|0}process(t,e){for(let v=0;v<16;v++,e+=4)ne[v]=t.getUint32(e),oe[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let T=ne[v-15]|0,B=oe[v-15]|0,O=xe(T,B,1)^xe(T,B,8)^gs(T,B,7),L=we(T,B,1)^we(T,B,8)^ys(T,B,7),I=ne[v-2]|0,k=oe[v-2]|0,q=xe(I,k,19)^Nr(I,k,61)^gs(I,k,6),P=we(I,k,19)^Ur(I,k,61)^ys(I,k,6),g=lc(L,P,oe[v-7],oe[v-16]),x=dc(g,O,q,ne[v-7],ne[v-16]);ne[v]=x|0,oe[v]=g|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:m,Gh:b,Gl:h,Hh:y,Hl:E}=this;for(let v=0;v<80;v++){let T=xe(l,d,14)^xe(l,d,18)^Nr(l,d,41),B=we(l,d,14)^we(l,d,18)^Ur(l,d,41),O=l&p^~l&b,L=d&m^~d&h,I=hc(E,B,L,vd[v],oe[v]),k=pc(I,y,T,O,Sd[v],ne[v]),q=I|0,P=xe(n,o,28)^Nr(n,o,34)^Nr(n,o,39),g=we(n,o,28)^Ur(n,o,34)^Ur(n,o,39),x=n&s^n&a^s&a,_=o&i^o&c^i&c;y=b|0,E=h|0,b=p|0,h=m|0,p=l|0,m=d|0,{h:l,l:d}=kt(u|0,f|0,k|0,q|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let S=uc(q,g,_);n=fc(S,k,P,x),o=S|0}({h:n,l:o}=kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=kt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=kt(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:m}=kt(this.Fh|0,this.Fl|0,p|0,m|0),{h:b,l:h}=kt(this.Gh|0,this.Gl|0,b|0,h|0),{h:y,l:E}=kt(this.Hh|0,this.Hl|0,y|0,E|0),this.set(n,o,s,i,a,c,u,f,l,d,p,m,b,h,y,E)}roundClean(){jt(ne,oe)}destroy(){this.destroyed=!0,jt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Es=class extends ws{Ah=at[0]|0;Al=at[1]|0;Bh=at[2]|0;Bl=at[3]|0;Ch=at[4]|0;Cl=at[5]|0;Dh=at[6]|0;Dl=at[7]|0;Eh=at[8]|0;El=at[9]|0;Fh=at[10]|0;Fl=at[11]|0;Gh=at[12]|0;Gl=at[13]|0;Hh=at[14]|0;Hl=at[15]|0;constructor(){super(64)}};var gc=ps(()=>new xs,ms(1));var kn=ps(()=>new Es,ms(3));var M=(r,t,e)=>wt(r,t,e),vs=ee,je=On,et=(...r)=>hs(...r),Ge=r=>kr(r),Ee=ds,Mr=r=>oc(r),Nn=BigInt(0),Ss=BigInt(1);function Dt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function Un(r){if(typeof r=="bigint"){if(!Pn(r))throw new RangeError("positive bigint expected, got "+r)}else vs(r);return r}function Ct(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 zr(r){let t=Un(r).toString(16);return t.length&1?"0"+t:t}function yc(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?Nn:BigInt("0x"+r)}function Se(r){return yc(On(r))}function Pt(r){return yc(On(Kr(wt(r)).reverse()))}function Mn(r,t){if(ee(t),t===0)throw new RangeError("zero length");r=Un(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return kr(e.padStart(t*2,"0"))}function _s(r,t){return Mn(r,t).reverse()}function bc(r,t){if(r=M(r),t=M(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 Kr(r){return Uint8Array.from(M(r))}function zn(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"&&Nn<=r;function _d(r,t,e){return Pn(r)&&Pn(t)&&Pn(e)&&t<=r&&r<e}function Ze(r,t,e,n){if(!_d(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Ye(r){if(r<Nn)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>Nn;r>>=Ss,t+=1);return t}var qr=r=>(Ss<<BigInt(r))-Ss;function xc(r,t,e){if(ee(r,"hashLen"),ee(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=h=>new Uint8Array(h),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=(...h)=>e(u,et(c,...h)),p=(h=o)=>{u=d(s,h),c=d(),h.length!==0&&(u=d(i,h),c=d())},m=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let h=0,y=[];for(;h<t;){c=d();let E=c.slice();y.push(E),h+=c.length}return et(...y)};return(h,y)=>{l(),p(h);let E;for(;(E=y(m()))===void 0;)p();return l(),E}}function Lt(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 As=()=>{throw new Error("not implemented")};var ct=BigInt(0),Z=BigInt(1),ve=BigInt(2),vc=BigInt(3),_c=BigInt(4),Ac=BigInt(5),Ad=BigInt(7),Ic=BigInt(8),Id=BigInt(9),Bc=BigInt(16);function Q(r,t){if(t<=ct)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=ct?e:t+e}function H(r,t,e){if(t<ct)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >ct;)n*=n,n%=e;return n}function wc(r,t){if(r===ct)throw new Error("invert: expected non-zero number");if(t<=ct)throw new Error("invert: expected positive modulus, got "+t);let e=Q(r,t),n=t,o=ct,s=Z,i=Z,a=ct;for(;e!==ct;){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!==Z)throw new Error("invert: does not exist");return Q(o,t)}function Is(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Tc(r,t){let e=r,n=(e.ORDER+Z)/_c,o=e.pow(t,n);return Is(e,o,t),o}function Bd(r,t){let e=r,n=(e.ORDER-Ac)/Ic,o=e.mul(t,ve),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,ve),s),c=e.mul(i,e.sub(a,e.ONE));return Is(e,c,t),c}function Td(r){let t=Xe(r),e=Dc(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Ad)/Bc;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),m=u.eql(u.sqr(l),c),b=u.eql(u.sqr(d),c);f=u.cmov(f,l,m),l=u.cmov(p,d,b);let h=u.eql(u.sqr(l),c),y=u.cmov(f,l,h);return Is(u,y,c),y})}function Dc(r){if(r<vc)throw new Error("sqrt is not defined for small field");let t=r-Z,e=0;for(;t%ve===ct;)t/=ve,e++;let n=ve,o=Xe(r);for(;Ec(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Tc;let s=o.pow(n,t),i=(t+Z)/ve;return function(c,u){let f=c;if(f.is0(u))return u;if(Ec(f,u)!==1)throw new Error("Cannot find square root");let l=e,d=f.mul(f.ONE,s),p=f.pow(u,t),m=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))return f.ZERO;let b=1,h=f.sqr(p);for(;!f.eql(h,f.ONE);)if(b++,h=f.sqr(h),b===l)throw new Error("Cannot find square root");let y=Z<<BigInt(l-b-1),E=f.pow(d,y);l=b,d=f.sqr(E),p=f.mul(p,d),m=f.mul(m,E)}return m}}function Dd(r){return r%_c===vc?Tc:r%Ic===Ac?Bd:r%Bc===Id?Td(r):Dc(r)}var Zt=(r,t)=>(Q(r,t)&Z)===Z,Cd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Bs(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Cd.reduce((n,o)=>(n[o]="function",n),t);if(Lt(r,e),Ct(r.BYTES,"BYTES"),Ct(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=Z)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function Ld(r,t,e){let n=r;if(e<ct)throw new Error("invalid exponent, negatives unsupported");if(e===ct)return n.ONE;if(e===Z)return t;let o=n.ONE,s=t;for(;e>ct;)e&Z&&(o=n.mul(o,s)),s=n.sqr(s),e>>=Z;return o}function Vr(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 Ec(r,t){let e=r,n=(e.ORDER-Z)/ve,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 Rd(r,t){if(t!==void 0&&vs(t),r<=ct)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=Ye(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 Sc=new WeakMap,Kn=class{ORDER;BITS;BYTES;isLE;ZERO=ct;ONE=Z;_lengths;_mod;constructor(t,e={}){if(t<=Z)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}=Rd(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 Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ct<=t&&t<this.ORDER}is0(t){return t===ct}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&Z)===Z}neg(t){return Q(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Q(t*t,this.ORDER)}add(t,e){return Q(t+e,this.ORDER)}sub(t,e){return Q(t-e,this.ORDER)}mul(t,e){return Q(t*e,this.ORDER)}pow(t,e){return Ld(this,t,e)}div(t,e){return Q(t*wc(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 wc(t,this.ORDER)}sqrt(t){let e=Sc.get(this);return e||Sc.set(this,e=Dd(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?_s(t,this.BYTES):Mn(t,this.BYTES)}fromBytes(t,e=!1){M(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?Pt(t):Se(t);if(a&&(c=Q(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Vr(this,t)}cmov(t,e,n){return Dt(n,"condition"),n?e:t}};Object.freeze(Kn.prototype);function Xe(r,t={}){return new Kn(r,t)}function Cc(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=Z)throw new Error("field order must be greater than 1");let t=Ye(r-Z);return Math.ceil(t/8)}function Ts(r){let t=Cc(r);return t+Math.ceil(t/2)}function Ds(r,t,e=!1){M(r);let n=r.length,o=Cc(t),s=Math.max(Ts(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Pt(r):Se(r),a=Q(i,t-Z)+Z;return e?_s(a,o):Mn(a,o)}var We=BigInt(0),_e=BigInt(1);function Hr(r,t){let e=t.negate();return r?e:t}function Ae(r,t){let e=Vr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Fc(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Cs(r,t){Fc(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=qr(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Lc(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+=_e);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 Ls=new WeakMap,kc=new WeakMap;function Rs(r){return kc.get(r)||1}function Rc(r){if(r!==We)throw new Error("invalid wNAF")}var Qe=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>We;)e&_e&&(n=n.add(o)),o=o.double(),e>>=_e;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Cs(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=Cs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:p}=Lc(n,a,i);n=c,f?s=s.add(Hr(d,e[p])):o=o.add(Hr(l,e[u]))}return Rc(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Cs(t,this.bits);for(let i=0;i<s.windows&&n!==We;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Lc(n,i,s);if(n=a,!u){let l=e[c];o=o.add(f?l.negate():l)}}return Rc(n),o}getPrecomputes(t,e,n){let o=Ls.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Ls.set(e,o))),o}cached(t,e,n){let o=Rs(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Rs(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Fc(e,this.bits),kc.set(t,e),Ls.delete(t)}hasCache(t){return Rs(t)!==1}};function Pc(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>We||n>We;)e&_e&&(s=s.add(o)),n&_e&&(i=i.add(o)),o=o.double(),e>>=_e,n>>=_e;return{p1:s,p2:i}}function Oc(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Bs(t),t}else return Xe(r,{isLE:e})}function qn(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>We))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Oc(t.p,e.Fp,n),s=Oc(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 Vn(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var se=BigInt(0),st=BigInt(1),Os=BigInt(2),Od=BigInt(8);function Fd(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 Nc(r,t={}){let e=t,n=qn("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Lt(e,{},{uvRatio:"function"});let c=Os<<BigInt(s.BYTES*8)-st,u=b=>o.create(b),f=e.uvRatio===void 0?(b,h)=>{try{return{isValid:!0,value:o.sqrt(o.div(b,h))}}catch{return{isValid:!1,value:se}}}:e.uvRatio;if(!Fd(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(b,h,y=!1){let E=y?st:se;return Ze("coordinate "+b,h,E,c),h}function d(b){if(!(b instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,st,u(i.Gx*i.Gy));static ZERO=new p(se,st,st,se);static Fp=o;static Fn=s;X;Y;Z;T;constructor(h,y,E,v){this.X=l("x",h),this.Y=l("y",y),this.Z=l("z",E,!0),this.T=l("t",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(h){if(h instanceof p)throw new Error("extended point not allowed");let{x:y,y:E}=h||{};return l("x",y),l("y",E),new p(y,E,st,u(y*E))}static fromBytes(h,y=!1){let E=o.BYTES,{a:v,d:T}=i;h=Kr(M(h,E,"point")),Dt(y,"zip215");let B=Kr(h),O=h[E-1];B[E-1]=O&-129;let L=Pt(B),I=y?c:o.ORDER;Ze("point.y",L,se,I);let k=u(L*L),q=u(k-st),P=u(T*k-v),{isValid:g,value:x}=f(q,P);if(!g)throw new Error("bad point: invalid y coordinate");let _=(x&st)===st,S=(O&128)!==0;if(!y&&x===se&&S)throw new Error("bad point: x=0 and x_0=1");return S!==_&&(x=u(-x)),p.fromAffine({x,y:L})}static fromHex(h,y=!1){return p.fromBytes(Ge(h),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,y=!0){return m.createCache(this,h),y||this.multiply(Os),this}assertValidity(){let h=this,{a:y,d:E}=i;if(h.is0())throw new Error("bad point: ZERO");let{X:v,Y:T,Z:B,T:O}=h,L=u(v*v),I=u(T*T),k=u(B*B),q=u(k*k),P=u(L*y),g=u(k*u(P+I)),x=u(q+u(E*u(L*I)));if(g!==x)throw new Error("bad point: equation left != right (1)");let _=u(v*T),S=u(B*O);if(_!==S)throw new Error("bad point: equation left != right (2)")}equals(h){d(h);let{X:y,Y:E,Z:v}=this,{X:T,Y:B,Z:O}=h,L=u(y*O),I=u(T*v),k=u(E*O),q=u(B*v);return L===I&&k===q}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:h}=i,{X:y,Y:E,Z:v}=this,T=u(y*y),B=u(E*E),O=u(Os*u(v*v)),L=u(h*T),I=y+E,k=u(u(I*I)-T-B),q=L+B,P=q-O,g=L-B,x=u(k*P),_=u(q*g),S=u(k*g),w=u(P*q);return new p(x,_,w,S)}add(h){d(h);let{a:y,d:E}=i,{X:v,Y:T,Z:B,T:O}=this,{X:L,Y:I,Z:k,T:q}=h,P=u(v*L),g=u(T*I),x=u(O*E*q),_=u(B*k),S=u((v+T)*(L+I)-P-g),w=_-x,A=_+x,C=u(g-y*P),D=u(S*w),R=u(A*C),F=u(S*C),U=u(w*A);return new p(D,R,U,F)}subtract(h){return d(h),this.add(h.negate())}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:E}=m.cached(this,h,v=>Ae(p,v));return Ae(p,[y,E])[0]}multiplyUnsafe(h){if(!s.isValid(h))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return h===se?p.ZERO:this.is0()||h===st?this:m.unsafe(this,h,y=>Ae(p,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(h){let y=this,E=h,{X:v,Y:T,Z:B}=y,O=y.is0();E==null&&(E=O?Od:o.inv(B));let L=u(v*E),I=u(T*E),k=o.mul(B,E);if(O)return{x:se,y:st};if(k!==st)throw new Error("invZ was invalid");return{x:L,y:I}}clearCofactor(){return a===st?this:this.multiplyUnsafe(a)}toBytes(){let{x:h,y}=this.toAffine(),E=o.toBytes(y);return E[E.length-1]|=h&st?128:0,E}toHex(){return je(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=new Qe(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Hn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){As()}static fromHex(t){As()}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 je(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 Uc(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;Lt(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&&(Ct(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Mr:o.randomBytes,d=o.adjustScalarBytes===void 0?g=>g:o.adjustScalarBytes,p=o.domain===void 0?(g,x,_)=>{if(Dt(_,"phflag"),x.length||_)throw new Error("Contexts/pre-hash are not supported");return g}:o.domain;function m(g){return c.create(Pt(g))}function b(g){let x=L.secretKey;M(g,L.secretKey,"secretKey");let _=M(n(g),2*x,"hashedSecretKey"),S=d(_.slice(0,x)),w=_.slice(x,2*x),A=m(S);return{head:S,prefix:w,scalar:A}}function h(g){let{head:x,prefix:_,scalar:S}=b(g),w=i.multiply(S),A=w.toBytes();return{head:x,prefix:_,scalar:S,point:w,pointBytes:A}}function y(g){return h(g).pointBytes}function E(g=Uint8Array.of(),...x){let _=et(...x);return m(n(p(_,M(g,void 0,"context"),!!s)))}function v(g,x,_={}){g=M(g,void 0,"message"),s&&(g=s(g));let{prefix:S,scalar:w,pointBytes:A}=h(x),C=E(_.context,S,g),D=i.multiply(C).toBytes(),R=E(_.context,D,A,g),F=c.create(C+R*w);if(!c.isValid(F))throw new Error("sign failed: invalid s");let U=et(D,c.toBytes(F));return M(U,L.signature,"result")}let T={zip215:o.zip215};function B(g,x,_,S=T){let{context:w}=S,A=S.zip215===void 0?!!T.zip215:S.zip215,C=L.signature;g=M(g,C,"signature"),x=M(x,void 0,"message"),_=M(_,L.publicKey,"publicKey"),A!==void 0&&Dt(A,"zip215"),s&&(x=s(x));let D=C/2,R=g.subarray(0,D),F=Pt(g.subarray(D,C)),U,z,N;try{U=r.fromBytes(_,A),z=r.fromBytes(R,A),N=i.multiplyUnsafe(F)}catch{return!1}if(!A&&U.isSmallOrder())return!1;let tt=E(w,R,_,x);return z.add(U.multiplyUnsafe(tt)).subtract(N).clearCofactor().is0()}let O=a.BYTES,L={secretKey:O,publicKey:O,signature:2*O,seed:O};function I(g){return g=g===void 0?l(L.seed):g,M(g,L.seed,"seed")}function k(g){return Ee(g)&&g.length===L.secretKey}function q(g,x){try{return!!r.fromBytes(g,x===void 0?T.zip215:x)}catch{return!1}}let P={getExtendedPublicKey:h,randomSecretKey:I,isValidSecretKey:k,isValidPublicKey:q,toMontgomery(g){let{y:x}=r.fromBytes(g),_=L.publicKey,S=_===32;if(!S&&_!==57)throw new Error("only defined for 25519 and 448");let w=S?a.div(st+x,st-x):a.div(x-st,x+st);return a.toBytes(w)},toMontgomerySecret(g){let x=L.secretKey;M(g,x);let _=n(g.subarray(0,x));return d(_).subarray(0,x)}};return Object.freeze(L),Object.freeze(P),Object.freeze({keygen:Vn(I,y),getPublicKey:y,sign:v,verify:B,utils:P,Point:r,lengths:L})}function $r(r,t){if(Ct(r),Ct(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 kd(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 Pd(r){if(!Ee(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?zn(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function Fs(r,t,e,n){M(r),Ct(e),t=Pd(t),t.length>255&&(t=n(et(zn("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=et(t,$r(t.length,1)),c=new Uint8Array(s),u=$r(e,2),f=new Array(i),l=n(et(c,r,u,$r(0,1),a));f[0]=n(et(l,$r(1,1),a));for(let p=1;p<i;p++){let m=[kd(l,f[p-1]),$r(p+1,1),a];f[p]=n(et(...m))}return et(...f).slice(0,e)}var Mc="HashToScalar-";var Nd=BigInt(0),Yt=BigInt(1),zc=BigInt(2);var Ud=BigInt(5),Md=BigInt(8),Je=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Us={p:Je,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Md,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function zd(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,zc,s)*a%s,u=H(c,Yt,s)*r%s,f=H(u,Ud,s)*u%s,l=H(f,t,s)*f%s,d=H(l,e,s)*l%s,p=H(d,n,s)*d%s,m=H(p,o,s)*p%s,b=H(m,o,s)*p%s,h=H(b,t,s)*f%s;return{pow_p_5_8:H(h,zc,s)*r%s,b2:a}}function Kd(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ks=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ms(r,t){let e=Je,n=Q(t*t*t,e),o=Q(n*n*t,e),s=zd(r*o).pow_p_5_8,i=Q(r*n*s,e),a=Q(t*i*i,e),c=i,u=Q(i*ks,e),f=a===r,l=a===Q(-r,e),d=a===Q(-r*ks,e);return f&&(i=c),(l||d)&&(i=u),Zt(i,e)&&(i=Q(-i,e)),{isValid:f||l,value:i}}var ae=Nc(Us,{uvRatio:Ms}),ie=ae.Fp,Vc=ae.Fn;function qd(r){return Uc(ae,kn,Object.assign({adjustScalarBytes:Kd,zip215:!0},r))}var Hc=qd({});var Ps=ks,Vd=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Hd=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),$d=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),jd=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Kc=r=>Ms(Yt,r),Gd=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ns=r=>ie.create(Pt(r)&Gd);function qc(r){let{d:t}=Us,e=Je,n=y=>ie.create(y),o=n(Ps*r*r),s=n((o+Yt)*$d),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=Ms(s,a),f=n(u*r);Zt(f,e)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-Yt)*jd-a),d=u*u,p=n((u+u)*a),m=n(l*Vd),b=n(Yt-d),h=n(Yt+d);return new ae(n(p*h),n(b*m),n(m*h),n(p*b))}var ce=class r extends Hn{static BASE=new r(ae.BASE);static ZERO=new r(ae.ZERO);static Fp=ie;static Fn=Vc;constructor(t){super(t)}static fromAffine(t){return new r(ae.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){wt(t,32);let{a:e,d:n}=Us,o=Je,s=T=>ie.create(T),i=Ns(t);if(!bc(ie.toBytes(i),t)||Zt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Yt+e*a),u=s(Yt-e*a),f=s(c*c),l=s(u*u),d=s(e*n*f-l),{isValid:p,value:m}=Kc(s(d*l)),b=s(m*u),h=s(m*b*d),y=s((i+i)*b);Zt(y,o)&&(y=s(-y));let E=s(c*h),v=s(y*E);if(!p||Zt(v,o)||E===Nd)throw new Error("invalid ristretto255 encoding 2");return new r(new ae(y,E,Yt,v))}static fromHex(t){return r.fromBytes(kr(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=Je,i=h=>ie.create(h),a=i(i(n+e)*i(n-e)),c=i(t*e),u=i(c*c),{value:f}=Kc(i(a*u)),l=i(f*a),d=i(f*c),p=i(l*d*o),m;if(Zt(o*p,s)){let h=i(e*Ps),y=i(t*Ps);t=h,e=y,m=i(l*Hd)}else m=d;Zt(t*p,s)&&(e=i(-e));let b=i((n-e)*m);return Zt(b,s)&&(b=i(-b)),ie.toBytes(b)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ie.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(ce.BASE);Object.freeze(ce.ZERO);Object.freeze(ce.prototype);Object.freeze(ce);var Zd=Object.freeze({Point:ce,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Fs(r,e,64,kn);return Zd.deriveToCurve(n)},hashToScalar(r,t={DST:Mc}){let e=Fs(r,t.DST,64,kn);return Vc.create(Pt(e))},deriveToCurve(r){wt(r,64);let t=Ns(r.subarray(0,32)),e=qc(t),n=Ns(r.subarray(32,64)),o=qc(n);return new ce(e.add(o))}});var jr=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 jn={get(r=globalThis){let t=r.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 Gn=32;var zs,Yd=(async()=>{try{return await jn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Xd(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await jn.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await jn.get().subtle.verify({name:"Ed25519"},n,Vt(t),Vt(e instanceof Uint8Array?e:e.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Wd(r,t,e){return Hc.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function $c(r,t,e){return zs==null&&(zs=await Yd),zs?Xd(r,t,e):Wd(r,t,e)}function Qd(r){return r?.buffer instanceof ArrayBuffer}function Ks(r){if(Qd(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ie(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=be(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return Ks(e)}function Zn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Yn=class{type="Ed25519";raw;constructor(t){this.raw=qs(t,Gn)}toMultihash(){return Bt.digest(He(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=$c(this.raw,e,t);return Zn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Gc(r){return r=qs(r,Gn),new Yn(r)}function qs(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new mt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function ue(r=0){return new Uint8Array(r)}var th=Math.pow(2,7),eh=Math.pow(2,14),rh=Math.pow(2,21),Zc=Math.pow(2,28),Yc=Math.pow(2,35),Xc=Math.pow(2,42),Wc=Math.pow(2,49),gt=128,fe=127;function Gr(r){if(r<th)return 1;if(r<eh)return 2;if(r<rh)return 3;if(r<Zc)return 4;if(r<Yc)return 5;if(r<Xc)return 6;if(r<Wc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qc(r,t,e=0){switch(Gr(r)){case 8:t[e++]=r&255|gt,r/=128;case 7:t[e++]=r&255|gt,r/=128;case 6:t[e++]=r&255|gt,r/=128;case 5:t[e++]=r&255|gt,r/=128;case 4:t[e++]=r&255|gt,r>>>=7;case 3:t[e++]=r&255|gt,r>>>=7;case 2:t[e++]=r&255|gt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Jc(r,t){let e=r[t],n=0;if(n+=e&fe,e<gt||(e=r[t+1],n+=(e&fe)<<7,e<gt)||(e=r[t+2],n+=(e&fe)<<14,e<gt)||(e=r[t+3],n+=(e&fe)<<21,e<gt)||(e=r[t+4],n+=(e&fe)*Zc,e<gt)||(e=r[t+5],n+=(e&fe)*Yc,e<gt)||(e=r[t+6],n+=(e&fe)*Xc,e<gt)||(e=r[t+7],n+=(e&fe)*Wc,e<gt))return n;throw new RangeError("Could not decode varint")}var Vs=new Float32Array([-0]),le=new Uint8Array(Vs.buffer);function tu(r,t,e){Vs[0]=r,t[e]=le[0],t[e+1]=le[1],t[e+2]=le[2],t[e+3]=le[3]}function eu(r,t){return le[0]=r[t],le[1]=r[t+1],le[2]=r[t+2],le[3]=r[t+3],Vs[0]}var Hs=new Float64Array([-0]),dt=new Uint8Array(Hs.buffer);function ru(r,t,e){Hs[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 nu(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],Hs[0]}var nh=BigInt(Number.MAX_SAFE_INTEGER),oh=BigInt(Number.MIN_SAFE_INTEGER),Et=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Be;if(t<nh&&t>oh)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>ou&&(o=0n,++n>ou&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Be;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):Be}},Be=new Et(0,0);Be.toBigInt=function(){return 0n};Be.zzEncode=Be.zzDecode=function(){return this};Be.length=function(){return 1};var ou=4294967296n;function su(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 iu(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 $s(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Rt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Xn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var js=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Rt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Rt(this,4);return Xn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return Xn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=eu(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=nu(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Rt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return iu(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Rt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Rt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Rt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Rt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Rt(this,8);let t=Xn(this.buf,this.pos+=4),e=Xn(this.buf,this.pos+=4);return new Et(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Jc(this.buf,this.pos);return this.pos+=Gr(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 Zr(r){return new js(r instanceof Uint8Array?r:r.subarray())}function vt(r,t,e){let n=Zr(r);return t.decode(n,void 0,e)}var Ws={};V(Ws,{base10:()=>lh});var Hb=new Uint8Array(0);function cu(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 Xt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function uu(r){return new TextEncoder().encode(r)}function fu(r){return new TextDecoder().decode(r)}function sh(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var b=0,h=0,y=0,E=m.length;y!==E&&m[y]===0;)y++,b++;for(var v=(E-y)*f+1>>>0,T=new Uint8Array(v);y!==E;){for(var B=m[y],O=0,L=v-1;(B!==0||O<h)&&L!==-1;L--,O++)B+=256*T[L]>>>0,T[L]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");h=O,y++}for(var I=v-h;I!==v&&T[I]===0;)I++;for(var k=c.repeat(b);I<v;++I)k+=r.charAt(T[I]);return k}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var h=0,y=0;m[b]===c;)h++,b++;for(var E=(m.length-b)*u+1>>>0,v=new Uint8Array(E);m[b];){var T=e[m.charCodeAt(b)];if(T===255)return;for(var B=0,O=E-1;(T!==0||B<y)&&O!==-1;O--,B++)T+=a*v[O]>>>0,v[O]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");y=B,b++}if(m[b]!==" "){for(var L=E-y;L!==E&&v[L]===0;)L++;for(var I=new Uint8Array(h+(E-L)),k=h;L!==E;)I[k++]=v[L++];return I}}}function p(m){var b=d(m);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:p}}var ih=sh,ah=ih,du=ah;var Gs=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")}},Zs=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 hu(this,t)}},Ys=class{decoders;constructor(t){this.decoders=t}or(t){return hu(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 hu(r,t){return new Ys({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Xs=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 Gs(t,e,n),this.decoder=new Zs(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function tr({name:r,prefix:t,encode:e,decode:n}){return new Xs(r,t,e,n)}function de({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=du(e,r);return tr({prefix:t,name:r,encode:n,decode:s=>Xt(o(s))})}function ch(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 uh(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 fh(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=fh(n);return tr({prefix:t,name:r,encode(s){return uh(s,n,e)},decode(s){return ch(s,o,e,r)}})}var lh=de({prefix:"9",name:"base10",alphabet:"0123456789"});var Qs={};V(Qs,{base16:()=>dh,base16upper:()=>hh});var dh=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),hh=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Js={};V(Js,{base2:()=>ph});var ph=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ti={};V(ti,{base256emoji:()=>xh});var pu=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}"),mh=pu.reduce((r,t,e)=>(r[e]=t,r),[]),gh=pu.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function yh(r){return r.reduce((t,e)=>(t+=mh[e],t),"")}function bh(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=gh[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var xh=tr({prefix:"\u{1F680}",name:"base256emoji",encode:yh,decode:bh});var ei={};V(ei,{base32:()=>er,base32hex:()=>vh,base32hexpad:()=>Ah,base32hexpadupper:()=>Ih,base32hexupper:()=>_h,base32pad:()=>Eh,base32padupper:()=>Sh,base32upper:()=>wh,base32z:()=>Bh});var er=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),wh=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Eh=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Sh=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),vh=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_h=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ah=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ih=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Bh=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ri={};V(ri,{base36:()=>Yr,base36upper:()=>Th});var Yr=de({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Th=de({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ni={};V(ni,{base58btc:()=>Nt,base58flickr:()=>Dh});var Nt=de({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Dh=de({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var oi={};V(oi,{base64:()=>Ch,base64pad:()=>Lh,base64url:()=>Rh,base64urlpad:()=>Oh});var Ch=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Lh=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Rh=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Oh=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var si={};V(si,{base8:()=>Fh});var Fh=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ii={};V(ii,{identity:()=>kh});var kh=tr({prefix:"\0",name:"identity",encode:r=>fu(r),decode:r=>uu(r)});var ix=new TextEncoder,ax=new TextDecoder;var ci={};V(ci,{identity:()=>op});var Uh=yu,mu=128,Mh=127,zh=~Mh,Kh=Math.pow(2,31);function yu(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Kh;)t[e++]=r&255|mu,r/=128;for(;r&zh;)t[e++]=r&255|mu,r>>>=7;return t[e]=r|0,yu.bytes=e-n+1,t}var qh=ai,Vh=128,gu=127;function ai(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw ai.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&gu)<<o:(i&gu)*Math.pow(2,o),o+=7}while(i>=Vh);return ai.bytes=s-n,e}var Hh=Math.pow(2,7),$h=Math.pow(2,14),jh=Math.pow(2,21),Gh=Math.pow(2,28),Zh=Math.pow(2,35),Yh=Math.pow(2,42),Xh=Math.pow(2,49),Wh=Math.pow(2,56),Qh=Math.pow(2,63),Jh=function(r){return r<Hh?1:r<$h?2:r<jh?3:r<Gh?4:r<Zh?5:r<Yh?6:r<Xh?7:r<Wh?8:r<Qh?9:10},tp={encode:Uh,decode:qh,encodingLength:Jh},ep=tp,Xr=ep;function Wr(r,t=0){return[Xr.decode(r,t),Xr.decode.bytes]}function rr(r,t,e=0){return Xr.encode(r,t,e),t}function nr(r){return Xr.encodingLength(r)}function sr(r,t){let e=t.byteLength,n=nr(r),o=n+nr(e),s=new Uint8Array(o+e);return rr(r,s,0),rr(e,s,n),s.set(t,o),new or(r,e,t,s)}function bu(r){let t=Xt(r),[e,n]=Wr(t),[o,s]=Wr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new or(e,o,i,t)}function xu(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&cu(r.bytes,e.bytes)}}var or=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var wu=0,rp="identity",Eu=Xt;function np(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 sr(wu,Eu(r))}var op={code:wu,name:rp,encode:Eu,digest:np};var li={};V(li,{sha256:()=>ip,sha512:()=>ap});var sp=20;function fi({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new ui(r,t,e,n,o)}var ui=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??sp,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?Su(n,this.code,e?.truncate):n.then(o=>Su(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Su(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 sr(t,r)}function _u(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ip=fi({name:"sha2-256",code:18,encode:_u("SHA-256")}),ap=fi({name:"sha2-512",code:19,encode:_u("SHA-512")});function Au(r,t){let{bytes:e,version:n}=r;return n===0?up(e,di(r),t??Nt.encoder):fp(e,di(r),t??er.encoder)}var Iu=new WeakMap;function di(r){let t=Iu.get(r);if(t==null){let e=new Map;return Iu.set(r,e),e}return t}var Qn=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Jr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==lp)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=sr(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&&xu(t.multihash,n.multihash)}toString(t){return Au(this,t)}toJSON(){return{"/":Au(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??Bu(n,o,s.bytes))}else if(e[dp]===!0){let{version:n,multihash:o,code:s}=e,i=bu(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!==Jr)throw new Error(`Version 0 CID must use dag-pb (code: ${Jr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Bu(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Jr,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=Xt(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 or(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]=Wr(t.subarray(e));return e+=d,l},o=n(),s=Jr;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]=cp(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 di(s).set(n,t),s}};function cp(r,t){switch(r[0]){case"Q":{let e=t??Nt;return[Nt.prefix,e.decode(`${Nt.prefix}${r}`)]}case Nt.prefix:{let e=t??Nt;return[Nt.prefix,e.decode(r)]}case er.prefix:{let e=t??er;return[er.prefix,e.decode(r)]}case Yr.prefix:{let e=t??Yr;return[Yr.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 up(r,t,e){let{prefix:n}=e;if(n!==Nt.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 fp(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 Jr=112,lp=18;function Bu(r,t,e){let n=nr(r),o=n+nr(t),s=new Uint8Array(o+e.byteLength);return rr(r,s,0),rr(t,s,n),s.set(e,o),s}var dp=Symbol.for("@ipld/js-cid/CID");var hi={...ii,...Js,...si,...Ws,...Qs,...ei,...ri,...ni,...oi,...ti},Dx={...li,...ci};function Du(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Tu=Du("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),pi=Du("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=ue(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),hp={utf8:Tu,"utf-8":Tu,hex:hi.base16,latin1:pi,ascii:pi,binary:pi,...hi},Cu=hp;function Lu(r,t="utf8"){let e=Cu[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function mi(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ue(i);o+i>t&&(n=ue(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Te=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function gi(){}var bi=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},pp=mi();function mp(r){return globalThis.Buffer!=null?ue(r):pp(r)}var en=class{len;head;tail;states;constructor(){this.len=0,this.head=new Te(gi,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Te(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new xi((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(Jn,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Jn,e.length(),e)}uint64Number(t){return this._push(Qc,Gr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Et.fromBigInt(t).zzEncode();return this._push(Jn,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Jn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(yi,1,t?1:0)}fixed32(t){return this._push(tn,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(tn,4,e.lo)._push(tn,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(tn,4,e.lo)._push(tn,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(tu,4,t)}double(t){return this._push(ru,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(yi,1,0):this.uint32(e)._push(yp,e,t)}string(t){let e=su(t);return e!==0?this.uint32(e)._push($s,e,t):this._push(yi,1,0)}fork(){return this.states=new bi(this),this.head=this.tail=new Te(gi,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 Te(gi,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=mp(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function yi(r,t,e){t[e]=r&255}function gp(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var xi=class extends Te{next;constructor(t,e){super(gp,t,e),this.next=void 0}};function Jn(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 tn(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 yp(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(en.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(bp,t,r),this},en.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(xp,t,r),this});function bp(r,t,e){t.set(r,e)}function xp(r,t,e){r.length<40?$s(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Lu(r),e)}function wi(){return new en}function _t(r,t){let e=wi();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*At(r,t,e){let n=Zr(r);yield*t.stream(n,void 0,"$",e)}var to={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function eo(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function De(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 eo("enum",to.VARINT,e,n,o)}function It(r,t,e){return eo("message",to.LENGTH_DELIMITED,r,t,e)}var rn=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var yt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(yt||(yt={}));var Ei;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Ei||(Ei={}));(function(r){r.codec=()=>De(Ei)})(yt||(yt={}));var nn;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),yt.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=yt.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:yt.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})(nn||(nn={}));var Si;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),yt.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=yt.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:yt.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})(Si||(Si={}));var ro=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(Cn(t),wt(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),jt(o)}update(t){return $e(this),this.iHash.update(t),this}digestInto(t){$e(this),Ln(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()}},Ru=(()=>{let r=((t,e,n)=>new ro(t,e).update(n).digest());return r.create=(t,e)=>new ro(t,e),r})();var Ou=(r,t)=>(r+(r>=0?t:-t)/Fu)/t;function Ep(r,t,e){Ze("scalar",r,Ut,e);let[[n,o],[s,i]]=t,a=Ou(i*r,e),c=Ou(-o*r,e),u=r-a*n-c*s,f=-a*o-c*i,l=u<Ut,d=f<Ut;l&&(u=-u),d&&(f=-f);let p=qr(Math.ceil(Ye(e)/2))+he;if(u<Ut||u>=p||f<Ut||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function _i(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function vi(r,t){Lt(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Dt(e.lowS,"lowS"),Dt(e.prehash,"prehash"),e.format!==void 0&&_i(e.format),e}var Ai=class extends Error{constructor(t=""){super(t)}},Ot={Err:Ai,_tlv:{encode:(r,t)=>{let{Err:e}=Ot;if(Ct(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=zr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?zr(o.length/2|128):"";return zr(r)+s+o+t},decode(r,t){let{Err:e}=Ot;t=M(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}=Ot;if(Un(r),r<Ut)throw new t("integer: negative integers are not allowed");let e=zr(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}=Ot;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 Se(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ot,o=M(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}=Ot,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(Ot._tlv);Object.freeze(Ot._int);Object.freeze(Ot);var Ut=BigInt(0),he=BigInt(1),Fu=BigInt(2),no=BigInt(3),Sp=BigInt(4);function ku(r,t={}){let e=qn("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;Lt(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=Nu(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(P,g,x){if(u&&g.is0())return Uint8Array.of(0);let{x:_,y:S}=g.toAffine(),w=n.toBytes(_);if(Dt(x,"isCompressed"),x){l();let A=!n.isOdd(S);return et(Pu(A),w)}else return et(Uint8Array.of(4),w,n.toBytes(S))}function p(P){M(P,void 0,"Point");let{publicKey:g,publicKeyUncompressed:x}=f,_=P.length,S=P[0],w=P.subarray(1);if(u&&_===1&&S===0)return{x:n.ZERO,y:n.ZERO};if(_===g&&(S===2||S===3)){let A=n.fromBytes(w);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let C=h(A),D;try{D=n.sqrt(C)}catch(U){let z=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}l();let R=n.isOdd(D);return(S&1)===1!==R&&(D=n.neg(D)),{x:A,y:D}}else if(_===x&&S===4){let A=n.BYTES,C=n.fromBytes(w.subarray(0,A)),D=n.fromBytes(w.subarray(A,A*2));if(!y(C,D))throw new Error("bad point: is not on curve");return{x:C,y:D}}else throw new Error(`bad point: got length ${_}, expected compressed=${g} or uncompressed=${x}`)}let m=t.toBytes===void 0?d:t.toBytes,b=t.fromBytes===void 0?p:t.fromBytes;function h(P){let g=n.sqr(P),x=n.mul(g,P);return n.add(n.add(x,n.mul(P,s.a)),s.b)}function y(P,g){let x=n.sqr(g),_=h(P);return n.eql(x,_)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let E=n.mul(n.pow(s.a,no),Sp),v=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(E,v)))throw new Error("bad curve params: a or b");function T(P,g,x=!1){if(!n.isValid(g)||x&&n.is0(g))throw new Error(`bad point coordinate ${P}`);return g}function B(P){if(!(P instanceof I))throw new Error("Weierstrass Point expected")}function O(P){if(!c||!c.basises)throw new Error("no endo");return Ep(P,c.basises,o.ORDER)}function L(P,g,x,_,S){return x=new I(n.mul(x.X,P),x.Y,x.Z),g=Hr(_,g),x=Hr(S,x),g.add(x)}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(g,x,_){this.X=T("x",g),this.Y=T("y",x,!0),this.Z=T("z",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x,y:_}=g||{};if(!g||!n.isValid(x)||!n.isValid(_))throw new Error("invalid affine point");if(g instanceof I)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(_)?I.ZERO:new I(x,_,n.ONE)}static fromBytes(g){let x=I.fromAffine(b(M(g,void 0,"point")));return x.assertValidity(),x}static fromHex(g){return I.fromBytes(Ge(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,x=!0){return q.createCache(this,g),x||this.multiply(no),this}assertValidity(){let g=this;if(g.is0()){if(t.allowInfinityPoint&&n.is0(g.X)&&n.eql(g.Y,n.ONE)&&n.is0(g.Z))return;throw new Error("bad point: ZERO")}let{x,y:_}=g.toAffine();if(!n.isValid(x)||!n.isValid(_))throw new Error("bad point: x or y not field elements");if(!y(x,_))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){B(g);let{X:x,Y:_,Z:S}=this,{X:w,Y:A,Z:C}=g,D=n.eql(n.mul(x,C),n.mul(w,S)),R=n.eql(n.mul(_,C),n.mul(A,S));return D&&R}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:x}=s,_=n.mul(x,no),{X:S,Y:w,Z:A}=this,C=n.ZERO,D=n.ZERO,R=n.ZERO,F=n.mul(S,S),U=n.mul(w,w),z=n.mul(A,A),N=n.mul(S,w);return N=n.add(N,N),R=n.mul(S,A),R=n.add(R,R),C=n.mul(g,R),D=n.mul(_,z),D=n.add(C,D),C=n.sub(U,D),D=n.add(U,D),D=n.mul(C,D),C=n.mul(N,C),R=n.mul(_,R),z=n.mul(g,z),N=n.sub(F,z),N=n.mul(g,N),N=n.add(N,R),R=n.add(F,F),F=n.add(R,F),F=n.add(F,z),F=n.mul(F,N),D=n.add(D,F),z=n.mul(w,A),z=n.add(z,z),F=n.mul(z,N),C=n.sub(C,F),R=n.mul(z,U),R=n.add(R,R),R=n.add(R,R),new I(C,D,R)}add(g){B(g);let{X:x,Y:_,Z:S}=this,{X:w,Y:A,Z:C}=g,D=n.ZERO,R=n.ZERO,F=n.ZERO,U=s.a,z=n.mul(s.b,no),N=n.mul(x,w),tt=n.mul(_,A),rt=n.mul(S,C),nt=n.add(x,_),X=n.add(w,A);nt=n.mul(nt,X),X=n.add(N,tt),nt=n.sub(nt,X),X=n.add(x,S);let bt=n.add(w,C);return X=n.mul(X,bt),bt=n.add(N,rt),X=n.sub(X,bt),bt=n.add(_,S),D=n.add(A,C),bt=n.mul(bt,D),D=n.add(tt,rt),bt=n.sub(bt,D),F=n.mul(U,X),D=n.mul(z,rt),F=n.add(D,F),D=n.sub(tt,F),F=n.add(tt,F),R=n.mul(D,F),tt=n.add(N,N),tt=n.add(tt,N),rt=n.mul(U,rt),X=n.mul(z,X),tt=n.add(tt,rt),rt=n.sub(N,rt),rt=n.mul(U,rt),X=n.add(X,rt),N=n.mul(tt,X),R=n.add(R,N),N=n.mul(bt,X),D=n.mul(nt,D),D=n.sub(D,N),N=n.mul(nt,tt),F=n.mul(bt,F),F=n.add(F,N),new I(D,R,F)}subtract(g){return B(g),this.add(g.negate())}is0(){return this.equals(I.ZERO)}multiply(g){let{endo:x}=t;if(!o.isValidNot0(g))throw new RangeError("invalid scalar: out of range");let _,S,w=A=>q.cached(this,A,C=>Ae(I,C));if(x){let{k1neg:A,k1:C,k2neg:D,k2:R}=O(g),{p:F,f:U}=w(C),{p:z,f:N}=w(R);S=U.add(N),_=L(x.beta,F,z,A,D)}else{let{p:A,f:C}=w(g);_=A,S=C}return Ae(I,[_,S])[0]}multiplyUnsafe(g){let{endo:x}=t,_=this,S=g;if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(S===Ut||_.is0())return I.ZERO;if(S===he)return _;if(q.hasCache(this))return this.multiply(S);if(x){let{k1neg:w,k1:A,k2neg:C,k2:D}=O(S),{p1:R,p2:F}=Pc(I,_,A,D);return L(x.beta,R,F,w,C)}else return q.unsafe(_,S)}toAffine(g){let x=this,_=g,{X:S,Y:w,Z:A}=x;if(n.eql(A,n.ONE))return{x:S,y:w};let C=x.is0();_==null&&(_=C?n.ONE:n.inv(A));let D=n.mul(S,_),R=n.mul(w,_),F=n.mul(A,_);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:D,y:R}}isTorsionFree(){let{isTorsionFree:g}=t;return i===he?!0:g?g(I,this):q.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===he?this:g?g(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===he?this.is0():this.clearCofactor().is0()}toBytes(g=!0){return Dt(g,"isCompressed"),this.assertValidity(),m(I,this,g)}toHex(g=!0){return je(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let k=o.BITS,q=new Qe(I,t.endo?Math.ceil(k/2):k);return k>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function Pu(r){return Uint8Array.of(r?2:3)}function Nu(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function vp(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?Mr:t.randomBytes,o=Object.assign(Nu(r.Fp,e),{seed:Math.max(Ts(e.ORDER),16)});function s(p){try{let m=e.fromBytes(p);return e.isValidNot0(m)}catch{return!1}}function i(p,m){let{publicKey:b,publicKeyUncompressed:h}=o;try{let y=p.length;return m===!0&&y!==b||m===!1&&y!==h?!1:!!r.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Ds(M(p,o.seed,"seed"),e.ORDER)}function c(p,m=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(m)}function u(p){let{secretKey:m,publicKey:b,publicKeyUncompressed:h}=o,y=e._lengths;if(!Ee(p))return;let E=M(p,void 0,"key").length,v=E===b||E===h,T=E===m||!!y?.includes(E);if(!(v&&T))return v}function f(p,m,b=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(m)===!1)throw new Error("second arg must be public key");let h=e.fromBytes(p);return r.fromBytes(m).multiply(h).toBytes(b)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=Vn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:r,utils:l,lengths:o})}function Uu(r,t,e={}){let n=t;Cn(n),Lt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?Mr:e.randomBytes,s=e.hmac===void 0?(S,w)=>Ru(n,S,w):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:p,lengths:m}=vp(r,e),b={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},h=c*Fu+he<i.ORDER;function y(S){let w=c>>he;return S>w}function E(S,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return w}function v(){if(h)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function T(S,w){_i(w);let A=m.signature,C=w==="compact"?A:w==="recovered"?A+1:void 0;return M(S,C)}class B{r;s;recovery;constructor(w,A,C){if(this.r=E("r",w),this.s=E("s",A),C!=null){if(v(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(w,A=b.format){T(w,A);let C;if(A==="der"){let{r:U,s:z}=Ot.toSig(M(w));return new B(U,z)}A==="recovered"&&(C=w[0],A="compact",w=w.subarray(1));let D=m.signature/2,R=w.subarray(0,D),F=w.subarray(D,D*2);return new B(a.fromBytes(R),a.fromBytes(F),C)}static fromHex(w,A){return this.fromBytes(Ge(w),A)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new B(this.r,this.s,w)}recoverPublicKey(w){let{r:A,s:C}=this,D=this.assertRecovery(),R=D===2||D===3?A+c:A;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let F=i.toBytes(R),U=r.fromBytes(et(Pu((D&1)===0),F)),z=a.inv(R),N=L(M(w,void 0,"msgHash")),tt=a.create(-N*z),rt=a.create(C*z),nt=r.BASE.multiplyUnsafe(tt).add(U.multiplyUnsafe(rt));if(nt.is0())throw new Error("invalid recovery: point at infinify");return nt.assertValidity(),nt}hasHighS(){return y(this.s)}toBytes(w=b.format){if(_i(w),w==="der")return Ge(Ot.hexFromSig(this));let{r:A,s:C}=this,D=a.toBytes(A),R=a.toBytes(C);return w==="recovered"?(v(),et(Uint8Array.of(this.assertRecovery()),D,R)):et(D,R)}toHex(w){return je(this.toBytes(w))}}Object.freeze(B.prototype),Object.freeze(B);let O=e.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let A=Se(w),C=w.length*8-u;return C>0?A>>BigInt(C):A}:e.bits2int,L=e.bits2int_modN===void 0?function(w){return a.create(O(w))}:e.bits2int_modN,I=qr(u);function k(S){return Ze("num < 2^"+u,S,Ut,I),a.toBytes(S)}function q(S,w){return M(S,void 0,"message"),w?M(n(S),void 0,"prehashed message"):S}function P(S,w,A){let{lowS:C,prehash:D,extraEntropy:R}=vi(A,b);S=q(S,D);let F=L(S),U=a.fromBytes(w);if(!a.isValidNot0(U))throw new Error("invalid private key");let z=[k(U),k(F)];if(R!=null&&R!==!1){let nt=R===!0?o(m.secretKey):R;z.push(M(nt,void 0,"extraEntropy"))}let N=et(...z),tt=F;function rt(nt){let X=O(nt);if(!a.isValidNot0(X))return;let bt=a.inv(X),Ne=r.BASE.multiply(X).toAffine(),Sr=a.create(Ne.x);if(Sr===Ut)return;let xn=a.create(bt*a.create(tt+Sr*U));if(xn===Ut)return;let xa=(Ne.x===Sr?0:2)|Number(Ne.y&he),wa=xn;return C&&y(xn)&&(wa=a.neg(xn),xa^=1),new B(Sr,wa,h?void 0:xa)}return{seed:N,k2sig:rt}}function g(S,w,A={}){let{seed:C,k2sig:D}=P(S,w,A);return xc(n.outputLen,a.BYTES,s)(C,D).toBytes(A.format)}function x(S,w,A,C={}){let{lowS:D,prehash:R,format:F}=vi(C,b);if(A=M(A,void 0,"publicKey"),w=q(w,R),!Ee(S)){let U=S instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}T(S,F);try{let U=B.fromBytes(S,F),z=r.fromBytes(A);if(D&&U.hasHighS())return!1;let{r:N,s:tt}=U,rt=L(w),nt=a.inv(tt),X=a.create(rt*nt),bt=a.create(N*nt),Ne=r.BASE.multiplyUnsafe(X).add(z.multiplyUnsafe(bt));return Ne.is0()?!1:a.create(Ne.x)===N}catch{return!1}}function _(S,w,A={}){let{prehash:C}=vi(A,b);return w=q(w,C),B.fromBytes(S,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:p,lengths:m,Point:r,sign:g,verify:x,recoverPublicKey:_,Signature:B,hash:n})}var Bi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},_p={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Mu=BigInt(2);function Ap(r){let t=Bi.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,Mu,t)*u%t,m=H(p,o,t)*p%t,b=H(m,s,t)*m%t,h=H(b,a,t)*b%t,y=H(h,c,t)*h%t,E=H(y,a,t)*b%t,v=H(E,e,t)*f%t,T=H(v,i,t)*m%t,B=H(T,n,t)*u%t,O=H(B,Mu,t);if(!Ii.eql(Ii.sqr(O),r))throw new Error("Cannot find square root");return O}var Ii=Xe(Bi.p,{sqrt:Ap}),Ip=ku(Bi,{Fp:Ii,endo:_p}),ir=Uu(Ip,gc);function zu(r,t,e,n){let o=Cr.digest(e instanceof Uint8Array?e:e.subarray());if(Zn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ir.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new jr(String(s))});try{return n?.signal?.throwIfAborted(),ir.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new jr(String(s))}}var oo=class{type="secp256k1";raw;_key;constructor(t){this._key=qu(t),this.raw=Ku(this._key)}toMultihash(){return Bt.digest(He(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e,n){return zu(this._key,e,t,n)}};function Vu(r){return new oo(r)}function Ku(r){return ir.Point.fromBytes(r).toBytes()}function qu(r){try{return ir.Point.fromBytes(r),r}catch(t){throw new En(String(t))}}function Hu(r){let{Type:t,Data:e}=nn.decode(r.digest),n=e??new Uint8Array;switch(t){case yt.Ed25519:return Gc(n);case yt.secp256k1:return Vu(n);case yt.ECDSA:return Ja(n);default:throw new vr}}function He(r){return nn.encode({Type:yt[r.type],Data:r.raw})}var $u=Symbol.for("nodejs.util.inspect.custom"),Bp=114,on=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()})`}[Po]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return lt.createV1(Bp,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[$u](){return`PeerId(${this.toString()})`}},so=class extends on{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},io=class extends on{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},ao=class extends on{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Tp=2336,co=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(G(this.url))}[$u](){return`PeerId(${this.url})`}[Po]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return lt.createV1(Tp,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=J(t)),t.toString()===this.toString())}};function ju(r){if(Cp(r))return new so({multihash:r});if(Dp(r))try{let t=Hu(r);if(t.type==="Ed25519")return new io({multihash:r,publicKey:t});if(t.type==="secp256k1")return new ao({multihash:r,publicKey:t})}catch{let e=J(r.digest);return new co(new URL(e))}throw new Sn("Supplied PeerID Multihash is invalid")}function Dp(r){return r.code===Bt.code}function Cp(r){return r.code===Cr.code}function Ti(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 uo(r){let t=Br(W.decode(`z${r}`));return ju(t)}var fo=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 Ti(this.set.entries(),t=>{let e=uo(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=uo(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ti(this.set.values(),t=>uo(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 Di(){return new fo}var Ci={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Gu={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Zu=new globalThis.TextEncoder;function Lp(r,t){let e=Ci[t],n=Gu[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Rp(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Ci[t],o=Gu[t],s=r;for(;s.length>0;){let i=Zu.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 Li(r,{size:t=32,utf8Buffer:e}={}){if(!Ci[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 Rp(r,t,e);r=Zu.encode(r)}return Lp(r,t)}var sn={hash:r=>Number(Li(r,{size:32})),hashV:(r,t)=>Op(sn.hash(r,t))};function Op(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),G(t,"base16")}var Ri=64,Ft=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Ri)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=Rr(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?xt(this.fp,t.fp):!1}};function Ce(r,t){return Math.floor(Math.random()*(t-r))+r}var Le=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Ft))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Ft))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 Ft))throw new TypeError("Invalid Fingerprint");let e=Ce(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Ft))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Fp=500,an=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??sn,this.seed=t.seed??Ce(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=G(t));let e=new Ft(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 Le(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Le(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[Ce(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Le(this.bucketSize));for(let a=0;a<Fp;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 Le(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=G(t));let e=new Ft(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=G(t));let e=new Ft(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}},kp={1:.5,2:.84,4:.95,8:.98};function Pp(r=.001){return r>.002?2:r>1e-5?4:8}function Yu(r,t=.001){let e=Pp(t),n=kp[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Ri);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var lo=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??sn,this.seed=t.seed??Ce(0,Math.pow(2,10)),this.filterSeries=[new an({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=G(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 an({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=G(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=G(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 Oi(r,t=.001,e){return new lo({...Yu(r,t),...e??{}})}function cn(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 ar(r){let t=cn(r);if(t==null)throw new mt(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var ho=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 Xu=45,Np=15,cr=new ho;function po(r){if(!(r.length>Np))return cr.new(r).parseWith(()=>cr.readIPv4Addr())}function mo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Xu))return cr.new(r).parseWith(()=>cr.readIPv6Addr())}function ur(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Xu)return;let e=cr.new(r).parseWith(()=>cr.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 Wu(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 Qu(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 Fi(r){switch(r.length){case Re:return r.join(".");case Oe:{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 Ju(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 tf(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Re=4,Oe=16,a1=parseInt("0xFFFF",16),Up=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function un(r,t){t.length===Oe&&r.length===Re&&Wu(t,0,11)&&(t=t.slice(12)),t.length===Re&&r.length===Oe&&Qu(r,Up,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 ef(r,t){if(typeof t=="string"&&(t=ur(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 ki(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Re,o=po(t);if(o==null&&(n=Oe,o=mo(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=Pi(s,8*n);return{network:un(o,i),mask:i}}function Pi(r,t){if(t!==8*Re&&t!==8*Oe)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 fn=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=ki(t));else{let n=ur(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=ur(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Pi(o,8*n.length);this.network=un(n,this.mask)}}contains(t){return ef({network:this.network,mask:this.mask},t)}toString(){let t=Ju(this.mask),e=t!==-1?String(t):tf(this.mask);return Fi(this.network)+"/"+e}};function rf(r,t){return new fn(r).contains(t)}function nf(r){try{let t=ar(r);return t.type==="ip6"?rf("2000::/3",t.host):!1}catch{return!1}}function fr(r){return!!po(r)}function go(r){return!!mo(r)}var cf=$f(af(),1),$p=["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"],jp=$p.map(r=>new cf.Netmask(r));function Vi(r){for(let t of jp)if(t.contains(r))return!0;return!1}function Gp(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Zp(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 Vi(o)}function Yp(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Xp(r){let t=r.split(":"),e=t[t.length-1];return Vi(e)}function Wp(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 bo(r){if(fr(r))return Vi(r);if(Gp(r))return Zp(r);if(Yp(r))return Xp(r);if(go(r))return Wp(r)}function uf(r){try{let t=ar(r);switch(t.type){case"ip4":case"ip6":return bo(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var Qp=Math.pow(2,7),Jp=Math.pow(2,14),t0=Math.pow(2,21),Hi=Math.pow(2,28),$i=Math.pow(2,35),ji=Math.pow(2,42),Gi=Math.pow(2,49),$=128,ht=127;function pr(r){if(r<Qp)return 1;if(r<Jp)return 2;if(r<t0)return 3;if(r<Hi)return 4;if(r<$i)return 5;if(r<ji)return 6;if(r<Gi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Zi(r,t,e=0){switch(pr(r)){case 8:t[e++]=r&255|$,r/=128;case 7:t[e++]=r&255|$,r/=128;case 6:t[e++]=r&255|$,r/=128;case 5:t[e++]=r&255|$,r/=128;case 4:t[e++]=r&255|$,r>>>=7;case 3:t[e++]=r&255|$,r>>>=7;case 2:t[e++]=r&255|$,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function e0(r,t){let e=r[t],n=0;if(n+=e&ht,e<$||(e=r[t+1],n+=(e&ht)<<7,e<$)||(e=r[t+2],n+=(e&ht)<<14,e<$)||(e=r[t+3],n+=(e&ht)<<21,e<$)||(e=r[t+4],n+=(e&ht)*Hi,e<$)||(e=r[t+5],n+=(e&ht)*$i,e<$)||(e=r[t+6],n+=(e&ht)*ji,e<$)||(e=r[t+7],n+=(e&ht)*Gi,e<$))return n;throw new RangeError("Could not decode varint")}function r0(r,t){let e=r.get(t),n=0;if(n+=e&ht,e<$||(e=r.get(t+1),n+=(e&ht)<<7,e<$)||(e=r.get(t+2),n+=(e&ht)<<14,e<$)||(e=r.get(t+3),n+=(e&ht)<<21,e<$)||(e=r.get(t+4),n+=(e&ht)*Hi,e<$)||(e=r.get(t+5),n+=(e&ht)*$i,e<$)||(e=r.get(t+6),n+=(e&ht)*ji,e<$)||(e=r.get(t+7),n+=(e&ht)*Gi,e<$))return n;throw new RangeError("Could not decode varint")}function Yi(r,t=0){return r instanceof Uint8Array?e0(r,t):r0(r,t)}var ut=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Wt=class extends Error{static name="ValidationError";name="ValidationError"},xo=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},wo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Wi(r){return t=>J(t,r)}function Qi(r){return t=>G(t,r)}function mr(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ke(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function ff(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=G(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=ke(n);return Ie([e,o],e.length+o.length)}function lf(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=te.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=ke(n);return Ie([e,o],e.length+o.length)}function Ji(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=J(t,"base32"),o=mr(e);return`${n}:${o}`}var ta=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 ut("Invalid byte value in IP address");t[n]=o}),t},df=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=fr(e[n]),i;s&&(i=ta(e[n]),e[n]=J(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,J(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 ut("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},hf=function(r){if(r.byteLength!==4)throw new ut("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},pf=function(r){if(r.byteLength!==16)throw new ut("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 ut(`Invalid IPv6 address "${e}"`)}};function mf(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ut(`Invalid IPv6 address "${r}"`)}}var Xi=Object.values(Lr).map(r=>r.decoder),o0=(function(){let r=Xi[0].or(Xi[1]);return Xi.slice(2).forEach(t=>r=r.or(t)),r})();function gf(r){return o0.decode(r)}function yf(r){return t=>r.encoder.encode(t)}function s0(r){if(parseInt(r).toString()!==r)throw new Wt("Value must be an integer")}function i0(r){if(r<0)throw new Wt("Value must be a positive integer, or zero")}function a0(r){return t=>{if(t>r)throw new Wt(`Value must be smaller than or equal to ${r}`)}}function c0(...r){return t=>{for(let e of r)e(t)}}var ln=c0(s0,i0,a0(65535));var it=-1,ea=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 wo(`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)}))}},Qt=new ea,G0=[{code:4,name:"ip4",size:32,valueToBytes:ta,bytesToValue:hf,validate:r=>{if(!fr(r))throw new Wt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ke,bytesToValue:mr,validate:ln},{code:273,name:"udp",size:16,valueToBytes:ke,bytesToValue:mr,validate:ln},{code:33,name:"dccp",size:16,valueToBytes:ke,bytesToValue:mr,validate:ln},{code:41,name:"ip6",size:128,valueToBytes:df,bytesToValue:pf,stringToValue:mf,validate:r=>{if(!go(r))throw new Wt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:it},{code:43,name:"ipcidr",size:8,bytesToValue:Wi("base10"),valueToBytes:Qi("base10")},{code:53,name:"dns",size:it},{code:54,name:"dns4",size:it},{code:55,name:"dns6",size:it},{code:56,name:"dnsaddr",size:it},{code:132,name:"sctp",size:16,valueToBytes:ke,bytesToValue:mr,validate:ln},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:it,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:it,bytesToValue:Wi("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Qi("base58btc")(r):lt.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ji,valueToBytes:ff},{code:445,name:"onion3",size:296,bytesToValue:Ji,valueToBytes:lf},{code:446,name:"garlic64",size:it},{code:447,name:"garlic32",size:it},{code:448,name:"tls"},{code:449,name:"sni",size:it},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:it,bytesToValue:yf(Qo),valueToBytes:gf},{code:480,name:"http"},{code:481,name:"http-path",size:it,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:it}];G0.forEach(r=>{Qt.addProtocol(r)});function bf(r){let t=[],e=0;for(;e<r.length;){let n=Yi(r,e),o=Qt.getProtocol(n),s=pr(n),i=Z0(o,r,e+s),a=0;i>0&&o.size===it&&(a=pr(i));let c=s+a+i,u={code:n,name:o.name,bytes:Vt(r.subarray(e,e+c))};if(i>0){let f=e+s+a,l=r.subarray(f,f+i);u.value=o.bytesToValue?.(l)??J(l)}t.push(u),e+=c}return t}function xf(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Qt.getProtocol(n.code),s=pr(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??G(n.value),a=i.byteLength,o.size===it&&(c=pr(a)));let u=new Uint8Array(s+c+a),f=0;Zi(n.code,u,f),f+=s,i!=null&&(o.size===it&&(Zi(a,u,f),f+=c),u.set(i,f)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return Ie(e,t)}function wf(r){if(r.charAt(0)!=="/")throw new ut('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=Qt.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 ut(`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 ut(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new ut("Incomplete multiaddr");return t}function Ef(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Qt.getProtocol(t.code);if(e==null)throw new ut(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Z0(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Yi(t,e)}var Y0=Symbol.for("nodejs.util.inspect.custom"),oa=Symbol.for("@multiformats/multiaddr");function X0(r){if(r==null&&(r="/"),Sf(r))return r.getComponents();if(r instanceof Uint8Array)return bf(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),wf(r);if(Array.isArray(r))return r;throw new ut("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Eo=class r{[oa]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=X0(t),e.validate!==!1&&W0(this)}get bytes(){return this.#r==null&&(this.#r=xf(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Ef(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 xo(`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 xt(this.bytes,t.bytes)}[Y0](){return`Multiaddr(${this.toString()})`}};function W0(r){r.getComponents().forEach(t=>{let e=Qt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function Sf(r){return!!r?.[oa]}function vf(r){return new Eo(r)}function gr(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var So=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}},yr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new So(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 So(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 sa=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function vo(r={}){return Q0(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 Q0(r,t){t=t??{};let e=t.onEnd,n=new yr,o,s,i,a=gr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,y)=>{s=E=>{s=null,n.push(E);try{h(r(n))}catch(v){y(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=gr()})}},u=h=>s!=null?s(h):(n.push(h),o),f=h=>(n=new yr,s!=null?s({error:h}):(n.push({error:h}),o)),l=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:h})},d=h=>i?o:(i=!0,h!=null?f(h):u({done:!0})),p=()=>(n=new yr,d(),{done:!0}),m=h=>(d(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:m,push:l,end:d,get readableLength(){return n.size},onEmpty:async h=>{let y=h?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let E,v;y!=null&&(E=new Promise((T,B)=>{v=()=>{B(new sa)},y.addEventListener("abort",v)}));try{await Promise.race([a.promise,E])}finally{v!=null&&y!=null&&y?.removeEventListener("abort",v)}}},e==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(h){return b.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return b.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(h){return b.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return b.readableLength},onEmpty:h=>b.onEmpty(h)},o}var ia=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},_f=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function aa(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(_f(i));return}if(i&&(c=()=>{d(_f(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,d),e===Number.POSITIVE_INFINITY)return;let p=new ia;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){d(m)}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 J0=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 tm(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}=J0(r),l=async(...p)=>{let m=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(m))return}catch(b){n(),i(b);return}c.push(m),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=aa(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function br(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=tm(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function dn(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 _o=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Pe=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function em(r){return r.reason}async function hn(r,t,e){if(t==null)return r;let n=e?.translateError??em;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 Ao=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=gr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Kt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function rm(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Io=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,e){this.id=rm(),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 Kt),this.cleanup())}async join(t){let e=new Ao(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 hn(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 Bo=class extends vn{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=dn(this.emitEmpty.bind(this),1),this.emitIdle=dn(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 _o;let n=new Io(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 Kt)}),this.clear()}async onEmpty(t){this.size!==0&&await br(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await br(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await br(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=vo({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 Kt("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 pn(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}function Af(r=0){return new Uint8Array(r)}var nm=Math.pow(2,7),om=Math.pow(2,14),sm=Math.pow(2,21),ca=Math.pow(2,28),ua=Math.pow(2,35),fa=Math.pow(2,42),la=Math.pow(2,49),K=128,pt=127;function mn(r){if(r<nm)return 1;if(r<om)return 2;if(r<sm)return 3;if(r<ca)return 4;if(r<ua)return 5;if(r<fa)return 6;if(r<la)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function im(r,t,e=0){switch(mn(r)){case 8:t[e++]=r&255|K,r/=128;case 7:t[e++]=r&255|K,r/=128;case 6:t[e++]=r&255|K,r/=128;case 5:t[e++]=r&255|K,r/=128;case 4:t[e++]=r&255|K,r>>>=7;case 3:t[e++]=r&255|K,r>>>=7;case 2:t[e++]=r&255|K,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function am(r,t,e=0){switch(mn(r)){case 8:t.set(e++,r&255|K),r/=128;case 7:t.set(e++,r&255|K),r/=128;case 6:t.set(e++,r&255|K),r/=128;case 5:t.set(e++,r&255|K),r/=128;case 4:t.set(e++,r&255|K),r>>>=7;case 3:t.set(e++,r&255|K),r>>>=7;case 2:t.set(e++,r&255|K),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function cm(r,t){let e=r[t],n=0;if(n+=e&pt,e<K||(e=r[t+1],n+=(e&pt)<<7,e<K)||(e=r[t+2],n+=(e&pt)<<14,e<K)||(e=r[t+3],n+=(e&pt)<<21,e<K)||(e=r[t+4],n+=(e&pt)*ca,e<K)||(e=r[t+5],n+=(e&pt)*ua,e<K)||(e=r[t+6],n+=(e&pt)*fa,e<K)||(e=r[t+7],n+=(e&pt)*la,e<K))return n;throw new RangeError("Could not decode varint")}function um(r,t){let e=r.get(t),n=0;if(n+=e&pt,e<K||(e=r.get(t+1),n+=(e&pt)<<7,e<K)||(e=r.get(t+2),n+=(e&pt)<<14,e<K)||(e=r.get(t+3),n+=(e&pt)<<21,e<K)||(e=r.get(t+4),n+=(e&pt)*ca,e<K)||(e=r.get(t+5),n+=(e&pt)*ua,e<K)||(e=r.get(t+6),n+=(e&pt)*fa,e<K)||(e=r.get(t+7),n+=(e&pt)*la,e<K))return n;throw new RangeError("Could not decode varint")}function If(r,t,e=0){return t==null&&(t=Af(mn(r))),t instanceof Uint8Array?im(r,t,e):am(r,t,e)}function Bf(r,t=0){return r instanceof Uint8Array?cm(r,t):um(r,t)}var lm=4194304,To=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ha=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},pa=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ma=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function dm(r){return typeof r?.closeRead=="function"}function hm(r){return typeof r?.close=="function"}function da(r){return dm(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:hm(r)?r.status!=="open":!1}function pm(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function mm(r,t){let e=t?.maxBufferSize??lm,n=new ot,o,s=!1;if(!pm(r))throw new mt("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 To("Stream was unwrapped");if(da(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 Pe(`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 hn(o.promise,f?.signal),da(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(da(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Pe(`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 To("Stream was unwrapped");r.send(f)||await br(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 gm(r,t={}){let e=mm(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=mn(t.maxDataLength));let n=t?.lengthDecoder??Bf,o=t?.lengthEncoder??If;return{async read(i){let a=-1,c=new ot;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 ha("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ma(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new pa(`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 Pe(`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 Pe(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new ot(o(i.byteLength),i),a)},async writeV(i,a){let c=new ot(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function xr(r,t){let e=gm(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Do=class extends Bo{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Tf(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal},f;e?.timeout!=null&&(f=pn([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=dn(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 ga=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 Df(r){let{name:t,metrics:e}=r,n;return e!=null?n=new ga({name:t,metrics:e}):n=new Map,n}var ya="libp2p",ba="autonat";var Cf="dial-request",Lf="dial-back",Rf=200n*1024n,Of=4096;var wr;(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),gn.codec().encode(s.dialRequest,i)),s.dialResponse!=null&&(i.uint32(18),zt.codec().encode(s.dialResponse,i)),s.dialDataRequest!=null&&(i.uint32(26),yn.codec().encode(s.dialDataRequest,i)),s.dialDataResponse!=null&&(i.uint32(34),bn.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=gn.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=yn.codec().decode(s,s.uint32(),{limits:a.limits?.dialDataRequest});break}case 4:{c.dialDataResponse=bn.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*gn.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*yn.codec().stream(s,s.uint32(),`${a}.dialDataRequest`,{limits:c.limits?.dialDataRequest});break}case 4:{yield*bn.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})(wr||(wr={}));var gn;(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 rn('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 rn('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})(gn||(gn={}));var yn;(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})(yn||(yn={}));var ft;(function(r){r.UNUSED="UNUSED",r.E_DIAL_ERROR="E_DIAL_ERROR",r.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",r.OK="OK"})(ft||(ft={}));var Co;(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"})(Co||(Co={}));(function(r){r.codec=()=>De(Co)})(ft||(ft={}));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=()=>De(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&&Co[a.dialStatus]!==0&&(c.uint32(24),ft.codec().encode(a.dialStatus,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:ft.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=ft.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:ft.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 bn;(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:Rr(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})(bn||(bn={}));var Er;(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})(Er||(Er={}));var me;(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=()=>De(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})(me||(me={}));function Lo(r,t){return Math.round(Math.random()*(t-r)+r)}var bm=4,xm=8,Ro=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;constructor(t,e){this.components=t,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=Df({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=Tf(this.findRandomPeers.bind(this),6e4),this.addressFilter=Oi(1024),this.queue=new Do({concurrency:3,maxSize:50}),this.maxDialDataBytes=e.maxDialDataBytes??Rf,this.dialDataChunkSize=e.dialDataChunkSize??Of,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[_n]=["@libp2p/autonat"];get[An](){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=pn([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=xr(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read(Er,{signal:n});if(!this.nonces.has(s.nonce))throw new St("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:me.DialBackStatus.OK},me),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=cn(s.multiaddr);return!(a==null||a.type==="ip6"&&(!e||!nf(s.multiaddr))||uf(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:Di(),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})=>cn(a)?.type==="ip6"),o=cn(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=pn([a.signal,AbortSignal.timeout(this.timeout)]),u=BigInt(Lo(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=xr(i).pb(wr);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),m=BigInt(this.dialDataChunkSize);for(let b=0n;b<u.dialDataRequest.numBytes;b+=m)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===ft.OK){if(this.log.trace("%p dialed %a successfully",t.remotePeer,d.multiaddr),d.success++,d.type!=="observed"){this.confirmAddress(d);continue}}else if(u.dialResponse.dialStatus===ft.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,d.multiaddr),d.failure++;else if(u.dialResponse.dialStatus===ft.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===bm&&this.confirmAddress(d),d.failure===xm&&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}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}getNetworkSegment(t){let e=ar(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 mt(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};var Oo=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=xr(t,{maxDataLength:this.maxMessageSize}).pb(wr),s=Uf(e.remoteAddr);if(s==null)throw new St(`Could not find IP address in connection address "${e.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new St("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new St("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=vf(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:ft.UNUSED}},{signal:n});continue}let f=Uf(c);if(f==null)throw new St(`Could not find IP address in requested address "${c}"`);if(bo(f))throw new St(`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=Lo(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 St("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),ft.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=xr(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:e},Er,n),(await i.read(me,n)).status!==me.DialBackStatus.OK)throw new St("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),ft.E_DIAL_BACK_ERROR}return ft.OK}};function Uf(r){return r.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var Fo=class{client;server;constructor(t,e){let n=`/${e.protocolPrefix??ya}/${ba}/${"2"}/${Cf}`,o=`/${e.protocolPrefix??ya}/${ba}/${"2"}/${Lf}`;this.client=new Ro(t,{...e,dialRequestProtocol:n,dialBackProtocol:o}),this.server=new Oo(t,{...e,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[_n]=["@libp2p/autonat"];get[An](){return["@libp2p/identify"]}async start(){await va(this.client,this.server)}async stop(){await _a(this.client,this.server)}};function wm(r={}){return t=>new Fo(t,r)}return jf(Em);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|