@libp2p/autonat 3.0.22-f144def15 → 3.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PAutonat=(()=>{var Nc=Object.create;var zr=Object.defineProperty;var Uc=Object.getOwnPropertyDescriptor;var Mc=Object.getOwnPropertyNames;var zc=Object.getPrototypeOf,Kc=Object.prototype.hasOwnProperty;var Yn=(r,t)=>()=>{try{return t||r((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}},yt=(r,t)=>{for(var e in t)zr(r,e,{get:t[e],enumerable:!0})},ii=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Mc(t))!Kc.call(r,o)&&o!==e&&zr(r,o,{get:()=>t[o],enumerable:!(n=Uc(t,o))||n.enumerable});return r};var qc=(r,t,e)=>(e=r!=null?Nc(zc(r)):{},ii(t||!r||!r.__esModule?zr(e,"default",{value:r,enumerable:!0}):e,r)),Vc=r=>ii(zr({},"__esModule",{value:!0}),r);var ks=Yn(We=>{"use strict";Object.defineProperty(We,"__esModule",{value:!0});We.Netmask4Impl=void 0;We.ip2long=Xe;We.long2ip=kt;function kt(r){let t=(r&-16777216)>>>24,e=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[t,e,n,o].join(".")}var Cl=48,Rl=97,Ol=65;function Pl(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)-Cl)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-Rl)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.charCodeAt(o)-Ol)>>>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 Xe(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]=Pl(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 Ps=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=Xe(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=(Xe(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=kt(this.netLong),this.mask=kt(this.maskLong),this.hostmask=kt(~this.maskLong),this.first=this.bitmask<=30?kt(this.netLong+1):this.base,this.last=this.bitmask<=30?kt(this.netLong+this.size-2):kt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?kt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):(Xe(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(kt(this.netLong+this.size*t),this.mask)}forEach(t){let e=Xe(this.first),n=Xe(this.last),o=0;for(;e<=n;)t(kt(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};We.Netmask4Impl=Ps});var hc=Yn(Qe=>{"use strict";Object.defineProperty(Qe,"__esModule",{value:!0});Qe.Netmask6Impl=void 0;Qe.ip6bigint=Ns;Qe.bigint2ip6=_e;var kl=ks(),Fs=(1n<<128n)-1n;function Ns(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,kl.ip2long)(n),s=r.substring(0,e+1)+"0:0";return dc(s)&~0xffffffffn|BigInt(o)}return dc(r)}function dc(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 _e(r){if(r<0n||r>Fs)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 Us=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=Fs>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ns(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=_e(this.netBigint),this.mask=_e(this.maskBigint),this.hostmask=_e(~this.maskBigint&Fs),this.first=this.base,this.last=_e(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.last):(Ns(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(_e(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(_e(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};Qe.Netmask6Impl=Us});var pc=Yn(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.long2ip=ce.ip2long=ce.Netmask=void 0;var Pn=ks();Object.defineProperty(ce,"ip2long",{enumerable:!0,get:function(){return Pn.ip2long}});Object.defineProperty(ce,"long2ip",{enumerable:!0,get:function(){return Pn.long2ip}});var Fl=hc(),Ms=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 Fl.Netmask6Impl(t,e):this._impl=new Pn.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 Pn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new r(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new r(t))),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let e=this._impl.next(t);return new r(e.base,e.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ce.Netmask=Ms});var oh={};yt(oh,{autoNAT:()=>nh});var Ft=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ht=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Kr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var qr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var or=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Xn=Symbol.for("@libp2p/peer-id");function Hc(r){return typeof r?.handleEvent=="function"}function jc(r){return(r!==!0&&r!==!1&&r?.once)??!1}var Vr=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=jc(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))}Hc(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 ai=Symbol.for("@libp2p/service-capabilities"),ci=Symbol.for("@libp2p/service-dependencies");var eo={};yt(eo,{base58btc:()=>Y,base58flickr:()=>Jc});var Ph=new Uint8Array(0);function fi(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 Nt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return fe(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return fe(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function ui(r){return new TextEncoder().encode(r)}function li(r){return new TextDecoder().decode(r)}function $c(r){return r?.buffer instanceof ArrayBuffer}function fe(r){return $c(r)?r:r.slice()}function Zc(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),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function h(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var w=0,m=0,l=0,g=b.length;l!==g&&b[l]===0;)l++,w++;for(var x=(g-l)*d+1>>>0,I=new Uint8Array(x);l!==g;){for(var B=b[l],C=0,O=x-1;(B!==0||C<m)&&O!==-1;O--,C++)B+=256*I[O]>>>0,I[O]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");m=C,l++}for(var L=x-m;L!==x&&I[L]===0;)L++;for(var k=c.repeat(w);L<x;++L)k+=r.charAt(I[L]);return k}function u(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var w=0;if(b[w]!==" "){for(var m=0,l=0;b[w]===c;)m++,w++;for(var g=(b.length-w)*f+1>>>0,x=new Uint8Array(g);b[w];){var I=e[b.charCodeAt(w)];if(I===255)return;for(var B=0,C=g-1;(I!==0||B<l)&&C!==-1;C--,B++)I+=a*x[C]>>>0,x[C]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");l=B,w++}if(b[w]!==" "){for(var O=g-l;O!==g&&x[O]===0;)O++;for(var L=new Uint8Array(m+(g-O)),k=m;O!==g;)L[k++]=x[O++];return L}}}function p(b){var w=u(b);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:u,decode:p}}var Gc=Zc,Yc=Gc,hi=Yc;var Wn=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")}},Qn=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 pi(this,t)}},Jn=class{decoders;constructor(t){this.decoders=t}or(t){return pi(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 pi(r,t){return new Jn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var to=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 Wn(t,e,n),this.decoder=new Qn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:r,prefix:t,encode:e,decode:n}){return new to(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=hi(e,r);return Te({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function Xc(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 f=0;f<o;++f){let d=t[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,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 Wc(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 Qc(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=Qc(n);return Te({prefix:t,name:r,encode(s){return Wc(s,n,e)},decode(s){return Xc(s,o,e,r)}})}var Y=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Jc=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ro={};yt(ro,{base32:()=>Xt,base32hex:()=>nf,base32hexpad:()=>sf,base32hexpadupper:()=>af,base32hexupper:()=>of,base32pad:()=>ef,base32padupper:()=>rf,base32upper:()=>tf,base32z:()=>cf});var Xt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),tf=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ef=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rf=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nf=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),of=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),sf=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),af=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),cf=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var no={};yt(no,{base36:()=>sr,base36upper:()=>ff});var sr=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ff=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var uf=yi,mi=128,lf=127,df=~lf,hf=Math.pow(2,31);function yi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=hf;)t[e++]=r&255|mi,r/=128;for(;r&df;)t[e++]=r&255|mi,r>>>=7;return t[e]=r|0,yi.bytes=e-n+1,t}var pf=oo,mf=128,gi=127;function oo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw oo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&gi)<<o:(i&gi)*Math.pow(2,o),o+=7}while(i>=mf);return oo.bytes=s-n,e}var gf=Math.pow(2,7),yf=Math.pow(2,14),bf=Math.pow(2,21),xf=Math.pow(2,28),wf=Math.pow(2,35),Ef=Math.pow(2,42),Sf=Math.pow(2,49),vf=Math.pow(2,56),_f=Math.pow(2,63),Af=function(r){return r<gf?1:r<yf?2:r<bf?3:r<xf?4:r<wf?5:r<Ef?6:r<Sf?7:r<vf?8:r<_f?9:10},If={encode:uf,decode:pf,encodingLength:Af},Bf=If,ir=Bf;function ar(r,t=0){return[ir.decode(r,t),ir.decode.bytes]}function Le(r,t,e=0){return ir.encode(r,t,e),t}function De(r){return ir.encodingLength(r)}function Re(r,t){let e=t.byteLength,n=De(r),o=n+De(e),s=new Uint8Array(o+e);return Le(r,s,0),Le(e,s,n),s.set(t,o),new Ce(r,e,t,s)}function ue(r){let t=Nt(r),[e,n]=ar(t),[o,s]=ar(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ce(e,o,i,t)}function bi(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&fi(r.bytes,e.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=fe(n),this.bytes=fe(o)}};function xi(r,t){let{bytes:e,version:n}=r;return n===0?Lf(e,so(r),t??Y.encoder):Df(e,so(r),t??Xt.encoder)}var wi=new WeakMap;function so(r){let t=wi.get(r);if(t==null){let e=new Map;return wi.set(r,e),e}return t}var ct=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=fe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Cf)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=Re(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&&bi(t.multihash,n.multihash)}toString(t){return xi(this,t)}toJSON(){return{"/":xi(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??Ei(n,o,s.bytes))}else if(e[Rf]===!0){let{version:n,multihash:o,code:s}=e,i=ue(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==cr)throw new Error(`Version 0 CID must use dag-pb (code: ${cr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ei(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,cr,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=Nt(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 Ce(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[h,u]=ar(t.subarray(e));return e+=u,h},o=n(),s=cr;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(),f=e+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=Tf(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return so(s).set(n,t),s}};function Tf(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 Xt.prefix:{let e=t??Xt;return[Xt.prefix,e.decode(r)]}case sr.prefix:{let e=t??sr;return[sr.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 Lf(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 Df(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 cr=112,Cf=18;function Ei(r,t,e){let n=De(r),o=n+De(t),s=new Uint8Array(o+e.byteLength);return Le(r,s,0),Le(t,s,n),s.set(e,o),s}var Rf=Symbol.for("@ipld/js-cid/CID");var io={};yt(io,{identity:()=>Et});var Si=0,Of="identity",vi=Nt;function Pf(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 Re(Si,vi(r))}var Et={code:Si,name:Of,encode:vi,digest:Pf};function ft(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 kf(r){return r.buffer instanceof ArrayBuffer}function St(r){return kf(r)?r:r.slice()}async function _i(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,St(t),St(e.subarray()));return n?.signal?.throwIfAborted(),s}function wt(r=0){return new Uint8Array(r)}function ut(r=0){return new Uint8Array(r)}function Ff(r){return r?.buffer instanceof ArrayBuffer}function ao(r){if(Ff(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ct(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ut(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return ao(e)}var Ii=Symbol.for("@achingbrain/uint8arraylist");function Ai(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 jr(r){return!!r?.[Ii]}var rt=class r{bufs;length;[Ii]=!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(jr(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(jr(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=Ai(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ai(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(jr(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 Ct(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Ct(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 f=t>=a&&t<c,d=e>a&&e<=c;if(f&&d){if(t===a&&e===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){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(!jr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(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 h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let h=e;h<=c;h+=d){d=0;for(let u=f;u>=0;u--){let p=this.get(h+u);if(n[u]!==p){d=Math.max(1,u-a[p]);break}}if(d===0)return h}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=ut(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=wt(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=wt(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=wt(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=ut(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=wt(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=wt(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=wt(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=wt(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=wt(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(!ft(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 co={};yt(co,{base10:()=>Nf});var Nf=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var fo={};yt(fo,{base16:()=>Uf,base16upper:()=>Mf});var Uf=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Mf=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var uo={};yt(uo,{base2:()=>zf});var zf=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var lo={};yt(lo,{base256emoji:()=>jf});var Bi=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}"),Kf=Bi.reduce((r,t,e)=>(r[e]=t,r),[]),qf=Bi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Vf(r){return r.reduce((t,e)=>(t+=Kf[e],t),"")}function Hf(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=qf[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var jf=Te({prefix:"\u{1F680}",name:"base256emoji",encode:Vf,decode:Hf});var po={};yt(po,{base64:()=>$f,base64pad:()=>Zf,base64url:()=>ho,base64urlpad:()=>Gf});var $f=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zf=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ho=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gf=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var mo={};yt(mo,{base8:()=>Yf});var Yf=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var go={};yt(go,{identity:()=>Xf});var Xf=Te({prefix:"\0",name:"identity",encode:r=>li(r),decode:r=>ui(r)});var xp=new TextEncoder,wp=new TextDecoder;var xo={};yt(xo,{sha256:()=>fr,sha512:()=>tu});var Jf=20;function bo({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new yo(r,t,e,n,o)}var yo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Jf,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?Ti(n,this.code,e?.truncate):n.then(o=>Ti(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ti(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 Re(t,r)}function Di(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var fr=bo({name:"sha2-256",code:18,encode:Di("SHA-256")}),tu=bo({name:"sha2-512",code:19,encode:Di("SHA-512")});var ur={...go,...uo,...mo,...co,...fo,...ro,...no,...eo,...po,...lo},Rp={...xo,...io};function Ri(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ci=Ri("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),wo=Ri("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=ut(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),eu={utf8:Ci,"utf-8":Ci,hex:ur.base16,latin1:wo,ascii:wo,binary:wo,...ur},$r=eu;function H(r,t="utf8"){let e=$r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function W(r,t="utf8"){let e=$r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var ru=parseInt("11111",2),Eo=parseInt("10000000",2),nu=parseInt("01111111",2),Oi={0:lr,1:lr,2:ou,3:au,4:cu,5:iu,6:su,16:lr,22:lr,48:lr};function So(r,t={offset:0}){let e=r[t.offset]&ru;if(t.offset++,Oi[e]!=null)return Oi[e](r,t);throw new Error("No decoder for tag "+e)}function dr(r,t){let e=0;if((r[t.offset]&Eo)===Eo){let n=r[t.offset]&nu,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 lr(r,t){dr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=So(r,t);if(n===null)break;e.push(n)}return e}function ou(r,t){let e=dr(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 su(r,t){let e=dr(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 f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let d=0;for(let h=0;h<c.length;h++)d+=c[h]<<h*7;a+=`.${d}`,c=[]}}return a}function iu(r,t){return t.offset++,null}function au(r,t){let e=dr(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 cu(r,t){let e=dr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function fu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new rt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function vo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=fu(r.byteLength);return new rt(Uint8Array.from([t.byteLength|Eo]),t)}function Pi(r){let t=new rt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new rt(Uint8Array.from([2]),vo(t),t)}function ki(r){let t=Uint8Array.from([0]),e=new rt(t,r);return new rt(Uint8Array.from([3]),vo(e),e)}function Zr(r,t=48){let e=new rt;for(let n of r)e.append(n);return new rt(Uint8Array.from([t]),vo(e),e)}var uu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),lu=Uint8Array.from([6,5,43,129,4,0,34]),du=Uint8Array.from([6,5,43,129,4,0,35]),hu={ext:!0,kty:"EC",crv:"P-256"},pu={ext:!0,kty:"EC",crv:"P-384"},mu={ext:!0,kty:"EC",crv:"P-521"},_o=32,Ao=48,Io=66;function Fi(r){let t=So(r);return Ni(t)}function Ni(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===_o*2+1)return n=W(t.subarray(e,e+_o),"base64url"),o=W(t.subarray(e+_o),"base64url"),new Oe({...hu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ao*2+1)return n=W(t.subarray(e,e+Ao),"base64url"),o=W(t.subarray(e+Ao),"base64url"),new Oe({...pu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Io*2+1)return n=W(t.subarray(e,e+Io),"base64url"),o=W(t.subarray(e+Io),"base64url"),new Oe({...mu,key_ops:["verify"],x:n,y:o});throw new ht(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ui(r){return Zr([Pi(Uint8Array.from([1])),Zr([gu(r.crv)],160),Zr([ki(new rt(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function gu(r){if(r==="P-256")return uu;if(r==="P-384")return lu;if(r==="P-521")return du;throw new ht(`Invalid curve ${r}`)}var Oe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ui(this.jwk)),this._raw}toMultihash(){return Et.digest(Pe(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:ft(this.raw,t.raw)}async verify(t,e,n){return _i(this.jwk,e,t,n)}};function Bo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Qt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${r}`)}}function bt(r,t,e=""){let n=Bo(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}`,f=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(f):new TypeError(f)}return r}function Gr(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Qt(r.outputLen),Qt(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function ke(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 Yr(r,t){bt(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 Mt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Xr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function vt(r,t){return r<<32-t|r>>>t}var zi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",yu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Wr(r){if(bt(r),zi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=yu[r[e]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function Mi(r){if(r>=Ut._0&&r<=Ut._9)return r-Ut._0;if(r>=Ut.A&&r<=Ut.F)return r-(Ut.A-10);if(r>=Ut.a&&r<=Ut.f)return r-(Ut.a-10)}function hr(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(zi)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=Mi(r.charCodeAt(s)),a=Mi(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 To(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];bt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Lo(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 Ki(r=32){Qt(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var Do=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function qi(r,t,e){return r&t^~r&e}function Vi(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=Xr(this.buffer)}update(t){ke(this),bt(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=Xr(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){ke(this),Yr(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)e[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Xr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],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()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Qr=BigInt(4294967295),Hi=BigInt(32);function bu(r,t=!1){return t?{h:Number(r&Qr),l:Number(r>>Hi&Qr)}:{h:Number(r>>Hi&Qr)|0,l:Number(r&Qr)|0}}function ji(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}=bu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Co=(r,t,e)=>r>>>e,Ro=(r,t,e)=>r<<32-e|t>>>e,le=(r,t,e)=>r>>>e|t<<32-e,de=(r,t,e)=>r<<32-e|t>>>e,mr=(r,t,e)=>r<<64-e|t>>>e-32,gr=(r,t,e)=>r>>>e-32|t<<64-e;function Rt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var $i=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Zi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Gi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Yi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Xi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Wi=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var wu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jt=new Uint32Array(64),Oo=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 h=0;h<16;h++,e+=4)Jt[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let u=Jt[h-15],p=Jt[h-2],b=vt(u,7)^vt(u,18)^u>>>3,w=vt(p,17)^vt(p,19)^p>>>10;Jt[h]=w+Jt[h-7]+b+Jt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:d}=this;for(let h=0;h<64;h++){let u=vt(a,6)^vt(a,11)^vt(a,25),p=d+u+qi(a,c,f)+wu[h]+Jt[h]|0,w=(vt(n,2)^vt(n,13)^vt(n,22))+Vi(n,o,s)|0;d=f,f=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+w|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,f=f+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,f,d)}roundClean(){Mt(Jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},Po=class extends Oo{A=zt[0]|0;B=zt[1]|0;C=zt[2]|0;D=zt[3]|0;E=zt[4]|0;F=zt[5]|0;G=zt[6]|0;H=zt[7]|0;constructor(){super(32)}};var Qi=ji(["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))),Eu=Qi[0],Su=Qi[1],te=new Uint32Array(80),ee=new Uint32Array(80),ko=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:f,El:d,Fh:h,Fl:u,Gh:p,Gl:b,Hh:w,Hl:m}=this;return[t,e,n,o,s,i,a,c,f,d,h,u,p,b,w,m]}set(t,e,n,o,s,i,a,c,f,d,h,u,p,b,w,m){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=d|0,this.Fh=h|0,this.Fl=u|0,this.Gh=p|0,this.Gl=b|0,this.Hh=w|0,this.Hl=m|0}process(t,e){for(let x=0;x<16;x++,e+=4)te[x]=t.getUint32(e),ee[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let I=te[x-15]|0,B=ee[x-15]|0,C=le(I,B,1)^le(I,B,8)^Co(I,B,7),O=de(I,B,1)^de(I,B,8)^Ro(I,B,7),L=te[x-2]|0,k=ee[x-2]|0,q=le(L,k,19)^mr(L,k,61)^Co(L,k,6),F=de(L,k,19)^gr(L,k,61)^Ro(L,k,6),y=Gi(O,F,ee[x-7],ee[x-16]),E=Yi(y,C,q,te[x-7],te[x-16]);te[x]=E|0,ee[x]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:d,Eh:h,El:u,Fh:p,Fl:b,Gh:w,Gl:m,Hh:l,Hl:g}=this;for(let x=0;x<80;x++){let I=le(h,u,14)^le(h,u,18)^mr(h,u,41),B=de(h,u,14)^de(h,u,18)^gr(h,u,41),C=h&p^~h&w,O=u&b^~u&m,L=Xi(g,B,O,Su[x],ee[x]),k=Wi(L,l,I,C,Eu[x],te[x]),q=L|0,F=le(n,o,28)^mr(n,o,34)^mr(n,o,39),y=de(n,o,28)^gr(n,o,34)^gr(n,o,39),E=n&s^n&a^s&a,_=o&i^o&c^i&c;l=w|0,g=m|0,w=p|0,m=b|0,p=h|0,b=u|0,{h,l:u}=Rt(f|0,d|0,k|0,q|0),f=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=$i(q,y,_);n=Zi(v,k,F,E),o=v|0}({h:n,l:o}=Rt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Rt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Rt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:d}=Rt(this.Dh|0,this.Dl|0,f|0,d|0),{h,l:u}=Rt(this.Eh|0,this.El|0,h|0,u|0),{h:p,l:b}=Rt(this.Fh|0,this.Fl|0,p|0,b|0),{h:w,l:m}=Rt(this.Gh|0,this.Gl|0,w|0,m|0),{h:l,l:g}=Rt(this.Hh|0,this.Hl|0,l|0,g|0),this.set(n,o,s,i,a,c,f,d,h,u,p,b,w,m,l,g)}roundClean(){Mt(te,ee)}destroy(){this.destroyed=!0,Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Fo=class extends ko{Ah=st[0]|0;Al=st[1]|0;Bh=st[2]|0;Bl=st[3]|0;Ch=st[4]|0;Cl=st[5]|0;Dh=st[6]|0;Dl=st[7]|0;Eh=st[8]|0;El=st[9]|0;Fh=st[10]|0;Fl=st[11]|0;Gh=st[12]|0;Gl=st[13]|0;Hh=st[14]|0;Hl=st[15]|0;constructor(){super(64)}};var Ji=Lo(()=>new Po,Do(1));var Jr=Lo(()=>new Fo,Do(3));var M=(r,t,e)=>bt(r,t,e),Uo=Qt,Fe=Wr,J=(...r)=>To(...r),Ne=r=>hr(r),he=Bo,yr=r=>Ki(r),en=BigInt(0),No=BigInt(1);function _t(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function rn(r){if(typeof r=="bigint"){if(!tn(r))throw new RangeError("positive bigint expected, got "+r)}else Uo(r);return r}function At(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 br(r){let t=rn(r).toString(16);return t.length&1?"0"+t:t}function ta(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?en:BigInt("0x"+r)}function pe(r){return ta(Wr(r))}function Ot(r){return ta(Wr(xr(bt(r)).reverse()))}function nn(r,t){if(Qt(t),t===0)throw new RangeError("zero length");r=rn(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return hr(e.padStart(t*2,"0"))}function Mo(r,t){return nn(r,t).reverse()}function ea(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 xr(r){return Uint8Array.from(M(r))}function on(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 tn=r=>typeof r=="bigint"&&en<=r;function vu(r,t,e){return tn(r)&&tn(t)&&tn(e)&&t<=r&&r<e}function Ue(r,t,e,n){if(!vu(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Me(r){if(r<en)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>en;r>>=No,t+=1);return t}var wr=r=>(No<<BigInt(r))-No;function ra(r,t,e){if(Qt(r,"hashLen"),Qt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),d=0,h=()=>{c.fill(1),f.fill(0),d=0},u=(...m)=>e(f,J(c,...m)),p=(m=o)=>{f=u(s,m),c=u(),m.length!==0&&(f=u(i,m),c=u())},b=()=>{if(d++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,l=[];for(;m<t;){c=u();let g=c.slice();l.push(g),m+=c.length}return J(...l)};return(m,l)=>{h(),p(m);let g;for(;(g=l(b()))===void 0;)p();return h(),g}}function It(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 f=typeof c;if(f!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}var zo=()=>{throw new Error("not implemented")};var it=BigInt(0),Z=BigInt(1),me=BigInt(2),ia=BigInt(3),aa=BigInt(4),ca=BigInt(5),_u=BigInt(7),fa=BigInt(8),Au=BigInt(9),ua=BigInt(16);function X(r,t){if(t<=it)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=it?e:t+e}function j(r,t,e){if(t<it)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >it;)n*=n,n%=e;return n}function na(r,t){if(r===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let e=X(r,t),n=t,o=it,s=Z,i=Z,a=it;for(;e!==it;){let f=n/e,d=n-e*f,h=o-i*f,u=s-a*f;n=e,e=d,o=i,s=a,i=h,a=u}if(n!==Z)throw new Error("invert: does not exist");return X(o,t)}function Ko(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function la(r,t){let e=r,n=(e.ORDER+Z)/aa,o=e.pow(t,n);return Ko(e,o,t),o}function Iu(r,t){let e=r,n=(e.ORDER-ca)/fa,o=e.mul(t,me),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,me),s),c=e.mul(i,e.sub(a,e.ONE));return Ko(e,c,t),c}function Bu(r){let t=ze(r),e=da(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+_u)/ua;return((a,c)=>{let f=a,d=f.pow(c,i),h=f.mul(d,n),u=f.mul(d,o),p=f.mul(d,s),b=f.eql(f.sqr(h),c),w=f.eql(f.sqr(u),c);d=f.cmov(d,h,b),h=f.cmov(p,u,w);let m=f.eql(f.sqr(h),c),l=f.cmov(d,h,m);return Ko(f,l,c),l})}function da(r){if(r<ia)throw new Error("sqrt is not defined for small field");let t=r-Z,e=0;for(;t%me===it;)t/=me,e++;let n=me,o=ze(r);for(;oa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return la;let s=o.pow(n,t),i=(t+Z)/me;return function(c,f){let d=c;if(d.is0(f))return f;if(oa(d,f)!==1)throw new Error("Cannot find square root");let h=e,u=d.mul(d.ONE,s),p=d.pow(f,t),b=d.pow(f,i);for(;!d.eql(p,d.ONE);){if(d.is0(p))return d.ZERO;let w=1,m=d.sqr(p);for(;!d.eql(m,d.ONE);)if(w++,m=d.sqr(m),w===h)throw new Error("Cannot find square root");let l=Z<<BigInt(h-w-1),g=d.pow(u,l);h=w,u=d.sqr(g),p=d.mul(p,u),b=d.mul(b,g)}return b}}function Tu(r){return r%aa===ia?la:r%fa===ca?Iu:r%ua===Au?Bu(r):da(r)}var Kt=(r,t)=>(X(r,t)&Z)===Z,Lu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function qo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Lu.reduce((n,o)=>(n[o]="function",n),t);if(It(r,e),At(r.BYTES,"BYTES"),At(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 Du(r,t,e){let n=r;if(e<it)throw new Error("invalid exponent, negatives unsupported");if(e===it)return n.ONE;if(e===Z)return t;let o=n.ONE,s=t;for(;e>it;)e&Z&&(o=n.mul(o,s)),s=n.sqr(s),e>>=Z;return o}function Er(r,t,e=!1){let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function oa(r,t){let e=r,n=(e.ORDER-Z)/me,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 Cu(r,t){if(t!==void 0&&Uo(t),r<=it)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=Me(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 sa=new WeakMap,sn=class{ORDER;BITS;BYTES;isLE;ZERO=it;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}=Cu(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 it<=t&&t<this.ORDER}is0(t){return t===it}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&Z)===Z}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 Du(this,t,e)}div(t,e){return X(t*na(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 na(t,this.ORDER)}sqrt(t){let e=sa.get(this);return e||sa.set(this,e=Tu(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?Mo(t,this.BYTES):nn(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 f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Ot(t):pe(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 Er(this,t)}cmov(t,e,n){return _t(n,"condition"),n?e:t}};Object.freeze(sn.prototype);function ze(r,t={}){return new sn(r,t)}function ha(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=Me(r-Z);return Math.ceil(t/8)}function Vo(r){let t=ha(r);return t+Math.ceil(t/2)}function Ho(r,t,e=!1){M(r);let n=r.length,o=ha(t),s=Math.max(Vo(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Ot(r):pe(r),a=X(i,t-Z)+Z;return e?Mo(a,o):nn(a,o)}var Ke=BigInt(0),ge=BigInt(1);function Sr(r,t){let e=t.negate();return r?e:t}function ye(r,t){let e=Er(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function ya(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function jo(r,t){ya(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=wr(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function pa(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+=ge);let f=t*n,d=f+Math.abs(a)-1,h=a===0,u=a<0,p=t%2!==0;return{nextN:c,offset:d,isZero:h,isNeg:u,isNegF:p,offsetF:f}}var $o=new WeakMap,ba=new WeakMap;function Zo(r){return ba.get(r)||1}function ma(r){if(r!==Ke)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>Ke;)e&ge&&(n=n.add(o)),o=o.double(),e>>=ge;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=jo(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)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=jo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:d,isNeg:h,isNegF:u,offsetF:p}=pa(n,a,i);n=c,d?s=s.add(Sr(u,e[p])):o=o.add(Sr(h,e[f]))}return ma(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=jo(t,this.bits);for(let i=0;i<s.windows&&n!==Ke;i++){let{nextN:a,offset:c,isZero:f,isNeg:d}=pa(n,i,s);if(n=a,!f){let h=e[c];o=o.add(d?h.negate():h)}}return ma(n),o}getPrecomputes(t,e,n){let o=$o.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),$o.set(e,o))),o}cached(t,e,n){let o=Zo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Zo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){ya(e,this.bits),ba.set(t,e),$o.delete(t)}hasCache(t){return Zo(t)!==1}};function xa(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ke||n>Ke;)e&ge&&(s=s.add(o)),n&ge&&(i=i.add(o)),o=o.double(),e>>=ge,n>>=ge;return{p1:s,p2:i}}function ga(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return qo(t),t}else return ze(r,{isLE:e})}function an(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 f=t[c];if(!(typeof f=="bigint"&&f>Ke))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ga(t.p,e.Fp,n),s=ga(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 cn(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var re=BigInt(0),nt=BigInt(1),Go=BigInt(2),Ru=BigInt(8);function Ou(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 wa(r,t={}){let e=t,n=an("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;It(e,{},{uvRatio:"function"});let c=Go<<BigInt(s.BYTES*8)-nt,f=w=>o.create(w),d=e.uvRatio===void 0?(w,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(w,m))}}catch{return{isValid:!1,value:re}}}:e.uvRatio;if(!Ou(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(w,m,l=!1){let g=l?nt:re;return Ue("coordinate "+w,m,g,c),m}function u(w){if(!(w instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,nt,f(i.Gx*i.Gy));static ZERO=new p(re,nt,nt,re);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,l,g,x){this.X=h("x",m),this.Y=h("y",l),this.Z=h("z",g,!0),this.T=h("t",x),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:l,y:g}=m||{};return h("x",l),h("y",g),new p(l,g,nt,f(l*g))}static fromBytes(m,l=!1){let g=o.BYTES,{a:x,d:I}=i;m=xr(M(m,g,"point")),_t(l,"zip215");let B=xr(m),C=m[g-1];B[g-1]=C&-129;let O=Ot(B),L=l?c:o.ORDER;Ue("point.y",O,re,L);let k=f(O*O),q=f(k-nt),F=f(I*k-x),{isValid:y,value:E}=d(q,F);if(!y)throw new Error("bad point: invalid y coordinate");let _=(E&nt)===nt,v=(C&128)!==0;if(!l&&E===re&&v)throw new Error("bad point: x=0 and x_0=1");return v!==_&&(E=f(-E)),p.fromAffine({x:E,y:O})}static fromHex(m,l=!1){return p.fromBytes(Ne(m),l)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,l=!0){return b.createCache(this,m),l||this.multiply(Go),this}assertValidity(){let m=this,{a:l,d:g}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:x,Y:I,Z:B,T:C}=m,O=f(x*x),L=f(I*I),k=f(B*B),q=f(k*k),F=f(O*l),y=f(k*f(F+L)),E=f(q+f(g*f(O*L)));if(y!==E)throw new Error("bad point: equation left != right (1)");let _=f(x*I),v=f(B*C);if(_!==v)throw new Error("bad point: equation left != right (2)")}equals(m){u(m);let{X:l,Y:g,Z:x}=this,{X:I,Y:B,Z:C}=m,O=f(l*C),L=f(I*x),k=f(g*C),q=f(B*x);return O===L&&k===q}is0(){return this.equals(p.ZERO)}negate(){return new p(f(-this.X),this.Y,this.Z,f(-this.T))}double(){let{a:m}=i,{X:l,Y:g,Z:x}=this,I=f(l*l),B=f(g*g),C=f(Go*f(x*x)),O=f(m*I),L=l+g,k=f(f(L*L)-I-B),q=O+B,F=q-C,y=O-B,E=f(k*F),_=f(q*y),v=f(k*y),S=f(F*q);return new p(E,_,S,v)}add(m){u(m);let{a:l,d:g}=i,{X:x,Y:I,Z:B,T:C}=this,{X:O,Y:L,Z:k,T:q}=m,F=f(x*O),y=f(I*L),E=f(C*g*q),_=f(B*k),v=f((x+I)*(O+L)-F-y),S=_-E,A=_+E,D=f(y-l*F),T=f(v*S),R=f(A*D),P=f(v*D),U=f(S*A);return new p(T,R,U,P)}subtract(m){return u(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:l,f:g}=b.cached(this,m,x=>ye(p,x));return ye(p,[l,g])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===re?p.ZERO:this.is0()||m===nt?this:b.unsafe(this,m,l=>ye(p,l))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.unsafe(this,i.n).is0()}toAffine(m){let l=this,g=m,{X:x,Y:I,Z:B}=l,C=l.is0();g==null&&(g=C?Ru:o.inv(B));let O=f(x*g),L=f(I*g),k=o.mul(B,g);if(C)return{x:re,y:nt};if(k!==nt)throw new Error("invZ was invalid");return{x:O,y:L}}clearCofactor(){return a===nt?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:l}=this.toAffine(),g=o.toBytes(l);return g[g.length-1]|=m&nt?128:0,g}toHex(){return Fe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=new qe(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var fn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){zo()}static fromHex(t){zo()}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 Fe(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 Ea(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;It(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,f=n.outputLen,d=2*a.BYTES;if(f!==void 0&&(At(f,"hash.outputLen"),f!==d))throw new Error(`hash.outputLen must be ${d}, got ${f}`);let h=o.randomBytes===void 0?yr:o.randomBytes,u=o.adjustScalarBytes===void 0?y=>y:o.adjustScalarBytes,p=o.domain===void 0?(y,E,_)=>{if(_t(_,"phflag"),E.length||_)throw new Error("Contexts/pre-hash are not supported");return y}:o.domain;function b(y){return c.create(Ot(y))}function w(y){let E=O.secretKey;M(y,O.secretKey,"secretKey");let _=M(n(y),2*E,"hashedSecretKey"),v=u(_.slice(0,E)),S=_.slice(E,2*E),A=b(v);return{head:v,prefix:S,scalar:A}}function m(y){let{head:E,prefix:_,scalar:v}=w(y),S=i.multiply(v),A=S.toBytes();return{head:E,prefix:_,scalar:v,point:S,pointBytes:A}}function l(y){return m(y).pointBytes}function g(y=Uint8Array.of(),...E){let _=J(...E);return b(n(p(_,M(y,void 0,"context"),!!s)))}function x(y,E,_={}){y=M(y,void 0,"message"),s&&(y=s(y));let{prefix:v,scalar:S,pointBytes:A}=m(E),D=g(_.context,v,y),T=i.multiply(D).toBytes(),R=g(_.context,T,A,y),P=c.create(D+R*S);if(!c.isValid(P))throw new Error("sign failed: invalid s");let U=J(T,c.toBytes(P));return M(U,O.signature,"result")}let I={zip215:o.zip215};function B(y,E,_,v=I){let{context:S}=v,A=v.zip215===void 0?!!I.zip215:v.zip215,D=O.signature;y=M(y,D,"signature"),E=M(E,void 0,"message"),_=M(_,O.publicKey,"publicKey"),A!==void 0&&_t(A,"zip215"),s&&(E=s(E));let T=D/2,R=y.subarray(0,T),P=Ot(y.subarray(T,D)),U,z,N;try{U=r.fromBytes(_,A),z=r.fromBytes(R,A),N=i.multiplyUnsafe(P)}catch{return!1}if(!A&&U.isSmallOrder())return!1;let Q=g(S,R,_,E);return z.add(U.multiplyUnsafe(Q)).subtract(N).clearCofactor().is0()}let C=a.BYTES,O={secretKey:C,publicKey:C,signature:2*C,seed:C};function L(y){return y=y===void 0?h(O.seed):y,M(y,O.seed,"seed")}function k(y){return he(y)&&y.length===O.secretKey}function q(y,E){try{return!!r.fromBytes(y,E===void 0?I.zip215:E)}catch{return!1}}let F={getExtendedPublicKey:m,randomSecretKey:L,isValidSecretKey:k,isValidPublicKey:q,toMontgomery(y){let{y:E}=r.fromBytes(y),_=O.publicKey,v=_===32;if(!v&&_!==57)throw new Error("only defined for 25519 and 448");let S=v?a.div(nt+E,nt-E):a.div(E-nt,E+nt);return a.toBytes(S)},toMontgomerySecret(y){let E=O.secretKey;M(y,E);let _=n(y.subarray(0,E));return u(_).subarray(0,E)}};return Object.freeze(O),Object.freeze(F),Object.freeze({keygen:cn(L,l),getPublicKey:l,sign:x,verify:B,utils:F,Point:r,lengths:O})}function vr(r,t){if(At(r),At(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 Pu(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 ku(r){if(!he(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?on(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function Yo(r,t,e,n){M(r),At(e),t=ku(t),t.length>255&&(t=n(J(on("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=J(t,vr(t.length,1)),c=new Uint8Array(s),f=vr(e,2),d=new Array(i),h=n(J(c,r,f,vr(0,1),a));d[0]=n(J(h,vr(1,1),a));for(let p=1;p<i;p++){let b=[Pu(h,d[p-1]),vr(p+1,1),a];d[p]=n(J(...b))}return J(...d).slice(0,e)}var Sa="HashToScalar-";var Fu=BigInt(0),qt=BigInt(1),va=BigInt(2);var Nu=BigInt(5),Uu=BigInt(8),Ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Jo={p:Ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Uu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Mu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ve,a=r*r%s*r%s,c=j(a,va,s)*a%s,f=j(c,qt,s)*r%s,d=j(f,Nu,s)*f%s,h=j(d,t,s)*d%s,u=j(h,e,s)*h%s,p=j(u,n,s)*u%s,b=j(p,o,s)*p%s,w=j(b,o,s)*p%s,m=j(w,t,s)*d%s;return{pow_p_5_8:j(m,va,s)*r%s,b2:a}}function zu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Xo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ts(r,t){let e=Ve,n=X(t*t*t,e),o=X(n*n*t,e),s=Mu(r*o).pow_p_5_8,i=X(r*n*s,e),a=X(t*i*i,e),c=i,f=X(i*Xo,e),d=a===r,h=a===X(-r,e),u=a===X(-r*Xo,e);return d&&(i=c),(h||u)&&(i=f),Kt(i,e)&&(i=X(-i,e)),{isValid:d||h,value:i}}var oe=wa(Jo,{uvRatio:ts}),ne=oe.Fp,Ia=oe.Fn;function Ku(r){return Ea(oe,Jr,Object.assign({adjustScalarBytes:zu,zip215:!0},r))}var Ba=Ku({});var Wo=Xo,qu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Vu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Hu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ju=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),_a=r=>ts(qt,r),$u=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Qo=r=>ne.create(Ot(r)&$u);function Aa(r){let{d:t}=Jo,e=Ve,n=l=>ne.create(l),o=n(Wo*r*r),s=n((o+qt)*Hu),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=ts(s,a),d=n(f*r);Kt(d,e)||(d=n(-d)),c||(f=d),c||(i=o);let h=n(i*(o-qt)*ju-a),u=f*f,p=n((f+f)*a),b=n(h*qu),w=n(qt-u),m=n(qt+u);return new oe(n(p*m),n(w*b),n(b*m),n(p*w))}var se=class r extends fn{static BASE=new r(oe.BASE);static ZERO=new r(oe.ZERO);static Fp=ne;static Fn=Ia;constructor(t){super(t)}static fromAffine(t){return new r(oe.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){bt(t,32);let{a:e,d:n}=Jo,o=Ve,s=I=>ne.create(I),i=Qo(t);if(!ea(ne.toBytes(i),t)||Kt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(qt+e*a),f=s(qt-e*a),d=s(c*c),h=s(f*f),u=s(e*n*d-h),{isValid:p,value:b}=_a(s(u*h)),w=s(b*f),m=s(b*w*u),l=s((i+i)*w);Kt(l,o)&&(l=s(-l));let g=s(c*m),x=s(l*g);if(!p||Kt(x,o)||g===Fu)throw new Error("invalid ristretto255 encoding 2");return new r(new oe(l,g,qt,x))}static fromHex(t){return r.fromBytes(hr(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=Ve,i=m=>ne.create(m),a=i(i(n+e)*i(n-e)),c=i(t*e),f=i(c*c),{value:d}=_a(i(a*f)),h=i(d*a),u=i(d*c),p=i(h*u*o),b;if(Kt(o*p,s)){let m=i(e*Wo),l=i(t*Wo);t=m,e=l,b=i(h*Vu)}else b=u;Kt(t*p,s)&&(e=i(-e));let w=i((n-e)*b);return Kt(w,s)&&(w=i(-w)),ne.toBytes(w)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>ne.create(f),a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Object.freeze(se.BASE);Object.freeze(se.ZERO);Object.freeze(se.prototype);Object.freeze(se);var Zu=Object.freeze({Point:se,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Yo(r,e,64,Jr);return Zu.deriveToCurve(n)},hashToScalar(r,t={DST:Sa}){let e=Yo(r,t.DST,64,Jr);return Ia.create(Ot(e))},deriveToCurve(r){bt(r,64);let t=Qo(r.subarray(0,32)),e=Aa(t),n=Qo(r.subarray(32,64)),o=Aa(n);return new se(e.add(o))}});var _r=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},un=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ln={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new un("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 dn=32;var es,Gu=(async()=>{try{return await ln.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Yu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await ln.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await ln.get().subtle.verify({name:"Ed25519"},n,St(t),St(e instanceof Uint8Array?e:e.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Xu(r,t,e){return Ba.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Ta(r,t,e){return es==null&&(es=await Gu),es?Yu(r,t,e):Xu(r,t,e)}function hn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var pn=class{type="Ed25519";raw;constructor(t){this.raw=rs(t,dn)}toMultihash(){return Et.digest(Pe(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:ft(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Ta(this.raw,e,t);return hn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Da(r){return r=rs(r,dn),new pn(r)}function rs(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new ht(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Qu=Math.pow(2,7),Ju=Math.pow(2,14),tl=Math.pow(2,21),ns=Math.pow(2,28),os=Math.pow(2,35),ss=Math.pow(2,42),is=Math.pow(2,49),K=128,lt=127;function gt(r){if(r<Qu)return 1;if(r<Ju)return 2;if(r<tl)return 3;if(r<ns)return 4;if(r<os)return 5;if(r<ss)return 6;if(r<is)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function He(r,t,e=0){switch(gt(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 el(r,t,e=0){switch(gt(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 as(r,t){let e=r[t],n=0;if(n+=e&lt,e<K||(e=r[t+1],n+=(e&lt)<<7,e<K)||(e=r[t+2],n+=(e&lt)<<14,e<K)||(e=r[t+3],n+=(e&lt)<<21,e<K)||(e=r[t+4],n+=(e&lt)*ns,e<K)||(e=r[t+5],n+=(e&lt)*os,e<K)||(e=r[t+6],n+=(e&lt)*ss,e<K)||(e=r[t+7],n+=(e&lt)*is,e<K))return n;throw new RangeError("Could not decode varint")}function rl(r,t){let e=r.get(t),n=0;if(n+=e&lt,e<K||(e=r.get(t+1),n+=(e&lt)<<7,e<K)||(e=r.get(t+2),n+=(e&lt)<<14,e<K)||(e=r.get(t+3),n+=(e&lt)<<21,e<K)||(e=r.get(t+4),n+=(e&lt)*ns,e<K)||(e=r.get(t+5),n+=(e&lt)*os,e<K)||(e=r.get(t+6),n+=(e&lt)*ss,e<K)||(e=r.get(t+7),n+=(e&lt)*is,e<K))return n;throw new RangeError("Could not decode varint")}function Ca(r,t,e=0){return t==null&&(t=ut(gt(r))),t instanceof Uint8Array?He(r,t,e):el(r,t,e)}function Ar(r,t=0){return r instanceof Uint8Array?as(r,t):rl(r,t)}var cs=new Float32Array([-0]),ie=new Uint8Array(cs.buffer);function Oa(r,t,e){cs[0]=r,t[e]=ie[0],t[e+1]=ie[1],t[e+2]=ie[2],t[e+3]=ie[3]}function Pa(r,t){return ie[0]=r[t],ie[1]=r[t+1],ie[2]=r[t+2],ie[3]=r[t+3],cs[0]}var fs=new Float64Array([-0]),dt=new Uint8Array(fs.buffer);function ka(r,t,e){fs[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 Fa(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],fs[0]}var nl=BigInt(Number.MAX_SAFE_INTEGER),ol=BigInt(Number.MIN_SAFE_INTEGER),xt=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<nl&&t>ol)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>Na&&(o=0n,++n>Na&&(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 xt(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var Na=4294967296n;function Ua(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 Ma(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 us(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 Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function mn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ls=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=St(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,Bt(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 Bt(this,4);return mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=Pa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=Fa(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 Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ma(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(0,0),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 Bt(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 Bt(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 Bt(this,8);let t=mn(this.buf,this.pos+=4),e=mn(this.buf,this.pos+=4);return new xt(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=as(this.buf,this.pos);return this.pos+=gt(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 Ir(r){return new ls(r instanceof Uint8Array?r:r.subarray())}function Vt(r,t,e){let n=Ir(r);return t.decode(n,void 0,e)}function ds(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ut(i);o+i>t&&(n=ut(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var xe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function hs(){}var ms=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},sl=ds();function il(r){return globalThis.Buffer!=null?ut(r):sl(r)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new xe(hs,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new xe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new gs((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(gn,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(gn,e.length(),e)}uint64Number(t){return this._push(He,gt(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=xt.fromBigInt(t).zzEncode();return this._push(gn,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(gn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ps,1,t?1:0)}fixed32(t){return this._push(Br,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(Br,4,e.lo)._push(Br,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push(Br,4,e.lo)._push(Br,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Oa,4,t)}double(t){return this._push(ka,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ps,1,0):this.uint32(e)._push(cl,e,t)}string(t){let e=Ua(t);return e!==0?this.uint32(e)._push(us,e,t):this._push(ps,1,0)}fork(){return this.states=new ms(this),this.head=this.tail=new xe(hs,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new xe(hs,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=il(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ps(r,t,e){t[e]=r&255}function al(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var gs=class extends xe{next;constructor(t,e){super(al,t,e),this.next=void 0}};function gn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Br(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function cl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(fl,t,r),this},Tr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ul,t,r),this});function fl(r,t,e){t.set(r,e)}function ul(r,t,e){r.length<40?us(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(H(r),e)}function ys(){return new Tr}function Ht(r,t){let e=ys();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*jt(r,t,e){let n=Ir(r);yield*t.stream(n,void 0,"$",e)}var yn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function bn(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function je(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 bn("enum",yn.VARINT,e,n,o)}function $t(r,t,e){return bn("message",yn.LENGTH_DELIMITED,r,t,e)}var Lr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var pt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(pt||(pt={}));var bs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(bs||(bs={}));(function(r){r.codec=()=>je(bs)})(pt||(pt={}));var Dr;(function(r){let t;r.codec=()=>(t==null&&(t=$t((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Ht(s,r.codec())}r.encode=e;function n(s,i){return Vt(s,r.codec(),i)}r.decode=n;function o(s,i){return jt(s,r.codec(),i)}r.stream=o})(Dr||(Dr={}));var xs;(function(r){let t;r.codec=()=>(t==null&&(t=$t((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Ht(s,r.codec())}r.encode=e;function n(s,i){return Vt(s,r.codec(),i)}r.decode=n;function o(s,i){return jt(s,r.codec(),i)}r.stream=o})(xs||(xs={}));var xn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(Gr(t),bt(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),Mt(o)}update(t){return ke(this),this.iHash.update(t),this}digestInto(t){ke(this),Yr(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()}},Ka=(()=>{let r=((t,e,n)=>new xn(t,e).update(n).digest());return r.create=(t,e)=>new xn(t,e),r})();var qa=(r,t)=>(r+(r>=0?t:-t)/Va)/t;function dl(r,t,e){Ue("scalar",r,Pt,e);let[[n,o],[s,i]]=t,a=qa(i*r,e),c=qa(-o*r,e),f=r-a*n-c*s,d=-a*o-c*i,h=f<Pt,u=d<Pt;h&&(f=-f),u&&(d=-d);let p=wr(Math.ceil(Me(e)/2))+ae;if(f<Pt||f>=p||d<Pt||d>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:u,k2:d}}function Es(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ws(r,t){It(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return _t(e.lowS,"lowS"),_t(e.prehash,"prehash"),e.format!==void 0&&Es(e.format),e}var Ss=class extends Error{constructor(t=""){super(t)}},Tt={Err:Ss,_tlv:{encode:(r,t)=>{let{Err:e}=Tt;if(At(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=br(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?br(o.length/2|128):"";return br(r)+s+o+t},decode(r,t){let{Err:e}=Tt;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 f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of f)i=i<<8|d;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}=Tt;if(rn(r),r<Pt)throw new t("integer: negative integers are not allowed");let e=br(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}=Tt;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 pe(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Tt,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:f,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Tt,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(Tt._tlv);Object.freeze(Tt._int);Object.freeze(Tt);var Pt=BigInt(0),ae=BigInt(1),Va=BigInt(2),wn=BigInt(3),hl=BigInt(4);function Ha(r,t={}){let e=an("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;It(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:f}=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 d=$a(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(F,y,E){if(f&&y.is0())return Uint8Array.of(0);let{x:_,y:v}=y.toAffine(),S=n.toBytes(_);if(_t(E,"isCompressed"),E){h();let A=!n.isOdd(v);return J(ja(A),S)}else return J(Uint8Array.of(4),S,n.toBytes(v))}function p(F){M(F,void 0,"Point");let{publicKey:y,publicKeyUncompressed:E}=d,_=F.length,v=F[0],S=F.subarray(1);if(f&&_===1&&v===0)return{x:n.ZERO,y:n.ZERO};if(_===y&&(v===2||v===3)){let A=n.fromBytes(S);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let D=m(A),T;try{T=n.sqrt(D)}catch(U){let z=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}h();let R=n.isOdd(T);return(v&1)===1!==R&&(T=n.neg(T)),{x:A,y:T}}else if(_===E&&v===4){let A=n.BYTES,D=n.fromBytes(S.subarray(0,A)),T=n.fromBytes(S.subarray(A,A*2));if(!l(D,T))throw new Error("bad point: is not on curve");return{x:D,y:T}}else throw new Error(`bad point: got length ${_}, expected compressed=${y} or uncompressed=${E}`)}let b=t.toBytes===void 0?u:t.toBytes,w=t.fromBytes===void 0?p:t.fromBytes;function m(F){let y=n.sqr(F),E=n.mul(y,F);return n.add(n.add(E,n.mul(F,s.a)),s.b)}function l(F,y){let E=n.sqr(y),_=m(F);return n.eql(E,_)}if(!l(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,wn),hl),x=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,x)))throw new Error("bad curve params: a or b");function I(F,y,E=!1){if(!n.isValid(y)||E&&n.is0(y))throw new Error(`bad point coordinate ${F}`);return y}function B(F){if(!(F instanceof L))throw new Error("Weierstrass Point expected")}function C(F){if(!c||!c.basises)throw new Error("no endo");return dl(F,c.basises,o.ORDER)}function O(F,y,E,_,v){return E=new L(n.mul(E.X,F),E.Y,E.Z),y=Sr(_,y),E=Sr(v,E),y.add(E)}class L{static BASE=new L(s.Gx,s.Gy,n.ONE);static ZERO=new L(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,E,_){this.X=I("x",y),this.Y=I("y",E,!0),this.Z=I("z",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:E,y:_}=y||{};if(!y||!n.isValid(E)||!n.isValid(_))throw new Error("invalid affine point");if(y instanceof L)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(_)?L.ZERO:new L(E,_,n.ONE)}static fromBytes(y){let E=L.fromAffine(w(M(y,void 0,"point")));return E.assertValidity(),E}static fromHex(y){return L.fromBytes(Ne(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,E=!0){return q.createCache(this,y),E||this.multiply(wn),this}assertValidity(){let y=this;if(y.is0()){if(t.allowInfinityPoint&&n.is0(y.X)&&n.eql(y.Y,n.ONE)&&n.is0(y.Z))return;throw new Error("bad point: ZERO")}let{x:E,y:_}=y.toAffine();if(!n.isValid(E)||!n.isValid(_))throw new Error("bad point: x or y not field elements");if(!l(E,_))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){B(y);let{X:E,Y:_,Z:v}=this,{X:S,Y:A,Z:D}=y,T=n.eql(n.mul(E,D),n.mul(S,v)),R=n.eql(n.mul(_,D),n.mul(A,v));return T&&R}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b:E}=s,_=n.mul(E,wn),{X:v,Y:S,Z:A}=this,D=n.ZERO,T=n.ZERO,R=n.ZERO,P=n.mul(v,v),U=n.mul(S,S),z=n.mul(A,A),N=n.mul(v,S);return N=n.add(N,N),R=n.mul(v,A),R=n.add(R,R),D=n.mul(y,R),T=n.mul(_,z),T=n.add(D,T),D=n.sub(U,T),T=n.add(U,T),T=n.mul(D,T),D=n.mul(N,D),R=n.mul(_,R),z=n.mul(y,z),N=n.sub(P,z),N=n.mul(y,N),N=n.add(N,R),R=n.add(P,P),P=n.add(R,P),P=n.add(P,z),P=n.mul(P,N),T=n.add(T,P),z=n.mul(S,A),z=n.add(z,z),P=n.mul(z,N),D=n.sub(D,P),R=n.mul(z,U),R=n.add(R,R),R=n.add(R,R),new L(D,T,R)}add(y){B(y);let{X:E,Y:_,Z:v}=this,{X:S,Y:A,Z:D}=y,T=n.ZERO,R=n.ZERO,P=n.ZERO,U=s.a,z=n.mul(s.b,wn),N=n.mul(E,S),Q=n.mul(_,A),tt=n.mul(v,D),et=n.add(E,_),G=n.add(S,A);et=n.mul(et,G),G=n.add(N,Q),et=n.sub(et,G),G=n.add(E,v);let mt=n.add(S,D);return G=n.mul(G,mt),mt=n.add(N,tt),G=n.sub(G,mt),mt=n.add(_,v),T=n.add(A,D),mt=n.mul(mt,T),T=n.add(Q,tt),mt=n.sub(mt,T),P=n.mul(U,G),T=n.mul(z,tt),P=n.add(T,P),T=n.sub(Q,P),P=n.add(Q,P),R=n.mul(T,P),Q=n.add(N,N),Q=n.add(Q,N),tt=n.mul(U,tt),G=n.mul(z,G),Q=n.add(Q,tt),tt=n.sub(N,tt),tt=n.mul(U,tt),G=n.add(G,tt),N=n.mul(Q,G),R=n.add(R,N),N=n.mul(mt,G),T=n.mul(et,T),T=n.sub(T,N),N=n.mul(et,Q),P=n.mul(mt,P),P=n.add(P,N),new L(T,R,P)}subtract(y){return B(y),this.add(y.negate())}is0(){return this.equals(L.ZERO)}multiply(y){let{endo:E}=t;if(!o.isValidNot0(y))throw new RangeError("invalid scalar: out of range");let _,v,S=A=>q.cached(this,A,D=>ye(L,D));if(E){let{k1neg:A,k1:D,k2neg:T,k2:R}=C(y),{p:P,f:U}=S(D),{p:z,f:N}=S(R);v=U.add(N),_=O(E.beta,P,z,A,T)}else{let{p:A,f:D}=S(y);_=A,v=D}return ye(L,[_,v])[0]}multiplyUnsafe(y){let{endo:E}=t,_=this,v=y;if(!o.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===Pt||_.is0())return L.ZERO;if(v===ae)return _;if(q.hasCache(this))return this.multiply(v);if(E){let{k1neg:S,k1:A,k2neg:D,k2:T}=C(v),{p1:R,p2:P}=xa(L,_,A,T);return O(E.beta,R,P,S,D)}else return q.unsafe(_,v)}toAffine(y){let E=this,_=y,{X:v,Y:S,Z:A}=E;if(n.eql(A,n.ONE))return{x:v,y:S};let D=E.is0();_==null&&(_=D?n.ONE:n.inv(A));let T=n.mul(v,_),R=n.mul(S,_),P=n.mul(A,_);if(D)return{x:n.ZERO,y:n.ZERO};if(!n.eql(P,n.ONE))throw new Error("invZ was invalid");return{x:T,y:R}}isTorsionFree(){let{isTorsionFree:y}=t;return i===ae?!0:y?y(L,this):q.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=t;return i===ae?this:y?y(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ae?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return _t(y,"isCompressed"),this.assertValidity(),b(L,this,y)}toHex(y=!0){return Fe(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let k=o.BITS,q=new qe(L,t.endo?Math.ceil(k/2):k);return k>=8&&L.BASE.precompute(8),Object.freeze(L.prototype),Object.freeze(L),L}function ja(r){return Uint8Array.of(r?2:3)}function $a(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function pl(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?yr:t.randomBytes,o=Object.assign($a(r.Fp,e),{seed:Math.max(Vo(e.ORDER),16)});function s(p){try{let b=e.fromBytes(p);return e.isValidNot0(b)}catch{return!1}}function i(p,b){let{publicKey:w,publicKeyUncompressed:m}=o;try{let l=p.length;return b===!0&&l!==w||b===!1&&l!==m?!1:!!r.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Ho(M(p,o.seed,"seed"),e.ORDER)}function c(p,b=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(b)}function f(p){let{secretKey:b,publicKey:w,publicKeyUncompressed:m}=o,l=e._lengths;if(!he(p))return;let g=M(p,void 0,"key").length,x=g===w||g===m,I=g===b||!!l?.includes(g);if(!(x&&I))return x}function d(p,b,w=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(b)===!1)throw new Error("second arg must be public key");let m=e.fromBytes(p);return r.fromBytes(b).multiply(m).toBytes(w)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},u=cn(a,c);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:u,Point:r,utils:h,lengths:o})}function Za(r,t,e={}){let n=t;Gr(n),It(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?yr:e.randomBytes,s=e.hmac===void 0?(v,S)=>Ka(n,v,S):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:f}=a,{keygen:d,getPublicKey:h,getSharedSecret:u,utils:p,lengths:b}=pl(r,e),w={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},m=c*Va+ae<i.ORDER;function l(v){let S=c>>ae;return v>S}function g(v,S){if(!a.isValidNot0(S))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return S}function x(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function I(v,S){Es(S);let A=b.signature,D=S==="compact"?A:S==="recovered"?A+1:void 0;return M(v,D)}class B{r;s;recovery;constructor(S,A,D){if(this.r=g("r",S),this.s=g("s",A),D!=null){if(x(),![0,1,2,3].includes(D))throw new Error("invalid recovery id");this.recovery=D}Object.freeze(this)}static fromBytes(S,A=w.format){I(S,A);let D;if(A==="der"){let{r:U,s:z}=Tt.toSig(M(S));return new B(U,z)}A==="recovered"&&(D=S[0],A="compact",S=S.subarray(1));let T=b.signature/2,R=S.subarray(0,T),P=S.subarray(T,T*2);return new B(a.fromBytes(R),a.fromBytes(P),D)}static fromHex(S,A){return this.fromBytes(Ne(S),A)}assertRecovery(){let{recovery:S}=this;if(S==null)throw new Error("invalid recovery id: must be present");return S}addRecoveryBit(S){return new B(this.r,this.s,S)}recoverPublicKey(S){let{r:A,s:D}=this,T=this.assertRecovery(),R=T===2||T===3?A+c:A;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=i.toBytes(R),U=r.fromBytes(J(ja((T&1)===0),P)),z=a.inv(R),N=O(M(S,void 0,"msgHash")),Q=a.create(-N*z),tt=a.create(D*z),et=r.BASE.multiplyUnsafe(Q).add(U.multiplyUnsafe(tt));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return l(this.s)}toBytes(S=w.format){if(Es(S),S==="der")return Ne(Tt.hexFromSig(this));let{r:A,s:D}=this,T=a.toBytes(A),R=a.toBytes(D);return S==="recovered"?(x(),J(Uint8Array.of(this.assertRecovery()),T,R)):J(T,R)}toHex(S){return Fe(this.toBytes(S))}}Object.freeze(B.prototype),Object.freeze(B);let C=e.bits2int===void 0?function(S){if(S.length>8192)throw new Error("input is too large");let A=pe(S),D=S.length*8-f;return D>0?A>>BigInt(D):A}:e.bits2int,O=e.bits2int_modN===void 0?function(S){return a.create(C(S))}:e.bits2int_modN,L=wr(f);function k(v){return Ue("num < 2^"+f,v,Pt,L),a.toBytes(v)}function q(v,S){return M(v,void 0,"message"),S?M(n(v),void 0,"prehashed message"):v}function F(v,S,A){let{lowS:D,prehash:T,extraEntropy:R}=ws(A,w);v=q(v,T);let P=O(v),U=a.fromBytes(S);if(!a.isValidNot0(U))throw new Error("invalid private key");let z=[k(U),k(P)];if(R!=null&&R!==!1){let et=R===!0?o(b.secretKey):R;z.push(M(et,void 0,"extraEntropy"))}let N=J(...z),Q=P;function tt(et){let G=C(et);if(!a.isValidNot0(G))return;let mt=a.inv(G),Be=r.BASE.multiply(G).toAffine(),nr=a.create(Be.x);if(nr===Pt)return;let Mr=a.create(mt*a.create(Q+nr*U));if(Mr===Pt)return;let oi=(Be.x===nr?0:2)|Number(Be.y&ae),si=Mr;return D&&l(Mr)&&(si=a.neg(Mr),oi^=1),new B(nr,si,m?void 0:oi)}return{seed:N,k2sig:tt}}function y(v,S,A={}){let{seed:D,k2sig:T}=F(v,S,A);return ra(n.outputLen,a.BYTES,s)(D,T).toBytes(A.format)}function E(v,S,A,D={}){let{lowS:T,prehash:R,format:P}=ws(D,w);if(A=M(A,void 0,"publicKey"),S=q(S,R),!he(v)){let U=v instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}I(v,P);try{let U=B.fromBytes(v,P),z=r.fromBytes(A);if(T&&U.hasHighS())return!1;let{r:N,s:Q}=U,tt=O(S),et=a.inv(Q),G=a.create(tt*et),mt=a.create(N*et),Be=r.BASE.multiplyUnsafe(G).add(z.multiplyUnsafe(mt));return Be.is0()?!1:a.create(Be.x)===N}catch{return!1}}function _(v,S,A={}){let{prehash:D}=ws(A,w);return S=q(S,D),B.fromBytes(v,"recovered").recoverPublicKey(S).toBytes()}return Object.freeze({keygen:d,getPublicKey:h,getSharedSecret:u,utils:p,lengths:b,Point:r,sign:y,verify:E,recoverPublicKey:_,Signature:B,hash:n})}var _s={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ml={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ga=BigInt(2);function gl(r){let t=_s.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,d=f*f*r%t,h=j(d,e,t)*d%t,u=j(h,e,t)*d%t,p=j(u,Ga,t)*f%t,b=j(p,o,t)*p%t,w=j(b,s,t)*b%t,m=j(w,a,t)*w%t,l=j(m,c,t)*m%t,g=j(l,a,t)*w%t,x=j(g,e,t)*d%t,I=j(x,i,t)*b%t,B=j(I,n,t)*f%t,C=j(B,Ga,t);if(!vs.eql(vs.sqr(C),r))throw new Error("Cannot find square root");return C}var vs=ze(_s.p,{sqrt:gl}),yl=Ha(_s,{Fp:vs,endo:ml}),$e=Za(yl,Ji);function Ya(r,t,e,n){let o=fr.digest(e instanceof Uint8Array?e:e.subarray());if(hn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),$e.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new _r(String(s))});try{return n?.signal?.throwIfAborted(),$e.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new _r(String(s))}}var En=class{type="secp256k1";raw;_key;constructor(t){this._key=Wa(t),this.raw=Xa(this._key)}toMultihash(){return Et.digest(Pe(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:ft(this.raw,t.raw)}verify(t,e,n){return Ya(this._key,e,t,n)}};function Qa(r){return new En(r)}function Xa(r){return $e.Point.fromBytes(r).toBytes()}function Wa(r){try{return $e.Point.fromBytes(r),r}catch(t){throw new Kr(String(t))}}function Ja(r){let{Type:t,Data:e}=Dr.decode(r.digest),n=e??new Uint8Array;switch(t){case pt.Ed25519:return Da(n);case pt.secp256k1:return Qa(n);case pt.ECDSA:return Fi(n);default:throw new or}}function Pe(r){return Dr.encode({Type:pt[r.type],Data:r.raw})}var tc=Symbol.for("nodejs.util.inspect.custom"),bl=114,Cr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Xn]=!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(bl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ft(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ft(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[tc](){return`PeerId(${this.toString()})`}},Sn=class extends Cr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},vn=class extends Cr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},_n=class extends Cr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},xl=2336,An=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Et.digest(H(this.url))}[tc](){return`PeerId(${this.url})`}[Xn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(xl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=W(t)),t.toString()===this.toString())}};function In(r){if(El(r))return new Sn({multihash:r});if(wl(r))try{let t=Ja(r);if(t.type==="Ed25519")return new vn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new _n({multihash:r,publicKey:t})}catch{let e=W(r.digest);return new An(new URL(e))}throw new qr("Supplied PeerID Multihash is invalid")}function wl(r){return r.code===Et.code}function El(r){return r.code===fr.code}function As(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 Bn(r){let t=ue(Y.decode(`z${r}`));return In(t)}var Tn=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 As(this.set.entries(),t=>{let e=Bn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Bn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return As(this.set.values(),t=>Bn(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 Is(){return new Tn}var Bs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ec={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},rc=new globalThis.TextEncoder;function Sl(r,t){let e=Bs[t],n=ec[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function vl(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Bs[t],o=ec[t],s=r;for(;s.length>0;){let i=rc.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 Ts(r,{size:t=32,utf8Buffer:e}={}){if(!Bs[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 vl(r,t,e);r=rc.encode(r)}return Sl(r,t)}var Rr={hash:r=>Number(Ts(r,{size:32})),hashV:(r,t)=>_l(Rr.hash(r,t))};function _l(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),H(t,"base16")}var Ls=64,Lt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Ls)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=wt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ft(this.fp,t.fp):!1}};function we(r,t){return Math.floor(Math.random()*(t-r))+r}var Ee=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Lt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Lt))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 Lt))throw new TypeError("Invalid Fingerprint");let e=we(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Lt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Al=500,Or=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??Rr,this.seed=t.seed??we(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=H(t));let e=new Lt(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 Ee(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Ee(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[we(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Ee(this.bucketSize));for(let a=0;a<Al;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 Ee(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=H(t));let e=new Lt(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=H(t));let e=new Lt(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}},Il={1:.5,2:.84,4:.95,8:.98};function Bl(r=.001){return r>.002?2:r>1e-5?4:8}function nc(r,t=.001){let e=Bl(t),n=Il[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Ls);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Ln=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??Rr,this.seed=t.seed??we(0,Math.pow(2,10)),this.filterSeries=[new Or({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=H(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 Or({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=H(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=H(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 Ds(r,t=.001,e){return new Ln({...nc(r,t),...e??{}})}function Tl(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 Dt(r){let t=Tl(r);if(t==null)throw new ht(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var Dn=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",f=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let u=Number.parseInt(h,t);if(!Number.isNaN(u))return u});if(d===void 0)break;if(s*=t,s+=d,s>f||(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 oc=45,Ll=15,Ze=new Dn;function Cn(r){if(!(r.length>Ll))return Ze.new(r).parseWith(()=>Ze.readIPv4Addr())}function Rn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>oc))return Ze.new(r).parseWith(()=>Ze.readIPv6Addr())}function Ge(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>oc)return;let e=Ze.new(r).parseWith(()=>Ze.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 sc(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function ic(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Cs(r){switch(r.length){case Se:return r.join(".");case ve:{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 ac(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 cc(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Se=4,ve=16,Vy=parseInt("0xFFFF",16),Dl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Pr(r,t){t.length===ve&&r.length===Se&&sc(t,0,11)&&(t=t.slice(12)),t.length===Se&&r.length===ve&&ic(r,Dl,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 fc(r,t){if(typeof t=="string"&&(t=Ge(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 Rs(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Se,o=Cn(t);if(o==null&&(n=ve,o=Rn(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=Os(s,8*n);return{network:Pr(o,i),mask:i}}function Os(r,t){if(t!==8*Se&&t!==8*ve)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 kr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Rs(t));else{let n=Ge(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=Ge(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Os(o,8*n.length);this.network=Pr(n,this.mask)}}contains(t){return fc({network:this.network,mask:this.mask},t)}toString(){let t=ac(this.mask),e=t!==-1?String(t):cc(this.mask);return Cs(this.network)+"/"+e}};function uc(r,t){return new kr(r).contains(t)}function lc(r){try{let t=Dt(r);return t.type==="ip6"?uc("2000::/3",t.host):!1}catch{return!1}}function Ye(r){return!!Cn(r)}function On(r){return!!Rn(r)}var mc=qc(pc(),1),Nl=["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"],Ul=Nl.map(r=>new mc.Netmask(r));function zs(r){for(let t of Ul)if(t.contains(r))return!0;return!1}function Ml(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function zl(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 zs(o)}function Kl(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function ql(r){let t=r.split(":"),e=t[t.length-1];return zs(e)}function Vl(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 gc(r){if(Ye(r))return zs(r);if(Ml(r))return zl(r);if(Kl(r))return ql(r);if(On(r))return Vl(r)}function Ks(r){try{let t=Dt(r);switch(t.type){case"ip4":case"ip6":return gc(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var at=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Zt=class extends Error{static name="ValidationError";name="ValidationError"},kn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Fn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Vs(r){return t=>W(t,r)}function Hs(r){return t=>H(t,r)}function Je(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Ae(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function yc(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=H(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ae(n);return Ct([e,o],e.length+o.length)}function bc(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=Xt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ae(n);return Ct([e,o],e.length+o.length)}function js(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=W(t,"base32"),o=Je(e);return`${n}:${o}`}var $s=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 at("Invalid byte value in IP address");t[n]=o}),t},xc=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Ye(e[n]),i;s&&(i=$s(e[n]),e[n]=W(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,W(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 at("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},wc=function(r){if(r.byteLength!==4)throw new at("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Ec=function(r){if(r.byteLength!==16)throw new at("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 at(`Invalid IPv6 address "${e}"`)}};function Sc(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new at(`Invalid IPv6 address "${r}"`)}}var qs=Object.values(ur).map(r=>r.decoder),Hl=(function(){let r=qs[0].or(qs[1]);return qs.slice(2).forEach(t=>r=r.or(t)),r})();function vc(r){return Hl.decode(r)}function _c(r){return t=>r.encoder.encode(t)}function jl(r){if(parseInt(r).toString()!==r)throw new Zt("Value must be an integer")}function $l(r){if(r<0)throw new Zt("Value must be a positive integer, or zero")}function Zl(r){return t=>{if(t>r)throw new Zt(`Value must be smaller than or equal to ${r}`)}}function Gl(...r){return t=>{for(let e of r)e(t)}}var Fr=Gl(jl,$l,Zl(65535));var ot=-1,Zs=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 Fn(`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)}))}},Gt=new Zs,Pd=[{code:4,name:"ip4",size:32,valueToBytes:$s,bytesToValue:wc,validate:r=>{if(!Ye(r))throw new Zt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ae,bytesToValue:Je,validate:Fr},{code:273,name:"udp",size:16,valueToBytes:Ae,bytesToValue:Je,validate:Fr},{code:33,name:"dccp",size:16,valueToBytes:Ae,bytesToValue:Je,validate:Fr},{code:41,name:"ip6",size:128,valueToBytes:xc,bytesToValue:Ec,stringToValue:Sc,validate:r=>{if(!On(r))throw new Zt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ot},{code:43,name:"ipcidr",size:8,bytesToValue:Vs("base10"),valueToBytes:Hs("base10")},{code:53,name:"dns",size:ot},{code:54,name:"dns4",size:ot},{code:55,name:"dns6",size:ot},{code:56,name:"dnsaddr",size:ot},{code:132,name:"sctp",size:16,valueToBytes:Ae,bytesToValue:Je,validate:Fr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ot,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ot,bytesToValue:Vs("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Hs("base58btc")(r):ct.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:js,valueToBytes:yc},{code:445,name:"onion3",size:296,bytesToValue:js,valueToBytes:bc},{code:446,name:"garlic64",size:ot},{code:447,name:"garlic32",size:ot},{code:448,name:"tls"},{code:449,name:"sni",size:ot},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ot,bytesToValue:_c(ho),valueToBytes:vc},{code:480,name:"http"},{code:481,name:"http-path",size:ot,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:ot}];Pd.forEach(r=>{Gt.addProtocol(r)});function Ac(r){let t=[],e=0;for(;e<r.length;){let n=Ar(r,e),o=Gt.getProtocol(n),s=gt(n),i=kd(o,r,e+s),a=0;i>0&&o.size===ot&&(a=gt(i));let c=s+a+i,f={code:n,name:o.name,bytes:St(r.subarray(e,e+c))};if(i>0){let d=e+s+a,h=r.subarray(d,d+i);f.value=o.bytesToValue?.(h)??W(h)}t.push(f),e+=c}return t}function Ic(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Gt.getProtocol(n.code),s=gt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??H(n.value),a=i.byteLength,o.size===ot&&(c=gt(a)));let f=new Uint8Array(s+c+a),d=0;He(n.code,f,d),d+=s,i!=null&&(o.size===ot&&(He(a,f,d),d+=c),f.set(i,d)),n.bytes=f}e.push(n.bytes),t+=n.bytes.byteLength}return Ct(e,t)}function Bc(r){if(r.charAt(0)!=="/")throw new at('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=Gt.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 at(`Component ${o} was missing value`);e="value"}else if(e==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new at(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new at("Incomplete multiaddr");return t}function Tc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Gt.getProtocol(t.code);if(e==null)throw new at(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function kd(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Ar(t,e)}var Fd=Symbol.for("nodejs.util.inspect.custom"),Gs=Symbol.for("@multiformats/multiaddr");function Nd(r){if(r==null&&(r="/"),Lc(r))return r.getComponents();if(r instanceof Uint8Array)return Ac(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Bc(r);if(Array.isArray(r))return r;throw new at("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Un=class r{[Gs]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Nd(t),e.validate!==!1&&Ud(this)}get bytes(){return this.#r==null&&(this.#r=Ic(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Tc(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 kn(`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 ft(this.bytes,t.bytes)}[Fd](){return`Multiaddr(${this.toString()})`}};function Ud(r){r.getComponents().forEach(t=>{let e=Gt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function Lc(r){return!!r?.[Gs]}function Dc(r){return new Un(r)}function tr(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Mn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},er=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Mn(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 Mn(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 Ys=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function zn(r={}){return Md(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 Md(r,t){t=t??{};let e=t.onEnd,n=new er,o,s,i,a=tr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,l)=>{s=g=>{s=null,n.push(g);try{m(r(n))}catch(x){l(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=tr()})}},f=m=>s!=null?s(m):(n.push(m),o),d=m=>(n=new er,s!=null?s({error:m}):(n.push({error:m}),o)),h=m=>{if(i)return o;if(t?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:m})},u=m=>i?o:(i=!0,m!=null?d(m):f({done:!0})),p=()=>(n=new er,u(),{done:!0}),b=m=>(u(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:b,push:h,end:u,get readableLength(){return n.size},onEmpty:async m=>{let l=m?.signal;if(l?.throwIfAborted(),n.isEmpty())return;let g,x;l!=null&&(g=new Promise((I,B)=>{x=()=>{B(new Ys)},l.addEventListener("abort",x)}));try{await Promise.race([a.promise,g])}finally{x!=null&&l!=null&&l?.removeEventListener("abort",x)}}},e==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(m){return w.throw(m),e!=null&&(e(m),e=void 0),{done:!0}},return(){return w.return(),e!=null&&(e(),e=void 0),{done:!0}},push:h,end(m){return w.end(m),e!=null&&(e(m),e=void 0),o},get readableLength(){return w.readableLength},onEmpty:m=>w.onEmpty(m)},o}var Xs=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Cc=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Ws(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,d=new Promise((h,u)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){u(Cc(i));return}if(i&&(c=()=>{u(Cc(i))},i.addEventListener("abort",c,{once:!0})),r.then(h,u),e===Number.POSITIVE_INFINITY)return;let p=new Xs;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(b){u(b)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?u(o):(p.message=o??`Promise timed out after ${e} milliseconds`,u(p))},e)}).finally(()=>{d.clear(),c&&i&&i.removeEventListener("abort",c)});return d.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},d}var zd=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 Kd(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:f,removeListener:d}=zd(r),h=async(...p)=>{let b=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(b))return}catch(w){n(),i(w);return}c.push(b),e.count===c.length&&(n(),s(c))},u=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)d(p,h);for(let p of e.rejectionEvents)a.includes(p)||d(p,u)};for(let p of a)f(p,h);for(let p of e.rejectionEvents)a.includes(p)||f(p,u);e.signal&&e.signal.addEventListener("abort",()=>{u(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=Ws(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function rr(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=Kd(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Nr(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Kn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Ie=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function qd(r){return r.reason}async function Ur(r,t,e){if(t==null)return r;let n=e?.translateError??qd;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 qn=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=tr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Ft)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Vd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Vn=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,e){this.id=Vd(),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 Ft),this.cleanup())}async join(t){let e=new qn(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 Ur(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 Hn=class extends Vr{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=Nr(this.emitEmpty.bind(this),1),this.emitIdle=Nr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Kn;let n=new Vn(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 Ft)}),this.clear()}async onEmpty(t){this.size!==0&&await rr(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await rr(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await rr(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=zn({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 Ft("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 jn(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 Hd=4194304,$n=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Js=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ti=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ei=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function jd(r){return typeof r?.closeRead=="function"}function $d(r){return typeof r?.close=="function"}function Qs(r){return jd(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:$d(r)?r.status!=="open":!1}function Zd(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Gd(r,t){let e=t?.maxBufferSize??Hd,n=new rt,o,s=!1;if(!Zd(r))throw new ht("Argument should be a Stream or a Multiaddr");let i=d=>{if(n.append(d.data),n.byteLength>e){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let a=d=>{d.error!=null?o?.reject(d.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(d){if(s===!0)throw new $n("Stream was unwrapped");if(Qs(r)){if(n.byteLength===0&&d?.bytes==null)return null;if(d?.bytes!=null&&n.byteLength<d.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new Ie(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let h=d?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await Ur(o.promise,d?.signal),Qs(r)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let u=d?.bytes??n.byteLength;if(n.byteLength<u){if(Qs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,u),new Ie(`Unexpected EOF - stream closed while reading ${n.byteLength}/${u} bytes`);return f.read(d)}let p=n.sublist(0,u);return n.consume(u),p},async write(d,h){if(s===!0)throw new $n("Stream was unwrapped");r.send(d)||await rr(r,"drain",{signal:h?.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 f}function Yd(r,t={}){let e=Gd(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=gt(t.maxDataLength));let n=t?.lengthDecoder??Ar,o=t?.lengthEncoder??Ca;return{async read(i){let a=-1,c=new rt;for(;;){let d=await e.read({...i,bytes:1});if(d==null)break;c.append(d);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Js("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ei(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ti(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await e.read({...i,bytes:a});if(f==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new Ie(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Ie(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await e.write(new rt(o(i.byteLength),i),a)},async writeV(i,a){let c=new rt(...i.flatMap(f=>[o(f.byteLength),f]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function ri(r,t){let e=Yd(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 Zn=class extends Hn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Rc(r,t,e){let n,o,s=!1;function i(){let f={signal:o.signal},d;e?.timeout!=null&&(d=jn([o.signal,AbortSignal.timeout(e.timeout)]),f.signal=d),s=!0,Promise.resolve().then(async()=>{await r(f)}).catch(()=>{}).finally(()=>{d!=null&&(d.aborted?d.clear():d.addEventListener("abort",()=>{d.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Nr(i,e?.debounce??100),c=!1;return{setInterval:f=>{t!==f&&(t=f,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:f=>{e??={},e.timeout=f},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 ni=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 Oc(r){let{name:t,metrics:e}=r,n;return e!=null?n=new ni({name:t,metrics:e}):n=new Map,n}var Pc="libp2p",kc="autonat",Fc="1.0.0";var V;(function(r){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),(function(u){u.codec=()=>je(e)})(t=r.MessageType||(r.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(u){u.codec=()=>je(o)})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let p;u.codec=()=>(p==null&&(p=$t((l,g,x={})=>{if(x.lengthDelimited!==!1&&g.fork(),l.id!=null&&(g.uint32(10),g.bytes(l.id)),l.addrs!=null&&l.addrs.length>0)for(let I of l.addrs)g.uint32(18),g.bytes(I);x.lengthDelimited!==!1&&g.ldelim()},(l,g,x={})=>{let I={addrs:[]},B=g==null?l.len:l.pos+g;for(;l.pos<B;){let C=l.uint32();switch(C>>>3){case 1:{I.id=l.bytes();break}case 2:{if(x.limits?.addrs!=null&&I.addrs.length===x.limits.addrs)throw new Lr('Decode error - repeated field "addrs" had too many elements');I.addrs.push(l.bytes());break}default:{l.skipType(C&7);break}}}return I},function*(l,g,x,I={}){let B={addrs:0},C=g==null?l.len:l.pos+g;for(;l.pos<C;){let O=l.uint32();switch(O>>>3){case 1:{yield{field:`${x}.id`,value:l.bytes()};break}case 2:{if(I.limits?.addrs!=null&&B.addrs===I.limits.addrs)throw new Lr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${x}.addrs[]`,index:B.addrs,value:l.bytes()},B.addrs++;break}default:{l.skipType(O&7);break}}}})),p);function b(l){return Ht(l,u.codec())}u.encode=b;function w(l,g){return Vt(l,u.codec(),g)}u.decode=w;function m(l,g){return jt(l,u.codec(),g)}u.stream=m})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let p;u.codec=()=>(p==null&&(p=$t((l,g,x={})=>{x.lengthDelimited!==!1&&g.fork(),l.peer!=null&&(g.uint32(10),r.PeerInfo.codec().encode(l.peer,g)),x.lengthDelimited!==!1&&g.ldelim()},(l,g,x={})=>{let I={},B=g==null?l.len:l.pos+g;for(;l.pos<B;){let C=l.uint32();C>>>3===1?I.peer=r.PeerInfo.codec().decode(l,l.uint32(),{limits:x.limits?.peer}):l.skipType(C&7)}return I},function*(l,g,x,I={}){let B=g==null?l.len:l.pos+g;for(;l.pos<B;){let C=l.uint32();C>>>3===1?yield*r.PeerInfo.codec().stream(l,l.uint32(),`${x}.peer`,{limits:I.limits?.peer}):l.skipType(C&7)}})),p);function b(l){return Ht(l,u.codec())}u.encode=b;function w(l,g){return Vt(l,u.codec(),g)}u.decode=w;function m(l,g){return jt(l,u.codec(),g)}u.stream=m})(i=r.Dial||(r.Dial={}));let a;(function(u){let p;u.codec=()=>(p==null&&(p=$t((l,g,x={})=>{x.lengthDelimited!==!1&&g.fork(),l.status!=null&&(g.uint32(8),r.ResponseStatus.codec().encode(l.status,g)),l.statusText!=null&&(g.uint32(18),g.string(l.statusText)),l.addr!=null&&(g.uint32(26),g.bytes(l.addr)),x.lengthDelimited!==!1&&g.ldelim()},(l,g,x={})=>{let I={},B=g==null?l.len:l.pos+g;for(;l.pos<B;){let C=l.uint32();switch(C>>>3){case 1:{I.status=r.ResponseStatus.codec().decode(l);break}case 2:{I.statusText=l.string();break}case 3:{I.addr=l.bytes();break}default:{l.skipType(C&7);break}}}return I},function*(l,g,x,I={}){let B=g==null?l.len:l.pos+g;for(;l.pos<B;){let C=l.uint32();switch(C>>>3){case 1:{yield{field:`${x}.status`,value:r.ResponseStatus.codec().decode(l)};break}case 2:{yield{field:`${x}.statusText`,value:l.string()};break}case 3:{yield{field:`${x}.addr`,value:l.bytes()};break}default:{l.skipType(C&7);break}}}})),p);function b(l){return Ht(l,u.codec())}u.encode=b;function w(l,g){return Vt(l,u.codec(),g)}u.decode=w;function m(l,g){return jt(l,u.codec(),g)}u.stream=m})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=$t((u,p,b={})=>{b.lengthDelimited!==!1&&p.fork(),u.type!=null&&(p.uint32(8),r.MessageType.codec().encode(u.type,p)),u.dial!=null&&(p.uint32(18),r.Dial.codec().encode(u.dial,p)),u.dialResponse!=null&&(p.uint32(26),r.DialResponse.codec().encode(u.dialResponse,p)),b.lengthDelimited!==!1&&p.ldelim()},(u,p,b={})=>{let w={},m=p==null?u.len:u.pos+p;for(;u.pos<m;){let l=u.uint32();switch(l>>>3){case 1:{w.type=r.MessageType.codec().decode(u);break}case 2:{w.dial=r.Dial.codec().decode(u,u.uint32(),{limits:b.limits?.dial});break}case 3:{w.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:b.limits?.dialResponse});break}default:{u.skipType(l&7);break}}}return w},function*(u,p,b,w={}){let m=p==null?u.len:u.pos+p;for(;u.pos<m;){let l=u.uint32();switch(l>>>3){case 1:{yield{field:`${b}.type`,value:r.MessageType.codec().decode(u)};break}case 2:{yield*r.Dial.codec().stream(u,u.uint32(),`${b}.dial`,{limits:w.limits?.dial});break}case 3:{yield*r.DialResponse.codec().stream(u,u.uint32(),`${b}.dialResponse`,{limits:w.limits?.dialResponse});break}default:{u.skipType(l&7);break}}}})),c);function f(u){return Ht(u,r.codec())}r.encode=f;function d(u,p){return Vt(u,r.codec(),p)}r.decode=d;function h(u,p){return jt(u,r.codec(),p)}r.stream=h})(V||(V={}));var eh=4,rh=8,Gn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${e.protocolPrefix??Pc}/${kc}/${Fc}`,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=Oc({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=Rc(this.findRandomPeers.bind(this),6e4),this.addressFilter=Ds(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ai]=["@libp2p/autonat"];get[ci](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,e)=>{this.handleIncomingAutonatStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=jn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,e){let n=AbortSignal.timeout(this.timeout);try{let o=ri(t,{maxDataLength:this.maxMessageSize}).pb(V),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,e,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(h=>Dt(h).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("peerId missing from message"),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let h=ue(a.id);i=In(h)}catch(h){return this.log.error("invalid PeerId - %e",h),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(h=>Dc(h)).filter(h=>{try{let u=Dt(h);return Ks(h)?!1:u.host!==Dt(e.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",h,e.remoteAddr),!1):o.includes(u.host)?!1:this.components.transportManager.dialTransportForMultiaddr(h)==null?(this.log.trace("not dialing %a - transport unsupported",h),!1):!0}catch{return!1}}).map(h=>(h.getComponents().find(u=>u.code===421)?.value==null&&(h=h.encapsulate(`/p2p/${i.toString()}`)),h));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(h=>h.toString()).join(", "),i);let f="",d=c[0];for(let h of c){let u;d=h;try{if(u=await this.components.connectionManager.openConnection(h,n),!u.remoteAddr.equals(h))throw this.log.error("tried to dial %a but dialed %a",h,u.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,h),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.OK,addr:u.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),f=p.message}finally{u!=null&&await u.close()}}return{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_DIAL_ERROR,statusText:f,addr:d.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||Dt(o.multiaddr).type==="ip6"&&(!e||!lc(o.multiaddr))||Ks(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:Is(),queue:new Zn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>Dt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=ri(i).pb(V),[,c]=await Promise.all([a.write({type:V.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==V.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let f=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,f),f!==V.ResponseStatus.OK&&f!==V.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),f===V.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else f===V.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===eh&&this.confirmAddress(o),o.failure===rh&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=Dt(t);switch(e.type){case"ip4":return e.host.split(".")[0].padStart(3,"0");case"ip6":return e.host.split(":")[0].padStart(4,"0");default:throw new ht(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function nh(r={}){return t=>new Gn(t,r)}return Vc(oh);})();
2
+ "use strict";var Libp2PAutonat=(()=>{var Uc=Object.create;var zr=Object.defineProperty;var Mc=Object.getOwnPropertyDescriptor;var zc=Object.getOwnPropertyNames;var Kc=Object.getPrototypeOf,qc=Object.prototype.hasOwnProperty;var Yn=(r,t)=>()=>{try{return t||r((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}},yt=(r,t)=>{for(var e in t)zr(r,e,{get:t[e],enumerable:!0})},ii=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of zc(t))!qc.call(r,o)&&o!==e&&zr(r,o,{get:()=>t[o],enumerable:!(n=Mc(t,o))||n.enumerable});return r};var Vc=(r,t,e)=>(e=r!=null?Uc(Kc(r)):{},ii(t||!r||!r.__esModule?zr(e,"default",{value:r,enumerable:!0}):e,r)),Hc=r=>ii(zr({},"__esModule",{value:!0}),r);var ks=Yn(We=>{"use strict";Object.defineProperty(We,"__esModule",{value:!0});We.Netmask4Impl=void 0;We.ip2long=Xe;We.long2ip=Ft;function Ft(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 Rl=48,Ol=97,Pl=65;function kl(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)-Rl)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-Ol)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.charCodeAt(o)-Pl)>>>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 Xe(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]=kl(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 Ps=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=Xe(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=(Xe(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=Ft(this.netLong),this.mask=Ft(this.maskLong),this.hostmask=Ft(~this.maskLong),this.first=this.bitmask<=30?Ft(this.netLong+1):this.base,this.last=this.bitmask<=30?Ft(this.netLong+this.size-2):Ft(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Ft(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):(Xe(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(Ft(this.netLong+this.size*t),this.mask)}forEach(t){let e=Xe(this.first),n=Xe(this.last),o=0;for(;e<=n;)t(Ft(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};We.Netmask4Impl=Ps});var pc=Yn(Qe=>{"use strict";Object.defineProperty(Qe,"__esModule",{value:!0});Qe.Netmask6Impl=void 0;Qe.ip6bigint=Ns;Qe.bigint2ip6=_e;var Fl=ks(),Fs=(1n<<128n)-1n;function Ns(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,Fl.ip2long)(n),s=r.substring(0,e+1)+"0:0";return hc(s)&~0xffffffffn|BigInt(o)}return hc(r)}function hc(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 _e(r){if(r<0n||r>Fs)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 Us=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=Fs>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ns(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=_e(this.netBigint),this.mask=_e(this.maskBigint),this.hostmask=_e(~this.maskBigint&Fs),this.first=this.base,this.last=_e(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.last):(Ns(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(_e(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(_e(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};Qe.Netmask6Impl=Us});var mc=Yn(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.long2ip=ce.ip2long=ce.Netmask=void 0;var Pn=ks();Object.defineProperty(ce,"ip2long",{enumerable:!0,get:function(){return Pn.ip2long}});Object.defineProperty(ce,"long2ip",{enumerable:!0,get:function(){return Pn.long2ip}});var Nl=pc(),Ms=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 Nl.Netmask6Impl(t,e):this._impl=new Pn.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 Pn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new r(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new r(t))),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let e=this._impl.next(t);return new r(e.base,e.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ce.Netmask=Ms});var sh={};yt(sh,{autoNAT:()=>oh});var Nt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ht=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Kr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var qr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var or=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Xn=Symbol.for("@libp2p/peer-id");function jc(r){return typeof r?.handleEvent=="function"}function $c(r){return(r!==!0&&r!==!1&&r?.once)??!1}var Vr=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=$c(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))}jc(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 ai=Symbol.for("@libp2p/service-capabilities"),ci=Symbol.for("@libp2p/service-dependencies");var eo={};yt(eo,{base58btc:()=>Y,base58flickr:()=>tf});var kh=new Uint8Array(0);function ui(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 wt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return fe(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return fe(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function li(r){let t=new Uint8Array(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}var fi=4096;function di(r){let t=r.length;if(t<=fi)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.subarray(n,n+=fi));return e}function Gc(r){return r?.buffer instanceof ArrayBuffer}function fe(r){return Gc(r)?r:r.slice()}function Zc(r,t,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,e){var c=i.toLowerCase().charCodeAt(0),f=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),f!==a&&(n[f]=s)}}var d=r.length,h=r.charAt(0),u=Math.log(d)/Math.log(256),p=Math.log(256)/Math.log(d);function S(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var g=0,x=0,I=0,B=l.length;I!==B&&l[I]===0;)I++,g++;for(var D=(B-I)*p+1>>>0,R=new Uint8Array(D);I!==B;){for(var T=l[I],F=0,N=D-1;(T!==0||F<x)&&N!==-1;N--,F++)T+=256*R[N]>>>0,R[N]=T%d>>>0,T=T/d>>>0;if(T!==0)throw new Error("Non-zero carry");x=F,I++}for(var k=D-x;k!==D&&R[k]===0;)k++;for(var y=h.repeat(g);k<D;++k)y+=r.charAt(R[k]);return y}function v(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var g=0;if(l[g]!==" "){for(var x=0,I=0;l[g]===h;)x++,g++;for(var B=(l.length-g)*u+1>>>0,D=new Uint8Array(B);l[g];){var R=n[l.charCodeAt(g)];if(R===255)return;for(var T=0,F=B-1;(R!==0||T<I)&&F!==-1;F--,T++)R+=d*D[F]>>>0,D[F]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");I=T,g++}if(l[g]!==" "){for(var N=B-I;N!==B&&D[N]===0;)N++;for(var k=new Uint8Array(x+(B-N)),y=x;N!==B;)k[y++]=D[N++];return k}}}function m(l){var g=v(l);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:S,decodeUnsafe:v,decode:m}}var Yc=Zc,Xc=Yc,pi=Xc;var Wn=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")}},Qn=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 mi(this,t)}},Jn=class{decoders;constructor(t){this.decoders=t}or(t){return mi(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 mi(r,t){return new Jn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var to=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 Wn(t,e,n),this.decoder=new Qn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:r,prefix:t,encode:e,decode:n}){return new to(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e,caseInsensitive:n=!1}){let{encode:o,decode:s}=pi(e,r,n);return Te({prefix:t,name:r,encode:o,decode:i=>wt(s(i))})}function Wc(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 f=0;f<o;++f){let d=t[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,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 Qc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Jc(r,t){let e={};for(let n=0;n<r.length;++n)if(e[r[n]]=n,t){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(e[o]=n),s!==r[n]&&(e[s]=n)}return e}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n,caseInsensitive:o=!1}){let s=Jc(n,o);return Te({prefix:t,name:r,encode(i){return Qc(i,n,e)},decode(i){return Wc(i,s,e,r)}})}var Y=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),tf=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ro={};yt(ro,{base32:()=>Xt,base32hex:()=>of,base32hexpad:()=>af,base32hexpadupper:()=>cf,base32hexupper:()=>sf,base32pad:()=>rf,base32padupper:()=>nf,base32upper:()=>ef,base32z:()=>ff});var Xt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),ef=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),rf=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),nf=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),of=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),sf=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),af=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),cf=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),ff=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var no={};yt(no,{base36:()=>sr,base36upper:()=>uf});var sr=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),uf=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var lf=bi,gi=128,df=127,hf=~df,pf=Math.pow(2,31);function bi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=pf;)t[e++]=r&255|gi,r/=128;for(;r&hf;)t[e++]=r&255|gi,r>>>=7;return t[e]=r|0,bi.bytes=e-n+1,t}var mf=oo,gf=128,yi=127;function oo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw oo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&yi)<<o:(i&yi)*Math.pow(2,o),o+=7}while(i>=gf);return oo.bytes=s-n,e}var yf=Math.pow(2,7),bf=Math.pow(2,14),xf=Math.pow(2,21),wf=Math.pow(2,28),Ef=Math.pow(2,35),Sf=Math.pow(2,42),vf=Math.pow(2,49),_f=Math.pow(2,56),Af=Math.pow(2,63),If=function(r){return r<yf?1:r<bf?2:r<xf?3:r<wf?4:r<Ef?5:r<Sf?6:r<vf?7:r<_f?8:r<Af?9:10},Bf={encode:lf,decode:mf,encodingLength:If},Tf=Bf,ir=Tf;function ar(r,t=0){return[ir.decode(r,t),ir.decode.bytes]}function Le(r,t,e=0){return ir.encode(r,t,e),t}function Ce(r){return ir.encodingLength(r)}function Re(r,t){let e=t.byteLength,n=Ce(r),o=n+Ce(e),s=new Uint8Array(o+e);return Le(r,s,0),Le(e,s,n),s.set(t,o),new De(r,e,t,s)}function ue(r){let t=wt(r),[e,n]=ar(t),[o,s]=ar(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new De(e,o,i,t)}function xi(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ui(r.bytes,e.bytes)}}var De=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=fe(n),this.bytes=fe(o)}};function wi(r,t){let{bytes:e,version:n}=r;return n===0?Cf(e,so(r),t??Y.encoder):Df(e,so(r),t??Xt.encoder)}var Ei=new WeakMap;function so(r){let t=Ei.get(r);if(t==null){let e=new Map;return Ei.set(r,e),e}return t}var ct=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=fe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Rf)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=Re(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&&xi(t.multihash,n.multihash)}toString(t){return wi(this,t)}toJSON(){return{"/":wi(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??Si(n,o,s.bytes))}else if(e[Of]===!0){let{version:n,multihash:o,code:s}=e,i=ue(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==cr)throw new Error(`Version 0 CID must use dag-pb (code: ${cr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Si(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,cr,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=wt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new De(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,u]=ar(t.subarray(e));return e+=u,h},o=n(),s=cr;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(),f=e+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=Lf(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 so(s).set(n,t),s}};function Lf(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 Xt.prefix:{let e=t??Xt;return[Xt.prefix,e.decode(r)]}case sr.prefix:{let e=t??sr;return[sr.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 Cf(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 Df(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 cr=112,Rf=18;function Si(r,t,e){let n=Ce(r),o=n+Ce(t),s=new Uint8Array(o+e.byteLength);return Le(r,s,0),Le(t,s,n),s.set(e,o),s}var Of=Symbol.for("@ipld/js-cid/CID");var io={};yt(io,{identity:()=>St});var vi=0,Pf="identity",_i=wt;function kf(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 Re(vi,_i(r))}var St={code:vi,name:Pf,encode:_i,digest:kf};function ft(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 Ff(r){return r.buffer instanceof ArrayBuffer}function vt(r){return Ff(r)?r:r.slice()}async function Ai(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 Et(r=0){return new Uint8Array(r)}function ut(r=0){return new Uint8Array(r)}function Nf(r){return r?.buffer instanceof ArrayBuffer}function ao(r){if(Nf(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Rt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ut(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return ao(e)}var Bi=Symbol.for("@achingbrain/uint8arraylist");function Ii(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 jr(r){return!!r?.[Bi]}var rt=class r{bufs;length;[Bi]=!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(jr(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(jr(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=Ii(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ii(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(jr(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 Rt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Rt(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 f=t>=a&&t<c,d=e>a&&e<=c;if(f&&d){if(t===a&&e===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){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(!jr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(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 h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let h=e;h<=c;h+=d){d=0;for(let u=f;u>=0;u--){let p=this.get(h+u);if(n[u]!==p){d=Math.max(1,u-a[p]);break}}if(d===0)return h}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=ut(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=Et(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=Et(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=Et(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=ut(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=Et(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=Et(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=Et(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=Et(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=Et(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(!ft(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 co={};yt(co,{base10:()=>Uf});var Uf=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var fo={};yt(fo,{base16:()=>Mf,base16upper:()=>zf});var Mf=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),zf=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var uo={};yt(uo,{base2:()=>Kf});var Kf=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var lo={};yt(lo,{base256emoji:()=>$f});var Ti=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}"),qf=Ti.reduce((r,t,e)=>(r[e]=t,r),[]),Vf=Ti.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Hf(r){return r.reduce((t,e)=>(t+=qf[e],t),"")}function jf(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Vf[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var $f=Te({prefix:"\u{1F680}",name:"base256emoji",encode:Hf,decode:jf});var po={};yt(po,{base64:()=>Gf,base64pad:()=>Zf,base64url:()=>ho,base64urlpad:()=>Yf});var Gf=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zf=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ho=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yf=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var mo={};yt(mo,{base8:()=>Xf});var Xf=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var go={};yt(go,{identity:()=>Wf});var Wf=Te({prefix:"\0",name:"identity",encode:r=>di(wt(r)),decode:r=>wt(li(r))});var wp=new TextEncoder,Ep=new TextDecoder;var xo={};yt(xo,{sha256:()=>fr,sha512:()=>eu});var tu=20;function bo({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new yo(r,t,e,n,o)}var yo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??tu,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?Li(n,this.code,e?.truncate):n.then(o=>Li(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Li(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 Re(t,r)}function Di(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var fr=bo({name:"sha2-256",code:18,encode:Di("SHA-256")}),eu=bo({name:"sha2-512",code:19,encode:Di("SHA-512")});var ur={...go,...uo,...mo,...co,...fo,...ro,...no,...eo,...po,...lo},Op={...xo,...io};function Oi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ri=Oi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),wo=Oi("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=ut(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ru={utf8:Ri,"utf-8":Ri,hex:ur.base16,latin1:wo,ascii:wo,binary:wo,...ur},$r=ru;function H(r,t="utf8"){let e=$r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function W(r,t="utf8"){let e=$r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var nu=parseInt("11111",2),Eo=parseInt("10000000",2),ou=parseInt("01111111",2),Pi={0:lr,1:lr,2:su,3:cu,4:fu,5:au,6:iu,16:lr,22:lr,48:lr};function So(r,t={offset:0}){let e=r[t.offset]&nu;if(t.offset++,Pi[e]!=null)return Pi[e](r,t);throw new Error("No decoder for tag "+e)}function dr(r,t){let e=0;if((r[t.offset]&Eo)===Eo){let n=r[t.offset]&ou,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 lr(r,t){dr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=So(r,t);if(n===null)break;e.push(n)}return e}function su(r,t){let e=dr(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 iu(r,t){let e=dr(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 f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let d=0;for(let h=0;h<c.length;h++)d+=c[h]<<h*7;a+=`.${d}`,c=[]}}return a}function au(r,t){return t.offset++,null}function cu(r,t){let e=dr(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 fu(r,t){let e=dr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function uu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new rt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function vo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=uu(r.byteLength);return new rt(Uint8Array.from([t.byteLength|Eo]),t)}function ki(r){let t=new rt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new rt(Uint8Array.from([2]),vo(t),t)}function Fi(r){let t=Uint8Array.from([0]),e=new rt(t,r);return new rt(Uint8Array.from([3]),vo(e),e)}function Gr(r,t=48){let e=new rt;for(let n of r)e.append(n);return new rt(Uint8Array.from([t]),vo(e),e)}var lu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),du=Uint8Array.from([6,5,43,129,4,0,34]),hu=Uint8Array.from([6,5,43,129,4,0,35]),pu={ext:!0,kty:"EC",crv:"P-256"},mu={ext:!0,kty:"EC",crv:"P-384"},gu={ext:!0,kty:"EC",crv:"P-521"},_o=32,Ao=48,Io=66;function Ni(r){let t=So(r);return Ui(t)}function Ui(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===_o*2+1)return n=W(t.subarray(e,e+_o),"base64url"),o=W(t.subarray(e+_o),"base64url"),new Oe({...pu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ao*2+1)return n=W(t.subarray(e,e+Ao),"base64url"),o=W(t.subarray(e+Ao),"base64url"),new Oe({...mu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Io*2+1)return n=W(t.subarray(e,e+Io),"base64url"),o=W(t.subarray(e+Io),"base64url"),new Oe({...gu,key_ops:["verify"],x:n,y:o});throw new ht(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Mi(r){return Gr([ki(Uint8Array.from([1])),Gr([yu(r.crv)],160),Gr([Fi(new rt(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function yu(r){if(r==="P-256")return lu;if(r==="P-384")return du;if(r==="P-521")return hu;throw new ht(`Invalid curve ${r}`)}var Oe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Mi(this.jwk)),this._raw}toMultihash(){return St.digest(Pe(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:ft(this.raw,t.raw)}async verify(t,e,n){return Ai(this.jwk,e,t,n)}};function Bo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Qt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${r}`)}}function bt(r,t,e=""){let n=Bo(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}`,f=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(f):new TypeError(f)}return r}function Zr(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Qt(r.outputLen),Qt(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function ke(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 Yr(r,t){bt(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 Mt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Xr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _t(r,t){return r<<32-t|r>>>t}var Ki=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",bu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Wr(r){if(bt(r),Ki)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=bu[r[e]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function zi(r){if(r>=Ut._0&&r<=Ut._9)return r-Ut._0;if(r>=Ut.A&&r<=Ut.F)return r-(Ut.A-10);if(r>=Ut.a&&r<=Ut.f)return r-(Ut.a-10)}function hr(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(Ki)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=zi(r.charCodeAt(s)),a=zi(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 To(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];bt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Lo(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 qi(r=32){Qt(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var Co=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function Vi(r,t,e){return r&t^~r&e}function Hi(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=Xr(this.buffer)}update(t){ke(this),bt(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=Xr(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){ke(this),Yr(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)e[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Xr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],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()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Qr=BigInt(4294967295),ji=BigInt(32);function xu(r,t=!1){return t?{h:Number(r&Qr),l:Number(r>>ji&Qr)}:{h:Number(r>>ji&Qr)|0,l:Number(r&Qr)|0}}function $i(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}=xu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Do=(r,t,e)=>r>>>e,Ro=(r,t,e)=>r<<32-e|t>>>e,le=(r,t,e)=>r>>>e|t<<32-e,de=(r,t,e)=>r<<32-e|t>>>e,mr=(r,t,e)=>r<<64-e|t>>>e-32,gr=(r,t,e)=>r>>>e-32|t<<64-e;function Ot(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Gi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Zi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Yi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Xi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Wi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Qi=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Eu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jt=new Uint32Array(64),Oo=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 h=0;h<16;h++,e+=4)Jt[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let u=Jt[h-15],p=Jt[h-2],S=_t(u,7)^_t(u,18)^u>>>3,v=_t(p,17)^_t(p,19)^p>>>10;Jt[h]=v+Jt[h-7]+S+Jt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:d}=this;for(let h=0;h<64;h++){let u=_t(a,6)^_t(a,11)^_t(a,25),p=d+u+Vi(a,c,f)+Eu[h]+Jt[h]|0,v=(_t(n,2)^_t(n,13)^_t(n,22))+Hi(n,o,s)|0;d=f,f=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+v|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,f,d)}roundClean(){Mt(Jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},Po=class extends Oo{A=zt[0]|0;B=zt[1]|0;C=zt[2]|0;D=zt[3]|0;E=zt[4]|0;F=zt[5]|0;G=zt[6]|0;H=zt[7]|0;constructor(){super(32)}};var Ji=$i(["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))),Su=Ji[0],vu=Ji[1],te=new Uint32Array(80),ee=new Uint32Array(80),ko=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:f,El:d,Fh:h,Fl:u,Gh:p,Gl:S,Hh:v,Hl:m}=this;return[t,e,n,o,s,i,a,c,f,d,h,u,p,S,v,m]}set(t,e,n,o,s,i,a,c,f,d,h,u,p,S,v,m){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=d|0,this.Fh=h|0,this.Fl=u|0,this.Gh=p|0,this.Gl=S|0,this.Hh=v|0,this.Hl=m|0}process(t,e){for(let x=0;x<16;x++,e+=4)te[x]=t.getUint32(e),ee[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let I=te[x-15]|0,B=ee[x-15]|0,D=le(I,B,1)^le(I,B,8)^Do(I,B,7),R=de(I,B,1)^de(I,B,8)^Ro(I,B,7),T=te[x-2]|0,F=ee[x-2]|0,N=le(T,F,19)^mr(T,F,61)^Do(T,F,6),k=de(T,F,19)^gr(T,F,61)^Ro(T,F,6),y=Yi(R,k,ee[x-7],ee[x-16]),b=Xi(y,D,N,te[x-7],te[x-16]);te[x]=b|0,ee[x]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:d,Eh:h,El:u,Fh:p,Fl:S,Gh:v,Gl:m,Hh:l,Hl:g}=this;for(let x=0;x<80;x++){let I=le(h,u,14)^le(h,u,18)^mr(h,u,41),B=de(h,u,14)^de(h,u,18)^gr(h,u,41),D=h&p^~h&v,R=u&S^~u&m,T=Wi(g,B,R,vu[x],ee[x]),F=Qi(T,l,I,D,Su[x],te[x]),N=T|0,k=le(n,o,28)^mr(n,o,34)^mr(n,o,39),y=de(n,o,28)^gr(n,o,34)^gr(n,o,39),b=n&s^n&a^s&a,_=o&i^o&c^i&c;l=v|0,g=m|0,v=p|0,m=S|0,p=h|0,S=u|0,{h,l:u}=Ot(f|0,d|0,F|0,N|0),f=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=Gi(N,y,_);n=Zi(E,F,k,b),o=E|0}({h:n,l:o}=Ot(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ot(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ot(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:d}=Ot(this.Dh|0,this.Dl|0,f|0,d|0),{h,l:u}=Ot(this.Eh|0,this.El|0,h|0,u|0),{h:p,l:S}=Ot(this.Fh|0,this.Fl|0,p|0,S|0),{h:v,l:m}=Ot(this.Gh|0,this.Gl|0,v|0,m|0),{h:l,l:g}=Ot(this.Hh|0,this.Hl|0,l|0,g|0),this.set(n,o,s,i,a,c,f,d,h,u,p,S,v,m,l,g)}roundClean(){Mt(te,ee)}destroy(){this.destroyed=!0,Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Fo=class extends ko{Ah=st[0]|0;Al=st[1]|0;Bh=st[2]|0;Bl=st[3]|0;Ch=st[4]|0;Cl=st[5]|0;Dh=st[6]|0;Dl=st[7]|0;Eh=st[8]|0;El=st[9]|0;Fh=st[10]|0;Fl=st[11]|0;Gh=st[12]|0;Gl=st[13]|0;Hh=st[14]|0;Hl=st[15]|0;constructor(){super(64)}};var ta=Lo(()=>new Po,Co(1));var Jr=Lo(()=>new Fo,Co(3));var z=(r,t,e)=>bt(r,t,e),Uo=Qt,Fe=Wr,J=(...r)=>To(...r),Ne=r=>hr(r),he=Bo,yr=r=>qi(r),en=BigInt(0),No=BigInt(1);function At(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function rn(r){if(typeof r=="bigint"){if(!tn(r))throw new RangeError("positive bigint expected, got "+r)}else Uo(r);return r}function It(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 br(r){let t=rn(r).toString(16);return t.length&1?"0"+t:t}function ea(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?en:BigInt("0x"+r)}function pe(r){return ea(Wr(r))}function Pt(r){return ea(Wr(xr(bt(r)).reverse()))}function nn(r,t){if(Qt(t),t===0)throw new RangeError("zero length");r=rn(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return hr(e.padStart(t*2,"0"))}function Mo(r,t){return nn(r,t).reverse()}function ra(r,t){if(r=z(r),t=z(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 xr(r){return Uint8Array.from(z(r))}function on(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 tn=r=>typeof r=="bigint"&&en<=r;function _u(r,t,e){return tn(r)&&tn(t)&&tn(e)&&t<=r&&r<e}function Ue(r,t,e,n){if(!_u(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Me(r){if(r<en)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>en;r>>=No,t+=1);return t}var wr=r=>(No<<BigInt(r))-No;function na(r,t,e){if(Qt(r,"hashLen"),Qt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),d=0,h=()=>{c.fill(1),f.fill(0),d=0},u=(...m)=>e(f,J(c,...m)),p=(m=o)=>{f=u(s,m),c=u(),m.length!==0&&(f=u(i,m),c=u())},S=()=>{if(d++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,l=[];for(;m<t;){c=u();let g=c.slice();l.push(g),m+=c.length}return J(...l)};return(m,l)=>{h(),p(m);let g;for(;(g=l(S()))===void 0;)p();return h(),g}}function Bt(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 f=typeof c;if(f!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}var zo=()=>{throw new Error("not implemented")};var it=BigInt(0),G=BigInt(1),me=BigInt(2),aa=BigInt(3),ca=BigInt(4),fa=BigInt(5),Au=BigInt(7),ua=BigInt(8),Iu=BigInt(9),la=BigInt(16);function X(r,t){if(t<=it)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=it?e:t+e}function j(r,t,e){if(t<it)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >it;)n*=n,n%=e;return n}function oa(r,t){if(r===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let e=X(r,t),n=t,o=it,s=G,i=G,a=it;for(;e!==it;){let f=n/e,d=n-e*f,h=o-i*f,u=s-a*f;n=e,e=d,o=i,s=a,i=h,a=u}if(n!==G)throw new Error("invert: does not exist");return X(o,t)}function Ko(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function da(r,t){let e=r,n=(e.ORDER+G)/ca,o=e.pow(t,n);return Ko(e,o,t),o}function Bu(r,t){let e=r,n=(e.ORDER-fa)/ua,o=e.mul(t,me),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,me),s),c=e.mul(i,e.sub(a,e.ONE));return Ko(e,c,t),c}function Tu(r){let t=ze(r),e=ha(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Au)/la;return((a,c)=>{let f=a,d=f.pow(c,i),h=f.mul(d,n),u=f.mul(d,o),p=f.mul(d,s),S=f.eql(f.sqr(h),c),v=f.eql(f.sqr(u),c);d=f.cmov(d,h,S),h=f.cmov(p,u,v);let m=f.eql(f.sqr(h),c),l=f.cmov(d,h,m);return Ko(f,l,c),l})}function ha(r){if(r<aa)throw new Error("sqrt is not defined for small field");let t=r-G,e=0;for(;t%me===it;)t/=me,e++;let n=me,o=ze(r);for(;sa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return da;let s=o.pow(n,t),i=(t+G)/me;return function(c,f){let d=c;if(d.is0(f))return f;if(sa(d,f)!==1)throw new Error("Cannot find square root");let h=e,u=d.mul(d.ONE,s),p=d.pow(f,t),S=d.pow(f,i);for(;!d.eql(p,d.ONE);){if(d.is0(p))return d.ZERO;let v=1,m=d.sqr(p);for(;!d.eql(m,d.ONE);)if(v++,m=d.sqr(m),v===h)throw new Error("Cannot find square root");let l=G<<BigInt(h-v-1),g=d.pow(u,l);h=v,u=d.sqr(g),p=d.mul(p,u),S=d.mul(S,g)}return S}}function Lu(r){return r%ca===aa?da:r%ua===fa?Bu:r%la===Iu?Tu(r):ha(r)}var Kt=(r,t)=>(X(r,t)&G)===G,Cu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function qo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Cu.reduce((n,o)=>(n[o]="function",n),t);if(Bt(r,e),It(r.BYTES,"BYTES"),It(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 Du(r,t,e){let n=r;if(e<it)throw new Error("invalid exponent, negatives unsupported");if(e===it)return n.ONE;if(e===G)return t;let o=n.ONE,s=t;for(;e>it;)e&G&&(o=n.mul(o,s)),s=n.sqr(s),e>>=G;return o}function Er(r,t,e=!1){let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function sa(r,t){let e=r,n=(e.ORDER-G)/me,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 Ru(r,t){if(t!==void 0&&Uo(t),r<=it)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=Me(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 ia=new WeakMap,sn=class{ORDER;BITS;BYTES;isLE;ZERO=it;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}=Ru(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 it<=t&&t<this.ORDER}is0(t){return t===it}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 Du(this,t,e)}div(t,e){return X(t*oa(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 oa(t,this.ORDER)}sqrt(t){let e=ia.get(this);return e||ia.set(this,e=Lu(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?Mo(t,this.BYTES):nn(t,this.BYTES)}fromBytes(t,e=!1){z(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 f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Pt(t):pe(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 Er(this,t)}cmov(t,e,n){return At(n,"condition"),n?e:t}};Object.freeze(sn.prototype);function ze(r,t={}){return new sn(r,t)}function pa(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=Me(r-G);return Math.ceil(t/8)}function Vo(r){let t=pa(r);return t+Math.ceil(t/2)}function Ho(r,t,e=!1){z(r);let n=r.length,o=pa(t),s=Math.max(Vo(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Pt(r):pe(r),a=X(i,t-G)+G;return e?Mo(a,o):nn(a,o)}var Ke=BigInt(0),ge=BigInt(1);function Sr(r,t){let e=t.negate();return r?e:t}function ye(r,t){let e=Er(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function ba(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function jo(r,t){ba(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=wr(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ma(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+=ge);let f=t*n,d=f+Math.abs(a)-1,h=a===0,u=a<0,p=t%2!==0;return{nextN:c,offset:d,isZero:h,isNeg:u,isNegF:p,offsetF:f}}var $o=new WeakMap,xa=new WeakMap;function Go(r){return xa.get(r)||1}function ga(r){if(r!==Ke)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>Ke;)e&ge&&(n=n.add(o)),o=o.double(),e>>=ge;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=jo(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)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=jo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:d,isNeg:h,isNegF:u,offsetF:p}=ma(n,a,i);n=c,d?s=s.add(Sr(u,e[p])):o=o.add(Sr(h,e[f]))}return ga(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=jo(t,this.bits);for(let i=0;i<s.windows&&n!==Ke;i++){let{nextN:a,offset:c,isZero:f,isNeg:d}=ma(n,i,s);if(n=a,!f){let h=e[c];o=o.add(d?h.negate():h)}}return ga(n),o}getPrecomputes(t,e,n){let o=$o.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),$o.set(e,o))),o}cached(t,e,n){let o=Go(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Go(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){ba(e,this.bits),xa.set(t,e),$o.delete(t)}hasCache(t){return Go(t)!==1}};function wa(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ke||n>Ke;)e&ge&&(s=s.add(o)),n&ge&&(i=i.add(o)),o=o.double(),e>>=ge,n>>=ge;return{p1:s,p2:i}}function ya(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return qo(t),t}else return ze(r,{isLE:e})}function an(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 f=t[c];if(!(typeof f=="bigint"&&f>Ke))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ya(t.p,e.Fp,n),s=ya(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 cn(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var re=BigInt(0),nt=BigInt(1),Zo=BigInt(2),Ou=BigInt(8);function Pu(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 Ea(r,t={}){let e=t,n=an("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Bt(e,{},{uvRatio:"function"});let c=Zo<<BigInt(s.BYTES*8)-nt,f=v=>o.create(v),d=e.uvRatio===void 0?(v,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,m))}}catch{return{isValid:!1,value:re}}}:e.uvRatio;if(!Pu(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(v,m,l=!1){let g=l?nt:re;return Ue("coordinate "+v,m,g,c),m}function u(v){if(!(v instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,nt,f(i.Gx*i.Gy));static ZERO=new p(re,nt,nt,re);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,l,g,x){this.X=h("x",m),this.Y=h("y",l),this.Z=h("z",g,!0),this.T=h("t",x),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:l,y:g}=m||{};return h("x",l),h("y",g),new p(l,g,nt,f(l*g))}static fromBytes(m,l=!1){let g=o.BYTES,{a:x,d:I}=i;m=xr(z(m,g,"point")),At(l,"zip215");let B=xr(m),D=m[g-1];B[g-1]=D&-129;let R=Pt(B),T=l?c:o.ORDER;Ue("point.y",R,re,T);let F=f(R*R),N=f(F-nt),k=f(I*F-x),{isValid:y,value:b}=d(N,k);if(!y)throw new Error("bad point: invalid y coordinate");let _=(b&nt)===nt,E=(D&128)!==0;if(!l&&b===re&&E)throw new Error("bad point: x=0 and x_0=1");return E!==_&&(b=f(-b)),p.fromAffine({x:b,y:R})}static fromHex(m,l=!1){return p.fromBytes(Ne(m),l)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,l=!0){return S.createCache(this,m),l||this.multiply(Zo),this}assertValidity(){let m=this,{a:l,d:g}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:x,Y:I,Z:B,T:D}=m,R=f(x*x),T=f(I*I),F=f(B*B),N=f(F*F),k=f(R*l),y=f(F*f(k+T)),b=f(N+f(g*f(R*T)));if(y!==b)throw new Error("bad point: equation left != right (1)");let _=f(x*I),E=f(B*D);if(_!==E)throw new Error("bad point: equation left != right (2)")}equals(m){u(m);let{X:l,Y:g,Z:x}=this,{X:I,Y:B,Z:D}=m,R=f(l*D),T=f(I*x),F=f(g*D),N=f(B*x);return R===T&&F===N}is0(){return this.equals(p.ZERO)}negate(){return new p(f(-this.X),this.Y,this.Z,f(-this.T))}double(){let{a:m}=i,{X:l,Y:g,Z:x}=this,I=f(l*l),B=f(g*g),D=f(Zo*f(x*x)),R=f(m*I),T=l+g,F=f(f(T*T)-I-B),N=R+B,k=N-D,y=R-B,b=f(F*k),_=f(N*y),E=f(F*y),w=f(k*N);return new p(b,_,w,E)}add(m){u(m);let{a:l,d:g}=i,{X:x,Y:I,Z:B,T:D}=this,{X:R,Y:T,Z:F,T:N}=m,k=f(x*R),y=f(I*T),b=f(D*g*N),_=f(B*F),E=f((x+I)*(R+T)-k-y),w=_-b,A=_+b,C=f(y-l*k),L=f(E*w),O=f(A*C),P=f(E*C),M=f(w*A);return new p(L,O,M,P)}subtract(m){return u(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:l,f:g}=S.cached(this,m,x=>ye(p,x));return ye(p,[l,g])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===re?p.ZERO:this.is0()||m===nt?this:S.unsafe(this,m,l=>ye(p,l))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.unsafe(this,i.n).is0()}toAffine(m){let l=this,g=m,{X:x,Y:I,Z:B}=l,D=l.is0();g==null&&(g=D?Ou:o.inv(B));let R=f(x*g),T=f(I*g),F=o.mul(B,g);if(D)return{x:re,y:nt};if(F!==nt)throw new Error("invZ was invalid");return{x:R,y:T}}clearCofactor(){return a===nt?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:l}=this.toAffine(),g=o.toBytes(l);return g[g.length-1]|=m&nt?128:0,g}toHex(){return Fe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let S=new qe(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var fn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){zo()}static fromHex(t){zo()}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 Fe(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 Sa(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;Bt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,f=n.outputLen,d=2*a.BYTES;if(f!==void 0&&(It(f,"hash.outputLen"),f!==d))throw new Error(`hash.outputLen must be ${d}, got ${f}`);let h=o.randomBytes===void 0?yr:o.randomBytes,u=o.adjustScalarBytes===void 0?y=>y:o.adjustScalarBytes,p=o.domain===void 0?(y,b,_)=>{if(At(_,"phflag"),b.length||_)throw new Error("Contexts/pre-hash are not supported");return y}:o.domain;function S(y){return c.create(Pt(y))}function v(y){let b=R.secretKey;z(y,R.secretKey,"secretKey");let _=z(n(y),2*b,"hashedSecretKey"),E=u(_.slice(0,b)),w=_.slice(b,2*b),A=S(E);return{head:E,prefix:w,scalar:A}}function m(y){let{head:b,prefix:_,scalar:E}=v(y),w=i.multiply(E),A=w.toBytes();return{head:b,prefix:_,scalar:E,point:w,pointBytes:A}}function l(y){return m(y).pointBytes}function g(y=Uint8Array.of(),...b){let _=J(...b);return S(n(p(_,z(y,void 0,"context"),!!s)))}function x(y,b,_={}){y=z(y,void 0,"message"),s&&(y=s(y));let{prefix:E,scalar:w,pointBytes:A}=m(b),C=g(_.context,E,y),L=i.multiply(C).toBytes(),O=g(_.context,L,A,y),P=c.create(C+O*w);if(!c.isValid(P))throw new Error("sign failed: invalid s");let M=J(L,c.toBytes(P));return z(M,R.signature,"result")}let I={zip215:o.zip215};function B(y,b,_,E=I){let{context:w}=E,A=E.zip215===void 0?!!I.zip215:E.zip215,C=R.signature;y=z(y,C,"signature"),b=z(b,void 0,"message"),_=z(_,R.publicKey,"publicKey"),A!==void 0&&At(A,"zip215"),s&&(b=s(b));let L=C/2,O=y.subarray(0,L),P=Pt(y.subarray(L,C)),M,K,U;try{M=r.fromBytes(_,A),K=r.fromBytes(O,A),U=i.multiplyUnsafe(P)}catch{return!1}if(!A&&M.isSmallOrder())return!1;let Q=g(w,O,_,b);return K.add(M.multiplyUnsafe(Q)).subtract(U).clearCofactor().is0()}let D=a.BYTES,R={secretKey:D,publicKey:D,signature:2*D,seed:D};function T(y){return y=y===void 0?h(R.seed):y,z(y,R.seed,"seed")}function F(y){return he(y)&&y.length===R.secretKey}function N(y,b){try{return!!r.fromBytes(y,b===void 0?I.zip215:b)}catch{return!1}}let k={getExtendedPublicKey:m,randomSecretKey:T,isValidSecretKey:F,isValidPublicKey:N,toMontgomery(y){let{y:b}=r.fromBytes(y),_=R.publicKey,E=_===32;if(!E&&_!==57)throw new Error("only defined for 25519 and 448");let w=E?a.div(nt+b,nt-b):a.div(b-nt,b+nt);return a.toBytes(w)},toMontgomerySecret(y){let b=R.secretKey;z(y,b);let _=n(y.subarray(0,b));return u(_).subarray(0,b)}};return Object.freeze(R),Object.freeze(k),Object.freeze({keygen:cn(T,l),getPublicKey:l,sign:x,verify:B,utils:k,Point:r,lengths:R})}function vr(r,t){if(It(r),It(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 ku(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 Fu(r){if(!he(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?on(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function Yo(r,t,e,n){z(r),It(e),t=Fu(t),t.length>255&&(t=n(J(on("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=J(t,vr(t.length,1)),c=new Uint8Array(s),f=vr(e,2),d=new Array(i),h=n(J(c,r,f,vr(0,1),a));d[0]=n(J(h,vr(1,1),a));for(let p=1;p<i;p++){let S=[ku(h,d[p-1]),vr(p+1,1),a];d[p]=n(J(...S))}return J(...d).slice(0,e)}var va="HashToScalar-";var Nu=BigInt(0),qt=BigInt(1),_a=BigInt(2);var Uu=BigInt(5),Mu=BigInt(8),Ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Jo={p:Ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Mu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function zu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ve,a=r*r%s*r%s,c=j(a,_a,s)*a%s,f=j(c,qt,s)*r%s,d=j(f,Uu,s)*f%s,h=j(d,t,s)*d%s,u=j(h,e,s)*h%s,p=j(u,n,s)*u%s,S=j(p,o,s)*p%s,v=j(S,o,s)*p%s,m=j(v,t,s)*d%s;return{pow_p_5_8:j(m,_a,s)*r%s,b2:a}}function Ku(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Xo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ts(r,t){let e=Ve,n=X(t*t*t,e),o=X(n*n*t,e),s=zu(r*o).pow_p_5_8,i=X(r*n*s,e),a=X(t*i*i,e),c=i,f=X(i*Xo,e),d=a===r,h=a===X(-r,e),u=a===X(-r*Xo,e);return d&&(i=c),(h||u)&&(i=f),Kt(i,e)&&(i=X(-i,e)),{isValid:d||h,value:i}}var oe=Ea(Jo,{uvRatio:ts}),ne=oe.Fp,Ba=oe.Fn;function qu(r){return Sa(oe,Jr,Object.assign({adjustScalarBytes:Ku,zip215:!0},r))}var Ta=qu({});var Wo=Xo,Vu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Hu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ju=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),$u=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Aa=r=>ts(qt,r),Gu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Qo=r=>ne.create(Pt(r)&Gu);function Ia(r){let{d:t}=Jo,e=Ve,n=l=>ne.create(l),o=n(Wo*r*r),s=n((o+qt)*ju),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=ts(s,a),d=n(f*r);Kt(d,e)||(d=n(-d)),c||(f=d),c||(i=o);let h=n(i*(o-qt)*$u-a),u=f*f,p=n((f+f)*a),S=n(h*Vu),v=n(qt-u),m=n(qt+u);return new oe(n(p*m),n(v*S),n(S*m),n(p*v))}var se=class r extends fn{static BASE=new r(oe.BASE);static ZERO=new r(oe.ZERO);static Fp=ne;static Fn=Ba;constructor(t){super(t)}static fromAffine(t){return new r(oe.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){bt(t,32);let{a:e,d:n}=Jo,o=Ve,s=I=>ne.create(I),i=Qo(t);if(!ra(ne.toBytes(i),t)||Kt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(qt+e*a),f=s(qt-e*a),d=s(c*c),h=s(f*f),u=s(e*n*d-h),{isValid:p,value:S}=Aa(s(u*h)),v=s(S*f),m=s(S*v*u),l=s((i+i)*v);Kt(l,o)&&(l=s(-l));let g=s(c*m),x=s(l*g);if(!p||Kt(x,o)||g===Nu)throw new Error("invalid ristretto255 encoding 2");return new r(new oe(l,g,qt,x))}static fromHex(t){return r.fromBytes(hr(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=Ve,i=m=>ne.create(m),a=i(i(n+e)*i(n-e)),c=i(t*e),f=i(c*c),{value:d}=Aa(i(a*f)),h=i(d*a),u=i(d*c),p=i(h*u*o),S;if(Kt(o*p,s)){let m=i(e*Wo),l=i(t*Wo);t=m,e=l,S=i(h*Hu)}else S=u;Kt(t*p,s)&&(e=i(-e));let v=i((n-e)*S);return Kt(v,s)&&(v=i(-v)),ne.toBytes(v)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>ne.create(f),a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Object.freeze(se.BASE);Object.freeze(se.ZERO);Object.freeze(se.prototype);Object.freeze(se);var Zu=Object.freeze({Point:se,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Yo(r,e,64,Jr);return Zu.deriveToCurve(n)},hashToScalar(r,t={DST:va}){let e=Yo(r,t.DST,64,Jr);return Ba.create(Pt(e))},deriveToCurve(r){bt(r,64);let t=Qo(r.subarray(0,32)),e=Ia(t),n=Qo(r.subarray(32,64)),o=Ia(n);return new se(e.add(o))}});var _r=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},un=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ln={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new un("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 dn=32;var es,Yu=(async()=>{try{return await ln.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Xu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await ln.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await ln.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 Wu(r,t,e){return Ta.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function La(r,t,e){return es==null&&(es=await Yu),es?Xu(r,t,e):Wu(r,t,e)}function hn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var pn=class{type="Ed25519";raw;constructor(t){this.raw=rs(t,dn)}toMultihash(){return St.digest(Pe(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:ft(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=La(this.raw,e,t);return hn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Da(r){return r=rs(r,dn),new pn(r)}function rs(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new ht(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Ju=Math.pow(2,7),tl=Math.pow(2,14),el=Math.pow(2,21),ns=Math.pow(2,28),os=Math.pow(2,35),ss=Math.pow(2,42),is=Math.pow(2,49),q=128,lt=127;function gt(r){if(r<Ju)return 1;if(r<tl)return 2;if(r<el)return 3;if(r<ns)return 4;if(r<os)return 5;if(r<ss)return 6;if(r<is)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function He(r,t,e=0){switch(gt(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function rl(r,t,e=0){switch(gt(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function as(r,t){let e=r[t],n=0;if(n+=e&lt,e<q||(e=r[t+1],n+=(e&lt)<<7,e<q)||(e=r[t+2],n+=(e&lt)<<14,e<q)||(e=r[t+3],n+=(e&lt)<<21,e<q)||(e=r[t+4],n+=(e&lt)*ns,e<q)||(e=r[t+5],n+=(e&lt)*os,e<q)||(e=r[t+6],n+=(e&lt)*ss,e<q)||(e=r[t+7],n+=(e&lt)*is,e<q))return n;throw new RangeError("Could not decode varint")}function nl(r,t){let e=r.get(t),n=0;if(n+=e&lt,e<q||(e=r.get(t+1),n+=(e&lt)<<7,e<q)||(e=r.get(t+2),n+=(e&lt)<<14,e<q)||(e=r.get(t+3),n+=(e&lt)<<21,e<q)||(e=r.get(t+4),n+=(e&lt)*ns,e<q)||(e=r.get(t+5),n+=(e&lt)*os,e<q)||(e=r.get(t+6),n+=(e&lt)*ss,e<q)||(e=r.get(t+7),n+=(e&lt)*is,e<q))return n;throw new RangeError("Could not decode varint")}function Ra(r,t,e=0){return t==null&&(t=ut(gt(r))),t instanceof Uint8Array?He(r,t,e):rl(r,t,e)}function Ar(r,t=0){return r instanceof Uint8Array?as(r,t):nl(r,t)}var cs=new Float32Array([-0]),ie=new Uint8Array(cs.buffer);function Pa(r,t,e){cs[0]=r,t[e]=ie[0],t[e+1]=ie[1],t[e+2]=ie[2],t[e+3]=ie[3]}function ka(r,t){return ie[0]=r[t],ie[1]=r[t+1],ie[2]=r[t+2],ie[3]=r[t+3],cs[0]}var fs=new Float64Array([-0]),dt=new Uint8Array(fs.buffer);function Fa(r,t,e){fs[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 Na(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],fs[0]}var ol=BigInt(Number.MAX_SAFE_INTEGER),sl=BigInt(Number.MIN_SAFE_INTEGER),xt=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<ol&&t>sl)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ua&&(o=0n,++n>Ua&&(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 xt(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var Ua=4294967296n;function Ma(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 za(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 us(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 Tt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function mn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ls=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=vt(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,Tt(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 Tt(this,4);return mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=ka(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=Na(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 Tt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return za(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(0,0),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 Tt(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 Tt(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 Tt(this,8);let t=mn(this.buf,this.pos+=4),e=mn(this.buf,this.pos+=4);return new xt(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=as(this.buf,this.pos);return this.pos+=gt(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 Ir(r){return new ls(r instanceof Uint8Array?r:r.subarray())}function Vt(r,t,e){let n=Ir(r);return t.decode(n,void 0,e)}function ds(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ut(i);o+i>t&&(n=ut(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var xe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function hs(){}var ms=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},il=ds();function al(r){return globalThis.Buffer!=null?ut(r):il(r)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new xe(hs,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new xe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new gs((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(gn,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(gn,e.length(),e)}uint64Number(t){return this._push(He,gt(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=xt.fromBigInt(t).zzEncode();return this._push(gn,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(gn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ps,1,t?1:0)}fixed32(t){return this._push(Br,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(Br,4,e.lo)._push(Br,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push(Br,4,e.lo)._push(Br,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Pa,4,t)}double(t){return this._push(Fa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ps,1,0):this.uint32(e)._push(fl,e,t)}string(t){let e=Ma(t);return e!==0?this.uint32(e)._push(us,e,t):this._push(ps,1,0)}fork(){return this.states=new ms(this),this.head=this.tail=new xe(hs,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new xe(hs,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=al(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ps(r,t,e){t[e]=r&255}function cl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var gs=class extends xe{next;constructor(t,e){super(cl,t,e),this.next=void 0}};function gn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Br(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function fl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(ul,t,r),this},Tr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ll,t,r),this});function ul(r,t,e){t.set(r,e)}function ll(r,t,e){r.length<40?us(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(H(r),e)}function ys(){return new Tr}function Ht(r,t){let e=ys();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*jt(r,t,e){let n=Ir(r);yield*t.stream(n,void 0,"$",e)}var yn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function bn(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function je(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 bn("enum",yn.VARINT,e,n,o)}function $t(r,t,e){return bn("message",yn.LENGTH_DELIMITED,r,t,e)}var Lr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var pt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(pt||(pt={}));var bs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(bs||(bs={}));(function(r){r.codec=()=>je(bs)})(pt||(pt={}));var Cr;(function(r){let t;r.codec=()=>(t==null&&(t=$t((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Ht(s,r.codec())}r.encode=e;function n(s,i){return Vt(s,r.codec(),i)}r.decode=n;function o(s,i){return jt(s,r.codec(),i)}r.stream=o})(Cr||(Cr={}));var xs;(function(r){let t;r.codec=()=>(t==null&&(t=$t((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Ht(s,r.codec())}r.encode=e;function n(s,i){return Vt(s,r.codec(),i)}r.decode=n;function o(s,i){return jt(s,r.codec(),i)}r.stream=o})(xs||(xs={}));var xn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(Zr(t),bt(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),Mt(o)}update(t){return ke(this),this.iHash.update(t),this}digestInto(t){ke(this),Yr(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()}},qa=(()=>{let r=((t,e,n)=>new xn(t,e).update(n).digest());return r.create=(t,e)=>new xn(t,e),r})();var Va=(r,t)=>(r+(r>=0?t:-t)/Ha)/t;function hl(r,t,e){Ue("scalar",r,kt,e);let[[n,o],[s,i]]=t,a=Va(i*r,e),c=Va(-o*r,e),f=r-a*n-c*s,d=-a*o-c*i,h=f<kt,u=d<kt;h&&(f=-f),u&&(d=-d);let p=wr(Math.ceil(Me(e)/2))+ae;if(f<kt||f>=p||d<kt||d>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:u,k2:d}}function Es(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ws(r,t){Bt(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return At(e.lowS,"lowS"),At(e.prehash,"prehash"),e.format!==void 0&&Es(e.format),e}var Ss=class extends Error{constructor(t=""){super(t)}},Lt={Err:Ss,_tlv:{encode:(r,t)=>{let{Err:e}=Lt;if(It(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=br(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?br(o.length/2|128):"";return br(r)+s+o+t},decode(r,t){let{Err:e}=Lt;t=z(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 f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of f)i=i<<8|d;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(rn(r),r<kt)throw new t("integer: negative integers are not allowed");let e=br(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 pe(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Lt,o=z(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:f,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},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 kt=BigInt(0),ae=BigInt(1),Ha=BigInt(2),wn=BigInt(3),pl=BigInt(4);function ja(r,t={}){let e=an("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;Bt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:f}=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 d=Ga(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(k,y,b){if(f&&y.is0())return Uint8Array.of(0);let{x:_,y:E}=y.toAffine(),w=n.toBytes(_);if(At(b,"isCompressed"),b){h();let A=!n.isOdd(E);return J($a(A),w)}else return J(Uint8Array.of(4),w,n.toBytes(E))}function p(k){z(k,void 0,"Point");let{publicKey:y,publicKeyUncompressed:b}=d,_=k.length,E=k[0],w=k.subarray(1);if(f&&_===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(_===y&&(E===2||E===3)){let A=n.fromBytes(w);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let C=m(A),L;try{L=n.sqrt(C)}catch(M){let K=M instanceof Error?": "+M.message:"";throw new Error("bad point: is not on curve, sqrt error"+K)}h();let O=n.isOdd(L);return(E&1)===1!==O&&(L=n.neg(L)),{x:A,y:L}}else if(_===b&&E===4){let A=n.BYTES,C=n.fromBytes(w.subarray(0,A)),L=n.fromBytes(w.subarray(A,A*2));if(!l(C,L))throw new Error("bad point: is not on curve");return{x:C,y:L}}else throw new Error(`bad point: got length ${_}, expected compressed=${y} or uncompressed=${b}`)}let S=t.toBytes===void 0?u:t.toBytes,v=t.fromBytes===void 0?p:t.fromBytes;function m(k){let y=n.sqr(k),b=n.mul(y,k);return n.add(n.add(b,n.mul(k,s.a)),s.b)}function l(k,y){let b=n.sqr(y),_=m(k);return n.eql(b,_)}if(!l(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,wn),pl),x=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,x)))throw new Error("bad curve params: a or b");function I(k,y,b=!1){if(!n.isValid(y)||b&&n.is0(y))throw new Error(`bad point coordinate ${k}`);return y}function B(k){if(!(k instanceof T))throw new Error("Weierstrass Point expected")}function D(k){if(!c||!c.basises)throw new Error("no endo");return hl(k,c.basises,o.ORDER)}function R(k,y,b,_,E){return b=new T(n.mul(b.X,k),b.Y,b.Z),y=Sr(_,y),b=Sr(E,b),y.add(b)}class T{static BASE=new T(s.Gx,s.Gy,n.ONE);static ZERO=new T(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,b,_){this.X=I("x",y),this.Y=I("y",b,!0),this.Z=I("z",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:b,y:_}=y||{};if(!y||!n.isValid(b)||!n.isValid(_))throw new Error("invalid affine point");if(y instanceof T)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(_)?T.ZERO:new T(b,_,n.ONE)}static fromBytes(y){let b=T.fromAffine(v(z(y,void 0,"point")));return b.assertValidity(),b}static fromHex(y){return T.fromBytes(Ne(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,b=!0){return N.createCache(this,y),b||this.multiply(wn),this}assertValidity(){let y=this;if(y.is0()){if(t.allowInfinityPoint&&n.is0(y.X)&&n.eql(y.Y,n.ONE)&&n.is0(y.Z))return;throw new Error("bad point: ZERO")}let{x:b,y:_}=y.toAffine();if(!n.isValid(b)||!n.isValid(_))throw new Error("bad point: x or y not field elements");if(!l(b,_))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){B(y);let{X:b,Y:_,Z:E}=this,{X:w,Y:A,Z:C}=y,L=n.eql(n.mul(b,C),n.mul(w,E)),O=n.eql(n.mul(_,C),n.mul(A,E));return L&&O}negate(){return new T(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b}=s,_=n.mul(b,wn),{X:E,Y:w,Z:A}=this,C=n.ZERO,L=n.ZERO,O=n.ZERO,P=n.mul(E,E),M=n.mul(w,w),K=n.mul(A,A),U=n.mul(E,w);return U=n.add(U,U),O=n.mul(E,A),O=n.add(O,O),C=n.mul(y,O),L=n.mul(_,K),L=n.add(C,L),C=n.sub(M,L),L=n.add(M,L),L=n.mul(C,L),C=n.mul(U,C),O=n.mul(_,O),K=n.mul(y,K),U=n.sub(P,K),U=n.mul(y,U),U=n.add(U,O),O=n.add(P,P),P=n.add(O,P),P=n.add(P,K),P=n.mul(P,U),L=n.add(L,P),K=n.mul(w,A),K=n.add(K,K),P=n.mul(K,U),C=n.sub(C,P),O=n.mul(K,M),O=n.add(O,O),O=n.add(O,O),new T(C,L,O)}add(y){B(y);let{X:b,Y:_,Z:E}=this,{X:w,Y:A,Z:C}=y,L=n.ZERO,O=n.ZERO,P=n.ZERO,M=s.a,K=n.mul(s.b,wn),U=n.mul(b,w),Q=n.mul(_,A),tt=n.mul(E,C),et=n.add(b,_),Z=n.add(w,A);et=n.mul(et,Z),Z=n.add(U,Q),et=n.sub(et,Z),Z=n.add(b,E);let mt=n.add(w,C);return Z=n.mul(Z,mt),mt=n.add(U,tt),Z=n.sub(Z,mt),mt=n.add(_,E),L=n.add(A,C),mt=n.mul(mt,L),L=n.add(Q,tt),mt=n.sub(mt,L),P=n.mul(M,Z),L=n.mul(K,tt),P=n.add(L,P),L=n.sub(Q,P),P=n.add(Q,P),O=n.mul(L,P),Q=n.add(U,U),Q=n.add(Q,U),tt=n.mul(M,tt),Z=n.mul(K,Z),Q=n.add(Q,tt),tt=n.sub(U,tt),tt=n.mul(M,tt),Z=n.add(Z,tt),U=n.mul(Q,Z),O=n.add(O,U),U=n.mul(mt,Z),L=n.mul(et,L),L=n.sub(L,U),U=n.mul(et,Q),P=n.mul(mt,P),P=n.add(P,U),new T(L,O,P)}subtract(y){return B(y),this.add(y.negate())}is0(){return this.equals(T.ZERO)}multiply(y){let{endo:b}=t;if(!o.isValidNot0(y))throw new RangeError("invalid scalar: out of range");let _,E,w=A=>N.cached(this,A,C=>ye(T,C));if(b){let{k1neg:A,k1:C,k2neg:L,k2:O}=D(y),{p:P,f:M}=w(C),{p:K,f:U}=w(O);E=M.add(U),_=R(b.beta,P,K,A,L)}else{let{p:A,f:C}=w(y);_=A,E=C}return ye(T,[_,E])[0]}multiplyUnsafe(y){let{endo:b}=t,_=this,E=y;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===kt||_.is0())return T.ZERO;if(E===ae)return _;if(N.hasCache(this))return this.multiply(E);if(b){let{k1neg:w,k1:A,k2neg:C,k2:L}=D(E),{p1:O,p2:P}=wa(T,_,A,L);return R(b.beta,O,P,w,C)}else return N.unsafe(_,E)}toAffine(y){let b=this,_=y,{X:E,Y:w,Z:A}=b;if(n.eql(A,n.ONE))return{x:E,y:w};let C=b.is0();_==null&&(_=C?n.ONE:n.inv(A));let L=n.mul(E,_),O=n.mul(w,_),P=n.mul(A,_);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(P,n.ONE))throw new Error("invZ was invalid");return{x:L,y:O}}isTorsionFree(){let{isTorsionFree:y}=t;return i===ae?!0:y?y(T,this):N.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=t;return i===ae?this:y?y(T,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ae?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return At(y,"isCompressed"),this.assertValidity(),S(T,this,y)}toHex(y=!0){return Fe(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let F=o.BITS,N=new qe(T,t.endo?Math.ceil(F/2):F);return F>=8&&T.BASE.precompute(8),Object.freeze(T.prototype),Object.freeze(T),T}function $a(r){return Uint8Array.of(r?2:3)}function Ga(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ml(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?yr:t.randomBytes,o=Object.assign(Ga(r.Fp,e),{seed:Math.max(Vo(e.ORDER),16)});function s(p){try{let S=e.fromBytes(p);return e.isValidNot0(S)}catch{return!1}}function i(p,S){let{publicKey:v,publicKeyUncompressed:m}=o;try{let l=p.length;return S===!0&&l!==v||S===!1&&l!==m?!1:!!r.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Ho(z(p,o.seed,"seed"),e.ORDER)}function c(p,S=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(S)}function f(p){let{secretKey:S,publicKey:v,publicKeyUncompressed:m}=o,l=e._lengths;if(!he(p))return;let g=z(p,void 0,"key").length,x=g===v||g===m,I=g===S||!!l?.includes(g);if(!(x&&I))return x}function d(p,S,v=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(S)===!1)throw new Error("second arg must be public key");let m=e.fromBytes(p);return r.fromBytes(S).multiply(m).toBytes(v)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},u=cn(a,c);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:u,Point:r,utils:h,lengths:o})}function Za(r,t,e={}){let n=t;Zr(n),Bt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?yr:e.randomBytes,s=e.hmac===void 0?(E,w)=>qa(n,E,w):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:f}=a,{keygen:d,getPublicKey:h,getSharedSecret:u,utils:p,lengths:S}=ml(r,e),v={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},m=c*Ha+ae<i.ORDER;function l(E){let w=c>>ae;return E>w}function g(E,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return w}function x(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function I(E,w){Es(w);let A=S.signature,C=w==="compact"?A:w==="recovered"?A+1:void 0;return z(E,C)}class B{r;s;recovery;constructor(w,A,C){if(this.r=g("r",w),this.s=g("s",A),C!=null){if(x(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(w,A=v.format){I(w,A);let C;if(A==="der"){let{r:M,s:K}=Lt.toSig(z(w));return new B(M,K)}A==="recovered"&&(C=w[0],A="compact",w=w.subarray(1));let L=S.signature/2,O=w.subarray(0,L),P=w.subarray(L,L*2);return new B(a.fromBytes(O),a.fromBytes(P),C)}static fromHex(w,A){return this.fromBytes(Ne(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,L=this.assertRecovery(),O=L===2||L===3?A+c:A;if(!i.isValid(O))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=i.toBytes(O),M=r.fromBytes(J($a((L&1)===0),P)),K=a.inv(O),U=R(z(w,void 0,"msgHash")),Q=a.create(-U*K),tt=a.create(C*K),et=r.BASE.multiplyUnsafe(Q).add(M.multiplyUnsafe(tt));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return l(this.s)}toBytes(w=v.format){if(Es(w),w==="der")return Ne(Lt.hexFromSig(this));let{r:A,s:C}=this,L=a.toBytes(A),O=a.toBytes(C);return w==="recovered"?(x(),J(Uint8Array.of(this.assertRecovery()),L,O)):J(L,O)}toHex(w){return Fe(this.toBytes(w))}}Object.freeze(B.prototype),Object.freeze(B);let D=e.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let A=pe(w),C=w.length*8-f;return C>0?A>>BigInt(C):A}:e.bits2int,R=e.bits2int_modN===void 0?function(w){return a.create(D(w))}:e.bits2int_modN,T=wr(f);function F(E){return Ue("num < 2^"+f,E,kt,T),a.toBytes(E)}function N(E,w){return z(E,void 0,"message"),w?z(n(E),void 0,"prehashed message"):E}function k(E,w,A){let{lowS:C,prehash:L,extraEntropy:O}=ws(A,v);E=N(E,L);let P=R(E),M=a.fromBytes(w);if(!a.isValidNot0(M))throw new Error("invalid private key");let K=[F(M),F(P)];if(O!=null&&O!==!1){let et=O===!0?o(S.secretKey):O;K.push(z(et,void 0,"extraEntropy"))}let U=J(...K),Q=P;function tt(et){let Z=D(et);if(!a.isValidNot0(Z))return;let mt=a.inv(Z),Be=r.BASE.multiply(Z).toAffine(),nr=a.create(Be.x);if(nr===kt)return;let Mr=a.create(mt*a.create(Q+nr*M));if(Mr===kt)return;let oi=(Be.x===nr?0:2)|Number(Be.y&ae),si=Mr;return C&&l(Mr)&&(si=a.neg(Mr),oi^=1),new B(nr,si,m?void 0:oi)}return{seed:U,k2sig:tt}}function y(E,w,A={}){let{seed:C,k2sig:L}=k(E,w,A);return na(n.outputLen,a.BYTES,s)(C,L).toBytes(A.format)}function b(E,w,A,C={}){let{lowS:L,prehash:O,format:P}=ws(C,v);if(A=z(A,void 0,"publicKey"),w=N(w,O),!he(E)){let M=E instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+M)}I(E,P);try{let M=B.fromBytes(E,P),K=r.fromBytes(A);if(L&&M.hasHighS())return!1;let{r:U,s:Q}=M,tt=R(w),et=a.inv(Q),Z=a.create(tt*et),mt=a.create(U*et),Be=r.BASE.multiplyUnsafe(Z).add(K.multiplyUnsafe(mt));return Be.is0()?!1:a.create(Be.x)===U}catch{return!1}}function _(E,w,A={}){let{prehash:C}=ws(A,v);return w=N(w,C),B.fromBytes(E,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:d,getPublicKey:h,getSharedSecret:u,utils:p,lengths:S,Point:r,sign:y,verify:b,recoverPublicKey:_,Signature:B,hash:n})}var _s={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},gl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ya=BigInt(2);function yl(r){let t=_s.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,d=f*f*r%t,h=j(d,e,t)*d%t,u=j(h,e,t)*d%t,p=j(u,Ya,t)*f%t,S=j(p,o,t)*p%t,v=j(S,s,t)*S%t,m=j(v,a,t)*v%t,l=j(m,c,t)*m%t,g=j(l,a,t)*v%t,x=j(g,e,t)*d%t,I=j(x,i,t)*S%t,B=j(I,n,t)*f%t,D=j(B,Ya,t);if(!vs.eql(vs.sqr(D),r))throw new Error("Cannot find square root");return D}var vs=ze(_s.p,{sqrt:yl}),bl=ja(_s,{Fp:vs,endo:gl}),$e=Za(bl,ta);function Xa(r,t,e,n){let o=fr.digest(e instanceof Uint8Array?e:e.subarray());if(hn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),$e.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new _r(String(s))});try{return n?.signal?.throwIfAborted(),$e.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new _r(String(s))}}var En=class{type="secp256k1";raw;_key;constructor(t){this._key=Qa(t),this.raw=Wa(this._key)}toMultihash(){return St.digest(Pe(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:ft(this.raw,t.raw)}verify(t,e,n){return Xa(this._key,e,t,n)}};function Ja(r){return new En(r)}function Wa(r){return $e.Point.fromBytes(r).toBytes()}function Qa(r){try{return $e.Point.fromBytes(r),r}catch(t){throw new Kr(String(t))}}function tc(r){let{Type:t,Data:e}=Cr.decode(r.digest),n=e??new Uint8Array;switch(t){case pt.Ed25519:return Da(n);case pt.secp256k1:return Ja(n);case pt.ECDSA:return Ni(n);default:throw new or}}function Pe(r){return Cr.encode({Type:pt[r.type],Data:r.raw})}var ec=Symbol.for("nodejs.util.inspect.custom"),xl=114,Dr=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()})`}[Xn]=!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(xl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ft(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ft(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ec](){return`PeerId(${this.toString()})`}},Sn=class extends Dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},vn=class extends Dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},_n=class extends Dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},wl=2336,An=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=St.digest(H(this.url))}[ec](){return`PeerId(${this.url})`}[Xn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(wl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=W(t)),t.toString()===this.toString())}};function In(r){if(Sl(r))return new Sn({multihash:r});if(El(r))try{let t=tc(r);if(t.type==="Ed25519")return new vn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new _n({multihash:r,publicKey:t})}catch{let e=W(r.digest);return new An(new URL(e))}throw new qr("Supplied PeerID Multihash is invalid")}function El(r){return r.code===St.code}function Sl(r){return r.code===fr.code}function As(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 Bn(r){let t=ue(Y.decode(`z${r}`));return In(t)}var Tn=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 As(this.set.entries(),t=>{let e=Bn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Bn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return As(this.set.values(),t=>Bn(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 Is(){return new Tn}var Bs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},rc={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},nc=new globalThis.TextEncoder;function vl(r,t){let e=Bs[t],n=rc[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function _l(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Bs[t],o=rc[t],s=r;for(;s.length>0;){let i=nc.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 Ts(r,{size:t=32,utf8Buffer:e}={}){if(!Bs[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 _l(r,t,e);r=nc.encode(r)}return vl(r,t)}var Rr={hash:r=>Number(Ts(r,{size:32})),hashV:(r,t)=>Al(Rr.hash(r,t))};function Al(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),H(t,"base16")}var Ls=64,Ct=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Ls)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=Et(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?ft(this.fp,t.fp):!1}};function we(r,t){return Math.floor(Math.random()*(t-r))+r}var Ee=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Ct))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Ct))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 Ct))throw new TypeError("Invalid Fingerprint");let e=we(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Ct))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Il=500,Or=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??Rr,this.seed=t.seed??we(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=H(t));let e=new Ct(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 Ee(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Ee(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[we(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Ee(this.bucketSize));for(let a=0;a<Il;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 Ee(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=H(t));let e=new Ct(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=H(t));let e=new Ct(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}},Bl={1:.5,2:.84,4:.95,8:.98};function Tl(r=.001){return r>.002?2:r>1e-5?4:8}function oc(r,t=.001){let e=Tl(t),n=Bl[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Ls);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Ln=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??Rr,this.seed=t.seed??we(0,Math.pow(2,10)),this.filterSeries=[new Or({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=H(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 Or({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=H(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=H(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 Cs(r,t=.001,e){return new Ln({...oc(r,t),...e??{}})}function Ll(r){let t=r.getComponents(),e={},n=0;return t[n]?.name==="ip6zone"&&(e.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(e.type=t[n].name,e.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(e.type=t[n].name,e.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(e.protocol=t[n].name==="tcp"?"tcp":"udp",e.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(e.type==="ip4"?e.cidr=parseInt(`${t[n].value}`):e.type==="ip6"&&(e.cidr=`${t[n].value}`),n++),e.type==null||e.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e)}function Dt(r){let t=Ll(r);if(t==null)throw new ht(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var Cn=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",f=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let u=Number.parseInt(h,t);if(!Number.isNaN(u))return u});if(d===void 0)break;if(s*=t,s+=d,s>f||(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 sc=45,Cl=15,Ge=new Cn;function Dn(r){if(!(r.length>Cl))return Ge.new(r).parseWith(()=>Ge.readIPv4Addr())}function Rn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>sc))return Ge.new(r).parseWith(()=>Ge.readIPv6Addr())}function Ze(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>sc)return;let e=Ge.new(r).parseWith(()=>Ge.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 ic(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 ac(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 Ds(r){switch(r.length){case Se:return r.join(".");case ve:{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 cc(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 fc(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Se=4,ve=16,Hy=parseInt("0xFFFF",16),Dl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Pr(r,t){t.length===ve&&r.length===Se&&ic(t,0,11)&&(t=t.slice(12)),t.length===Se&&r.length===ve&&ac(r,Dl,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 uc(r,t){if(typeof t=="string"&&(t=Ze(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 Rs(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Se,o=Dn(t);if(o==null&&(n=ve,o=Rn(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=Os(s,8*n);return{network:Pr(o,i),mask:i}}function Os(r,t){if(t!==8*Se&&t!==8*ve)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 kr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Rs(t));else{let n=Ze(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=Ze(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Os(o,8*n.length);this.network=Pr(n,this.mask)}}contains(t){return uc({network:this.network,mask:this.mask},t)}toString(){let t=cc(this.mask),e=t!==-1?String(t):fc(this.mask);return Ds(this.network)+"/"+e}};function lc(r,t){return new kr(r).contains(t)}function dc(r){try{let t=Dt(r);return t.type==="ip6"?lc("2000::/3",t.host):!1}catch{return!1}}function Ye(r){return!!Dn(r)}function On(r){return!!Rn(r)}var gc=Vc(mc(),1),Ul=["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"],Ml=Ul.map(r=>new gc.Netmask(r));function zs(r){for(let t of Ml)if(t.contains(r))return!0;return!1}function zl(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Kl(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 zs(o)}function ql(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Vl(r){let t=r.split(":"),e=t[t.length-1];return zs(e)}function Hl(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 yc(r){if(Ye(r))return zs(r);if(zl(r))return Kl(r);if(ql(r))return Vl(r);if(On(r))return Hl(r)}function Ks(r){try{let t=Dt(r);switch(t.type){case"ip4":case"ip6":return yc(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var at=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Gt=class extends Error{static name="ValidationError";name="ValidationError"},kn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Fn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Vs(r){return t=>W(t,r)}function Hs(r){return t=>H(t,r)}function Je(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Ae(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function bc(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=H(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ae(n);return Rt([e,o],e.length+o.length)}function xc(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=Xt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ae(n);return Rt([e,o],e.length+o.length)}function js(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=W(t,"base32"),o=Je(e);return`${n}:${o}`}var $s=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 at("Invalid byte value in IP address");t[n]=o}),t},wc=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Ye(e[n]),i;s&&(i=$s(e[n]),e[n]=W(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,W(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 at("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ec=function(r){if(r.byteLength!==4)throw new at("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Sc=function(r){if(r.byteLength!==16)throw new at("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 at(`Invalid IPv6 address "${e}"`)}};function vc(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new at(`Invalid IPv6 address "${r}"`)}}var qs=Object.values(ur).map(r=>r.decoder),jl=(function(){let r=qs[0].or(qs[1]);return qs.slice(2).forEach(t=>r=r.or(t)),r})();function _c(r){return jl.decode(r)}function Ac(r){return t=>r.encoder.encode(t)}function $l(r){if(parseInt(r).toString()!==r)throw new Gt("Value must be an integer")}function Gl(r){if(r<0)throw new Gt("Value must be a positive integer, or zero")}function Zl(r){return t=>{if(t>r)throw new Gt(`Value must be smaller than or equal to ${r}`)}}function Yl(...r){return t=>{for(let e of r)e(t)}}var Fr=Yl($l,Gl,Zl(65535));var ot=-1,Gs=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 Fn(`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)}))}},Zt=new Gs,kd=[{code:4,name:"ip4",size:32,valueToBytes:$s,bytesToValue:Ec,validate:r=>{if(!Ye(r))throw new Gt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ae,bytesToValue:Je,validate:Fr},{code:273,name:"udp",size:16,valueToBytes:Ae,bytesToValue:Je,validate:Fr},{code:33,name:"dccp",size:16,valueToBytes:Ae,bytesToValue:Je,validate:Fr},{code:41,name:"ip6",size:128,valueToBytes:wc,bytesToValue:Sc,stringToValue:vc,validate:r=>{if(!On(r))throw new Gt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ot},{code:43,name:"ipcidr",size:8,bytesToValue:Vs("base10"),valueToBytes:Hs("base10")},{code:53,name:"dns",size:ot},{code:54,name:"dns4",size:ot},{code:55,name:"dns6",size:ot},{code:56,name:"dnsaddr",size:ot},{code:132,name:"sctp",size:16,valueToBytes:Ae,bytesToValue:Je,validate:Fr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ot,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ot,bytesToValue:Vs("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Hs("base58btc")(r):ct.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:js,valueToBytes:bc},{code:445,name:"onion3",size:296,bytesToValue:js,valueToBytes:xc},{code:446,name:"garlic64",size:ot},{code:447,name:"garlic32",size:ot},{code:448,name:"tls"},{code:449,name:"sni",size:ot},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ot,bytesToValue:Ac(ho),valueToBytes:_c},{code:480,name:"http"},{code:481,name:"http-path",size:ot,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:ot}];kd.forEach(r=>{Zt.addProtocol(r)});function Ic(r){let t=[],e=0;for(;e<r.length;){let n=Ar(r,e),o=Zt.getProtocol(n),s=gt(n),i=Fd(o,r,e+s),a=0;i>0&&o.size===ot&&(a=gt(i));let c=s+a+i,f={code:n,name:o.name,bytes:vt(r.subarray(e,e+c))};if(i>0){let d=e+s+a,h=r.subarray(d,d+i);f.value=o.bytesToValue?.(h)??W(h)}t.push(f),e+=c}return t}function Bc(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Zt.getProtocol(n.code),s=gt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??H(n.value),a=i.byteLength,o.size===ot&&(c=gt(a)));let f=new Uint8Array(s+c+a),d=0;He(n.code,f,d),d+=s,i!=null&&(o.size===ot&&(He(a,f,d),d+=c),f.set(i,d)),n.bytes=f}e.push(n.bytes),t+=n.bytes.byteLength}return Rt(e,t)}function Tc(r){if(r.charAt(0)!=="/")throw new at('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=Zt.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 at(`Component ${o} was missing value`);e="value"}else if(e==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new at(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new at("Incomplete multiaddr");return t}function Lc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Zt.getProtocol(t.code);if(e==null)throw new at(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Fd(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Ar(t,e)}var Nd=Symbol.for("nodejs.util.inspect.custom"),Zs=Symbol.for("@multiformats/multiaddr");function Ud(r){if(r==null&&(r="/"),Cc(r))return r.getComponents();if(r instanceof Uint8Array)return Ic(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Tc(r);if(Array.isArray(r))return r;throw new at("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Un=class r{[Zs]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Ud(t),e.validate!==!1&&Md(this)}get bytes(){return this.#r==null&&(this.#r=Bc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Lc(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 kn(`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 ft(this.bytes,t.bytes)}[Nd](){return`Multiaddr(${this.toString()})`}};function Md(r){r.getComponents().forEach(t=>{let e=Zt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function Cc(r){return!!r?.[Zs]}function Dc(r){return new Un(r)}function tr(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Mn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},er=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Mn(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 Mn(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 Ys=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function zn(r={}){return zd(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 zd(r,t){t=t??{};let e=t.onEnd,n=new er,o,s,i,a=tr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,l)=>{s=g=>{s=null,n.push(g);try{m(r(n))}catch(x){l(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=tr()})}},f=m=>s!=null?s(m):(n.push(m),o),d=m=>(n=new er,s!=null?s({error:m}):(n.push({error:m}),o)),h=m=>{if(i)return o;if(t?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:m})},u=m=>i?o:(i=!0,m!=null?d(m):f({done:!0})),p=()=>(n=new er,u(),{done:!0}),S=m=>(u(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:S,push:h,end:u,get readableLength(){return n.size},onEmpty:async m=>{let l=m?.signal;if(l?.throwIfAborted(),n.isEmpty())return;let g,x;l!=null&&(g=new Promise((I,B)=>{x=()=>{B(new Ys)},l.addEventListener("abort",x)}));try{await Promise.race([a.promise,g])}finally{x!=null&&l!=null&&l?.removeEventListener("abort",x)}}},e==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(m){return v.throw(m),e!=null&&(e(m),e=void 0),{done:!0}},return(){return v.return(),e!=null&&(e(),e=void 0),{done:!0}},push:h,end(m){return v.end(m),e!=null&&(e(m),e=void 0),o},get readableLength(){return v.readableLength},onEmpty:m=>v.onEmpty(m)},o}var Xs=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Rc=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Ws(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,d=new Promise((h,u)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){u(Rc(i));return}if(i&&(c=()=>{u(Rc(i))},i.addEventListener("abort",c,{once:!0})),r.then(h,u),e===Number.POSITIVE_INFINITY)return;let p=new Xs;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(S){u(S)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?u(o):(p.message=o??`Promise timed out after ${e} milliseconds`,u(p))},e)}).finally(()=>{d.clear(),c&&i&&i.removeEventListener("abort",c)});return d.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},d}var Kd=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 qd(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:f,removeListener:d}=Kd(r),h=async(...p)=>{let S=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(S))return}catch(v){n(),i(v);return}c.push(S),e.count===c.length&&(n(),s(c))},u=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)d(p,h);for(let p of e.rejectionEvents)a.includes(p)||d(p,u)};for(let p of a)f(p,h);for(let p of e.rejectionEvents)a.includes(p)||f(p,u);e.signal&&e.signal.addEventListener("abort",()=>{u(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=Ws(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function rr(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=qd(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Nr(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Kn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Ie=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Vd(r){return r.reason}async function Ur(r,t,e){if(t==null)return r;let n=e?.translateError??Vd;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 qn=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=tr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Nt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Hd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Vn=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,e){this.id=Hd(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Nt),this.cleanup())}async join(t){let e=new qn(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 Ur(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 Hn=class extends Vr{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=Nr(this.emitEmpty.bind(this),1),this.emitIdle=Nr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Kn;let n=new Vn(t,e);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(e).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Nt)}),this.clear()}async onEmpty(t){this.size!==0&&await rr(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await rr(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await rr(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=zn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Nt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function jn(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 jd=4194304,$n=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Js=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ti=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ei=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $d(r){return typeof r?.closeRead=="function"}function Gd(r){return typeof r?.close=="function"}function Qs(r){return $d(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:Gd(r)?r.status!=="open":!1}function Zd(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Yd(r,t){let e=t?.maxBufferSize??jd,n=new rt,o,s=!1;if(!Zd(r))throw new ht("Argument should be a Stream or a Multiaddr");let i=d=>{if(n.append(d.data),n.byteLength>e){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let a=d=>{d.error!=null?o?.reject(d.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(d){if(s===!0)throw new $n("Stream was unwrapped");if(Qs(r)){if(n.byteLength===0&&d?.bytes==null)return null;if(d?.bytes!=null&&n.byteLength<d.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new Ie(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let h=d?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await Ur(o.promise,d?.signal),Qs(r)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let u=d?.bytes??n.byteLength;if(n.byteLength<u){if(Qs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,u),new Ie(`Unexpected EOF - stream closed while reading ${n.byteLength}/${u} bytes`);return f.read(d)}let p=n.sublist(0,u);return n.consume(u),p},async write(d,h){if(s===!0)throw new $n("Stream was unwrapped");r.send(d)||await rr(r,"drain",{signal:h?.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 f}function Xd(r,t={}){let e=Yd(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=gt(t.maxDataLength));let n=t?.lengthDecoder??Ar,o=t?.lengthEncoder??Ra;return{async read(i){let a=-1,c=new rt;for(;;){let d=await e.read({...i,bytes:1});if(d==null)break;c.append(d);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Js("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ei(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ti(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await e.read({...i,bytes:a});if(f==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new Ie(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Ie(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await e.write(new rt(o(i.byteLength),i),a)},async writeV(i,a){let c=new rt(...i.flatMap(f=>[o(f.byteLength),f]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function ri(r,t){let e=Xd(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 Gn=class extends Hn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Oc(r,t,e){let n,o,s=!1;function i(){let f={signal:o.signal},d;e?.timeout!=null&&(d=jn([o.signal,AbortSignal.timeout(e.timeout)]),f.signal=d),s=!0,Promise.resolve().then(async()=>{await r(f)}).catch(()=>{}).finally(()=>{d!=null&&(d.aborted?d.clear():d.addEventListener("abort",()=>{d.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Nr(i,e?.debounce??100),c=!1;return{setInterval:f=>{t!==f&&(t=f,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:f=>{e??={},e.timeout=f},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 ni=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 Pc(r){let{name:t,metrics:e}=r,n;return e!=null?n=new ni({name:t,metrics:e}):n=new Map,n}var kc="libp2p",Fc="autonat",Nc="1.0.0";var V;(function(r){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),(function(u){u.codec=()=>je(e)})(t=r.MessageType||(r.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(u){u.codec=()=>je(o)})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let p;u.codec=()=>(p==null&&(p=$t((l,g,x={})=>{if(x.lengthDelimited!==!1&&g.fork(),l.id!=null&&(g.uint32(10),g.bytes(l.id)),l.addrs!=null&&l.addrs.length>0)for(let I of l.addrs)g.uint32(18),g.bytes(I);x.lengthDelimited!==!1&&g.ldelim()},(l,g,x={})=>{let I={addrs:[]},B=g==null?l.len:l.pos+g;for(;l.pos<B;){let D=l.uint32();switch(D>>>3){case 1:{I.id=l.bytes();break}case 2:{if(x.limits?.addrs!=null&&I.addrs.length===x.limits.addrs)throw new Lr('Decode error - repeated field "addrs" had too many elements');I.addrs.push(l.bytes());break}default:{l.skipType(D&7);break}}}return I},function*(l,g,x,I={}){let B={addrs:0},D=g==null?l.len:l.pos+g;for(;l.pos<D;){let R=l.uint32();switch(R>>>3){case 1:{yield{field:`${x}.id`,value:l.bytes()};break}case 2:{if(I.limits?.addrs!=null&&B.addrs===I.limits.addrs)throw new Lr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${x}.addrs[]`,index:B.addrs,value:l.bytes()},B.addrs++;break}default:{l.skipType(R&7);break}}}})),p);function S(l){return Ht(l,u.codec())}u.encode=S;function v(l,g){return Vt(l,u.codec(),g)}u.decode=v;function m(l,g){return jt(l,u.codec(),g)}u.stream=m})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let p;u.codec=()=>(p==null&&(p=$t((l,g,x={})=>{x.lengthDelimited!==!1&&g.fork(),l.peer!=null&&(g.uint32(10),r.PeerInfo.codec().encode(l.peer,g)),x.lengthDelimited!==!1&&g.ldelim()},(l,g,x={})=>{let I={},B=g==null?l.len:l.pos+g;for(;l.pos<B;){let D=l.uint32();D>>>3===1?I.peer=r.PeerInfo.codec().decode(l,l.uint32(),{limits:x.limits?.peer}):l.skipType(D&7)}return I},function*(l,g,x,I={}){let B=g==null?l.len:l.pos+g;for(;l.pos<B;){let D=l.uint32();D>>>3===1?yield*r.PeerInfo.codec().stream(l,l.uint32(),`${x}.peer`,{limits:I.limits?.peer}):l.skipType(D&7)}})),p);function S(l){return Ht(l,u.codec())}u.encode=S;function v(l,g){return Vt(l,u.codec(),g)}u.decode=v;function m(l,g){return jt(l,u.codec(),g)}u.stream=m})(i=r.Dial||(r.Dial={}));let a;(function(u){let p;u.codec=()=>(p==null&&(p=$t((l,g,x={})=>{x.lengthDelimited!==!1&&g.fork(),l.status!=null&&(g.uint32(8),r.ResponseStatus.codec().encode(l.status,g)),l.statusText!=null&&(g.uint32(18),g.string(l.statusText)),l.addr!=null&&(g.uint32(26),g.bytes(l.addr)),x.lengthDelimited!==!1&&g.ldelim()},(l,g,x={})=>{let I={},B=g==null?l.len:l.pos+g;for(;l.pos<B;){let D=l.uint32();switch(D>>>3){case 1:{I.status=r.ResponseStatus.codec().decode(l);break}case 2:{I.statusText=l.string();break}case 3:{I.addr=l.bytes();break}default:{l.skipType(D&7);break}}}return I},function*(l,g,x,I={}){let B=g==null?l.len:l.pos+g;for(;l.pos<B;){let D=l.uint32();switch(D>>>3){case 1:{yield{field:`${x}.status`,value:r.ResponseStatus.codec().decode(l)};break}case 2:{yield{field:`${x}.statusText`,value:l.string()};break}case 3:{yield{field:`${x}.addr`,value:l.bytes()};break}default:{l.skipType(D&7);break}}}})),p);function S(l){return Ht(l,u.codec())}u.encode=S;function v(l,g){return Vt(l,u.codec(),g)}u.decode=v;function m(l,g){return jt(l,u.codec(),g)}u.stream=m})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=$t((u,p,S={})=>{S.lengthDelimited!==!1&&p.fork(),u.type!=null&&(p.uint32(8),r.MessageType.codec().encode(u.type,p)),u.dial!=null&&(p.uint32(18),r.Dial.codec().encode(u.dial,p)),u.dialResponse!=null&&(p.uint32(26),r.DialResponse.codec().encode(u.dialResponse,p)),S.lengthDelimited!==!1&&p.ldelim()},(u,p,S={})=>{let v={},m=p==null?u.len:u.pos+p;for(;u.pos<m;){let l=u.uint32();switch(l>>>3){case 1:{v.type=r.MessageType.codec().decode(u);break}case 2:{v.dial=r.Dial.codec().decode(u,u.uint32(),{limits:S.limits?.dial});break}case 3:{v.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:S.limits?.dialResponse});break}default:{u.skipType(l&7);break}}}return v},function*(u,p,S,v={}){let m=p==null?u.len:u.pos+p;for(;u.pos<m;){let l=u.uint32();switch(l>>>3){case 1:{yield{field:`${S}.type`,value:r.MessageType.codec().decode(u)};break}case 2:{yield*r.Dial.codec().stream(u,u.uint32(),`${S}.dial`,{limits:v.limits?.dial});break}case 3:{yield*r.DialResponse.codec().stream(u,u.uint32(),`${S}.dialResponse`,{limits:v.limits?.dialResponse});break}default:{u.skipType(l&7);break}}}})),c);function f(u){return Ht(u,r.codec())}r.encode=f;function d(u,p){return Vt(u,r.codec(),p)}r.decode=d;function h(u,p){return jt(u,r.codec(),p)}r.stream=h})(V||(V={}));var rh=4,nh=8,Zn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${e.protocolPrefix??kc}/${Fc}/${Nc}`,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=Pc({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=Oc(this.findRandomPeers.bind(this),6e4),this.addressFilter=Cs(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ai]=["@libp2p/autonat"];get[ci](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,e)=>{this.handleIncomingAutonatStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=jn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,e){let n=AbortSignal.timeout(this.timeout);try{let o=ri(t,{maxDataLength:this.maxMessageSize}).pb(V),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,e,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(h=>Dt(h).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("peerId missing from message"),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let h=ue(a.id);i=In(h)}catch(h){return this.log.error("invalid PeerId - %e",h),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(h=>Dc(h)).filter(h=>{try{let u=Dt(h);return Ks(h)?!1:u.host!==Dt(e.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",h,e.remoteAddr),!1):o.includes(u.host)?!1:this.components.transportManager.dialTransportForMultiaddr(h)==null?(this.log.trace("not dialing %a - transport unsupported",h),!1):!0}catch{return!1}}).map(h=>(h.getComponents().find(u=>u.code===421)?.value==null&&(h=h.encapsulate(`/p2p/${i.toString()}`)),h));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(h=>h.toString()).join(", "),i);let f="",d=c[0];for(let h of c){let u;d=h;try{if(u=await this.components.connectionManager.openConnection(h,n),!u.remoteAddr.equals(h))throw this.log.error("tried to dial %a but dialed %a",h,u.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,h),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.OK,addr:u.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),f=p.message}finally{u!=null&&await u.close()}}return{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_DIAL_ERROR,statusText:f,addr:d.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||Dt(o.multiaddr).type==="ip6"&&(!e||!dc(o.multiaddr))||Ks(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:Is(),queue:new Gn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>Dt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=ri(i).pb(V),[,c]=await Promise.all([a.write({type:V.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==V.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let f=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,f),f!==V.ResponseStatus.OK&&f!==V.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),f===V.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else f===V.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===rh&&this.confirmAddress(o),o.failure===nh&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=Dt(t);switch(e.type){case"ip4":return e.host.split(".")[0].padStart(3,"0");case"ip6":return e.host.split(":")[0].padStart(4,"0");default:throw new ht(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function oh(r={}){return t=>new Zn(t,r)}return Hc(sh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: