@libp2p/autonat 2.0.16-b56d91884 → 2.0.16-e2ec7bdaa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PAutonat=(()=>{var wa=Object.create;var ir=Object.defineProperty;var ba=Object.getOwnPropertyDescriptor;var ya=Object.getOwnPropertyNames;var Ea=Object.getPrototypeOf,va=Object.prototype.hasOwnProperty;var dn=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)ir(r,e,{get:t[e],enumerable:!0})},us=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ya(t))!va.call(r,o)&&o!==e&&ir(r,o,{get:()=>t[o],enumerable:!(n=ba(t,o))||n.enumerable});return r};var fs=(r,t,e)=>(e=r!=null?wa(Ea(r)):{},us(t||!r||!r.__esModule?ir(e,"default",{value:r,enumerable:!0}):e,r)),Sa=r=>us(ir({},"__esModule",{value:!0}),r);var Bi=dn((tr,zr)=>{(function(r,t){"use strict";var e={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(u){if(!Array.isArray(u)&&!ArrayBuffer.isView(u))return!1;for(var p=0;p<u.length;p++)if(!Number.isInteger(u[p])||u[p]<0||u[p]>255)return!1;return!0}function o(u,p){return(u&65535)*p+(((u>>>16)*p&65535)<<16)}function s(u,p){return u<<p|u>>>32-p}function i(u){return u^=u>>>16,u=o(u,2246822507),u^=u>>>13,u=o(u,3266489909),u^=u>>>16,u}function a(u,p){u=[u[0]>>>16,u[0]&65535,u[1]>>>16,u[1]&65535],p=[p[0]>>>16,p[0]&65535,p[1]>>>16,p[1]&65535];var g=[0,0,0,0];return g[3]+=u[3]+p[3],g[2]+=g[3]>>>16,g[3]&=65535,g[2]+=u[2]+p[2],g[1]+=g[2]>>>16,g[2]&=65535,g[1]+=u[1]+p[1],g[0]+=g[1]>>>16,g[1]&=65535,g[0]+=u[0]+p[0],g[0]&=65535,[g[0]<<16|g[1],g[2]<<16|g[3]]}function c(u,p){u=[u[0]>>>16,u[0]&65535,u[1]>>>16,u[1]&65535],p=[p[0]>>>16,p[0]&65535,p[1]>>>16,p[1]&65535];var g=[0,0,0,0];return g[3]+=u[3]*p[3],g[2]+=g[3]>>>16,g[3]&=65535,g[2]+=u[2]*p[3],g[1]+=g[2]>>>16,g[2]&=65535,g[2]+=u[3]*p[2],g[1]+=g[2]>>>16,g[2]&=65535,g[1]+=u[1]*p[3],g[0]+=g[1]>>>16,g[1]&=65535,g[1]+=u[2]*p[2],g[0]+=g[1]>>>16,g[1]&=65535,g[1]+=u[3]*p[1],g[0]+=g[1]>>>16,g[1]&=65535,g[0]+=u[0]*p[3]+u[1]*p[2]+u[2]*p[1]+u[3]*p[0],g[0]&=65535,[g[0]<<16|g[1],g[2]<<16|g[3]]}function l(u,p){return p%=64,p===32?[u[1],u[0]]:p<32?[u[0]<<p|u[1]>>>32-p,u[1]<<p|u[0]>>>32-p]:(p-=32,[u[1]<<p|u[0]>>>32-p,u[0]<<p|u[1]>>>32-p])}function h(u,p){return p%=64,p===0?u:p<32?[u[0]<<p|u[1]>>>32-p,u[1]<<p]:[u[1]<<p-32,0]}function f(u,p){return[u[0]^p[0],u[1]^p[1]]}function d(u){return u=f(u,[0,u[0]>>>1]),u=c(u,[4283543511,3981806797]),u=f(u,[0,u[0]>>>1]),u=c(u,[3301882366,444984403]),u=f(u,[0,u[0]>>>1]),u}e.x86.hash32=function(u,p){if(e.inputValidation&&!n(u))return t;p=p||0;for(var g=u.length%4,x=u.length-g,w=p,b=0,m=3432918353,v=461845907,_=0;_<x;_=_+4)b=u[_]|u[_+1]<<8|u[_+2]<<16|u[_+3]<<24,b=o(b,m),b=s(b,15),b=o(b,v),w^=b,w=s(w,13),w=o(w,5)+3864292196;switch(b=0,g){case 3:b^=u[_+2]<<16;case 2:b^=u[_+1]<<8;case 1:b^=u[_],b=o(b,m),b=s(b,15),b=o(b,v),w^=b}return w^=u.length,w=i(w),w>>>0},e.x86.hash128=function(u,p){if(e.inputValidation&&!n(u))return t;p=p||0;for(var g=u.length%16,x=u.length-g,w=p,b=p,m=p,v=p,_=0,I=0,y=0,B=0,T=597399067,V=2869860233,F=951274213,O=2716044179,N=0;N<x;N=N+16)_=u[N]|u[N+1]<<8|u[N+2]<<16|u[N+3]<<24,I=u[N+4]|u[N+5]<<8|u[N+6]<<16|u[N+7]<<24,y=u[N+8]|u[N+9]<<8|u[N+10]<<16|u[N+11]<<24,B=u[N+12]|u[N+13]<<8|u[N+14]<<16|u[N+15]<<24,_=o(_,T),_=s(_,15),_=o(_,V),w^=_,w=s(w,19),w+=b,w=o(w,5)+1444728091,I=o(I,V),I=s(I,16),I=o(I,F),b^=I,b=s(b,17),b+=m,b=o(b,5)+197830471,y=o(y,F),y=s(y,17),y=o(y,O),m^=y,m=s(m,15),m+=v,m=o(m,5)+2530024501,B=o(B,O),B=s(B,18),B=o(B,T),v^=B,v=s(v,13),v+=w,v=o(v,5)+850148119;switch(_=0,I=0,y=0,B=0,g){case 15:B^=u[N+14]<<16;case 14:B^=u[N+13]<<8;case 13:B^=u[N+12],B=o(B,O),B=s(B,18),B=o(B,T),v^=B;case 12:y^=u[N+11]<<24;case 11:y^=u[N+10]<<16;case 10:y^=u[N+9]<<8;case 9:y^=u[N+8],y=o(y,F),y=s(y,17),y=o(y,O),m^=y;case 8:I^=u[N+7]<<24;case 7:I^=u[N+6]<<16;case 6:I^=u[N+5]<<8;case 5:I^=u[N+4],I=o(I,V),I=s(I,16),I=o(I,F),b^=I;case 4:_^=u[N+3]<<24;case 3:_^=u[N+2]<<16;case 2:_^=u[N+1]<<8;case 1:_^=u[N],_=o(_,T),_=s(_,15),_=o(_,V),w^=_}return w^=u.length,b^=u.length,m^=u.length,v^=u.length,w+=b,w+=m,w+=v,b+=w,m+=w,v+=w,w=i(w),b=i(b),m=i(m),v=i(v),w+=b,w+=m,w+=v,b+=w,m+=w,v+=w,("00000000"+(w>>>0).toString(16)).slice(-8)+("00000000"+(b>>>0).toString(16)).slice(-8)+("00000000"+(m>>>0).toString(16)).slice(-8)+("00000000"+(v>>>0).toString(16)).slice(-8)},e.x64.hash128=function(u,p){if(e.inputValidation&&!n(u))return t;p=p||0;for(var g=u.length%16,x=u.length-g,w=[0,p],b=[0,p],m=[0,0],v=[0,0],_=[2277735313,289559509],I=[1291169091,658871167],y=0;y<x;y=y+16)m=[u[y+4]|u[y+5]<<8|u[y+6]<<16|u[y+7]<<24,u[y]|u[y+1]<<8|u[y+2]<<16|u[y+3]<<24],v=[u[y+12]|u[y+13]<<8|u[y+14]<<16|u[y+15]<<24,u[y+8]|u[y+9]<<8|u[y+10]<<16|u[y+11]<<24],m=c(m,_),m=l(m,31),m=c(m,I),w=f(w,m),w=l(w,27),w=a(w,b),w=a(c(w,[0,5]),[0,1390208809]),v=c(v,I),v=l(v,33),v=c(v,_),b=f(b,v),b=l(b,31),b=a(b,w),b=a(c(b,[0,5]),[0,944331445]);switch(m=[0,0],v=[0,0],g){case 15:v=f(v,h([0,u[y+14]],48));case 14:v=f(v,h([0,u[y+13]],40));case 13:v=f(v,h([0,u[y+12]],32));case 12:v=f(v,h([0,u[y+11]],24));case 11:v=f(v,h([0,u[y+10]],16));case 10:v=f(v,h([0,u[y+9]],8));case 9:v=f(v,[0,u[y+8]]),v=c(v,I),v=l(v,33),v=c(v,_),b=f(b,v);case 8:m=f(m,h([0,u[y+7]],56));case 7:m=f(m,h([0,u[y+6]],48));case 6:m=f(m,h([0,u[y+5]],40));case 5:m=f(m,h([0,u[y+4]],32));case 4:m=f(m,h([0,u[y+3]],24));case 3:m=f(m,h([0,u[y+2]],16));case 2:m=f(m,h([0,u[y+1]],8));case 1:m=f(m,[0,u[y]]),m=c(m,_),m=l(m,31),m=c(m,I),w=f(w,m)}return w=f(w,[0,u.length]),b=f(b,[0,u.length]),w=a(w,b),b=a(b,w),w=d(w),b=d(b),w=a(w,b),b=a(b,w),("00000000"+(w[0]>>>0).toString(16)).slice(-8)+("00000000"+(w[1]>>>0).toString(16)).slice(-8)+("00000000"+(b[0]>>>0).toString(16)).slice(-8)+("00000000"+(b[1]>>>0).toString(16)).slice(-8)},typeof tr<"u"?(typeof zr<"u"&&zr.exports&&(tr=zr.exports=e),tr.murmurHash3=e):typeof define=="function"&&define.amd?define([],function(){return e}):(e._murmurHash3=r.murmurHash3,e.noConflict=function(){return r.murmurHash3=e._murmurHash3,e._murmurHash3=t,e.noConflict=t,e},r.murmurHash3=e)})(tr)});var Ti=dn((Tp,Li)=>{Li.exports=Bi()});var Hi=dn(or=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var l,h,f,d;return l=(c&255<<24)>>>24,h=(c&255<<16)>>>16,f=(c&65280)>>>8,d=c&255,[l,h,f,d].join(".")},i=function(c){var l,h,f,d,u,p;for(l=[],f=d=0;d<=3&&c.length!==0;f=++d){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}p=t(c),u=p[0],h=p[1],c=c.substring(h),l.push(u)}if(c.length!==0)throw new Error("Invalid IP");switch(l.length){case 1:if(l[0]>4294967295)throw new Error("Invalid IP");return l[0]>>>0;case 2:if(l[0]>255||l[1]>16777215)throw new Error("Invalid IP");return(l[0]<<24|l[1])>>>0;case 3:if(l[0]>255||l[1]>255||l[2]>65535)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2])>>>0;case 4:if(l[0]>255||l[1]>255||l[2]>255||l[3]>255)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2]<<8|l[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var l,h,f,d,u;for(d=0,l=10,h="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,l=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,l=8,h="7")),u=f;f<c.length;){if("0"<=c[f]&&c[f]<=h)d=d*l+(e(c[f])-n)>>>0;else if(l===16)if("a"<=c[f]&&c[f]<="f")d=d*l+(10+e(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")d=d*l+(10+e(c[f])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");f++}if(f===u)throw new Error("empty octet");return[d,f]},r=function(){function c(l,h){var f,d,u,p;if(typeof l!="string")throw new Error("Missing `net' parameter");if(h||(p=l.split("/",2),l=p[0],h=p[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(g){throw f=g,new Error("Invalid mask: "+h)}for(d=u=32;u>=0;d=--u)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(h||h===0)this.bitmask=parseInt(h,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(l)&this.maskLong)>>>0}catch(g){throw f=g,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+h);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new c(l)),l instanceof c?this.contains(l.base)&&this.contains(l.broadcast||l.last):(i(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(l){return l==null&&(l=1),new c(a(this.netLong+this.size*l),this.mask)},c.prototype.forEach=function(l){var h,f,d;for(d=i(this.first),f=i(this.last),h=0;d<=f;)l(a(d),d,h),h++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),or.ip2long=i,or.long2ip=a,or.Netmask=r}).call(or)});var rl={};dt(rl,{autoNAT:()=>el});var pn=Symbol.for("@libp2p/peer-id");var Nt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Oe=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ar=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var cr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Fe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Tt=(r,...t)=>{try{[...t]}catch{}};var ur=class extends EventTarget{#t=new Map;constructor(){super(),Tt(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}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))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ls=Symbol.for("@libp2p/service-capabilities"),hs=Symbol.for("@libp2p/service-dependencies");var bn={};dt(bn,{base58btc:()=>W,base58flickr:()=>Ta});var Nl=new Uint8Array(0);function ds(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 Pt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ps(r){return new TextEncoder().encode(r)}function ms(r){return new TextDecoder().decode(r)}function _a(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),l=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,x=0,w=0,b=p.length;w!==b&&p[w]===0;)w++,g++;for(var m=(b-w)*h+1>>>0,v=new Uint8Array(m);w!==b;){for(var _=p[w],I=0,y=m-1;(_!==0||I<x)&&y!==-1;y--,I++)_+=256*v[y]>>>0,v[y]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");x=I,w++}for(var B=m-x;B!==m&&v[B]===0;)B++;for(var T=c.repeat(g);B<m;++B)T+=r.charAt(v[B]);return T}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var x=0,w=0;p[g]===c;)x++,g++;for(var b=(p.length-g)*l+1>>>0,m=new Uint8Array(b);p[g];){var v=e[p.charCodeAt(g)];if(v===255)return;for(var _=0,I=b-1;(v!==0||_<w)&&I!==-1;I--,_++)v+=a*m[I]>>>0,m[I]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");w=_,g++}if(p[g]!==" "){for(var y=b-w;y!==b&&m[y]===0;)y++;for(var B=new Uint8Array(x+(b-y)),T=x;y!==b;)B[T++]=m[y++];return B}}}function u(p){var g=d(p);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:d,decode:u}}var Aa=_a,Ia=Aa,xs=Ia;var mn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},gn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ws(this,t)}},xn=class{decoders;constructor(t){this.decoders=t}or(t){return ws(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 ws(r,t){return new xn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var wn=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 mn(t,e,n),this.decoder=new gn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ee({name:r,prefix:t,encode:e,decode:n}){return new wn(r,t,e,n)}function Xt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=xs(e,r);return Ee({prefix:t,name:r,encode:n,decode:s=>Pt(o(s))})}function Ba(r,t,e,n){let o={};for(let h=0;h<t.length;++h)o[t[h]]=h;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),a=0,c=0,l=0;for(let h=0;h<s;++h){let f=o[r[h]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,a+=e,a>=8&&(a-=8,i[l++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function La(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;)s+="=";return s}function Q({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ee({prefix:t,name:r,encode(o){return La(o,n,e)},decode(o){return Ba(o,n,e,r)}})}var W=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ta=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yn={};dt(yn,{base32:()=>kt,base32hex:()=>Pa,base32hexpad:()=>Ua,base32hexpadupper:()=>Ca,base32hexupper:()=>ka,base32pad:()=>Da,base32padupper:()=>Na,base32upper:()=>Ra,base32z:()=>Oa});var kt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ra=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Da=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Na=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Pa=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ka=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ua=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ca=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Oa=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var En={};dt(En,{base36:()=>Me,base36upper:()=>Fa});var Me=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fa=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ma=Es,bs=128,za=127,qa=~za,Va=Math.pow(2,31);function Es(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Va;)t[e++]=r&255|bs,r/=128;for(;r&qa;)t[e++]=r&255|bs,r>>>=7;return t[e]=r|0,Es.bytes=e-n+1,t}var Ha=vn,Ka=128,ys=127;function vn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw vn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ys)<<o:(i&ys)*Math.pow(2,o),o+=7}while(i>=Ka);return vn.bytes=s-n,e}var Ga=Math.pow(2,7),ja=Math.pow(2,14),Za=Math.pow(2,21),$a=Math.pow(2,28),Xa=Math.pow(2,35),Wa=Math.pow(2,42),Ya=Math.pow(2,49),Qa=Math.pow(2,56),Ja=Math.pow(2,63),tc=function(r){return r<Ga?1:r<ja?2:r<Za?3:r<$a?4:r<Xa?5:r<Wa?6:r<Ya?7:r<Qa?8:r<Ja?9:10},ec={encode:Ma,decode:Ha,encodingLength:tc},rc=ec,ze=rc;function qe(r,t=0){return[ze.decode(r,t),ze.decode.bytes]}function ve(r,t,e=0){return ze.encode(r,t,e),t}function Se(r){return ze.encodingLength(r)}function ie(r,t){let e=t.byteLength,n=Se(r),o=n+Se(e),s=new Uint8Array(o+e);return ve(r,s,0),ve(e,s,n),s.set(t,o),new _e(r,e,t,s)}function Ut(r){let t=Pt(r),[e,n]=qe(t),[o,s]=qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new _e(e,o,i,t)}function vs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ds(r.bytes,e.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ss(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return oc(e,Sn(r),t??W.encoder);default:return sc(e,Sn(r),t??kt.encoder)}}var _s=new WeakMap;function Sn(r){let t=_s.get(r);if(t==null){let e=new Map;return _s.set(r,e),e}return t}var lt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ic)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=ie(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&&vs(t.multihash,n.multihash)}toString(t){return Ss(this,t)}toJSON(){return{"/":Ss(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??As(n,o,s.bytes))}else if(e[ac]===!0){let{version:n,multihash:o,code:s}=e,i=Ut(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!==Ve)throw new Error(`Version 0 CID must use dag-pb (code: ${Ve}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=As(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ve,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=Pt(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 _e(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[f,d]=qe(t.subarray(e));return e+=d,f},o=n(),s=Ve;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(),l=e+c,h=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(t,e){let[n,o]=nc(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 Sn(s).set(n,t),s}};function nc(r,t){switch(r[0]){case"Q":{let e=t??W;return[W.prefix,e.decode(`${W.prefix}${r}`)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}case kt.prefix:{let e=t??kt;return[kt.prefix,e.decode(r)]}case Me.prefix:{let e=t??Me;return[Me.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 oc(r,t,e){let{prefix:n}=e;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function sc(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 Ve=112,ic=18;function As(r,t,e){let n=Se(r),o=n+Se(t),s=new Uint8Array(o+e.byteLength);return ve(r,s,0),ve(t,s,n),s.set(e,o),s}var ac=Symbol.for("@ipld/js-cid/CID");var _n={};dt(_n,{identity:()=>Ot});var Is=0,cc="identity",Bs=Pt;function uc(r){return ie(Is,Bs(r))}var Ot={code:Is,name:cc,encode:Bs,digest:uc};function xt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ls(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function fc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ae(r,...t){if(!fc(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Ts(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ls(r.outputLen),Ls(r.blockLen)}function Ie(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 Rs(r,t){Ae(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var lr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Et=(r,t)=>r<<32-t|r>>>t;function Ds(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function He(r){return typeof r=="string"&&(r=Ds(r)),Ae(r),r}function An(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ae(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}var Be=class{clone(){return this._cloneInto()}};function hr(r){let t=n=>r().update(He(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function dr(r=32){if(ae&&typeof ae.getRandomValues=="function")return ae.getRandomValues(new Uint8Array(r));if(ae&&typeof ae.randomBytes=="function")return ae.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function lc(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}var Ns=(r,t,e)=>r&t^~r&e,Ps=(r,t,e)=>r&t^r&e^t&e,Le=class extends Be{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=lr(this.buffer)}update(t){Ie(this);let{view:e,buffer:n,blockLen:o}=this;t=He(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=lr(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){Ie(this),Rs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;lc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=lr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,h[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){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.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var pr=BigInt(4294967295),In=BigInt(32);function ks(r,t=!1){return t?{h:Number(r&pr),l:Number(r>>In&pr)}:{h:Number(r>>In&pr)|0,l:Number(r&pr)|0}}function hc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=ks(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var dc=(r,t)=>BigInt(r>>>0)<<In|BigInt(t>>>0),pc=(r,t,e)=>r>>>e,mc=(r,t,e)=>r<<32-e|t>>>e,gc=(r,t,e)=>r>>>e|t<<32-e,xc=(r,t,e)=>r<<32-e|t>>>e,wc=(r,t,e)=>r<<64-e|t>>>e-32,bc=(r,t,e)=>r>>>e-32|t<<64-e,yc=(r,t)=>t,Ec=(r,t)=>r,vc=(r,t,e)=>r<<e|t>>>32-e,Sc=(r,t,e)=>t<<e|r>>>32-e,_c=(r,t,e)=>t<<e-32|r>>>64-e,Ac=(r,t,e)=>r<<e-32|t>>>64-e;function Ic(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Bc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Lc=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Tc=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Rc=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Dc=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Nc=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Pc={fromBig:ks,split:hc,toBig:dc,shrSH:pc,shrSL:mc,rotrSH:gc,rotrSL:xc,rotrBH:wc,rotrBL:bc,rotr32H:yc,rotr32L:Ec,rotlSH:vc,rotlSL:Sc,rotlBH:_c,rotlBL:Ac,add:Ic,add3L:Bc,add3H:Lc,add4L:Tc,add4H:Rc,add5H:Nc,add5L:Dc},C=Pc;var[kc,Uc]=C.split(["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))),Wt=new Uint32Array(80),Yt=new Uint32Array(80),Bn=class extends Le{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:h,Fh:f,Fl:d,Gh:u,Gl:p,Hh:g,Hl:x}=this;return[t,e,n,o,s,i,a,c,l,h,f,d,u,p,g,x]}set(t,e,n,o,s,i,a,c,l,h,f,d,u,p,g,x){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=l|0,this.El=h|0,this.Fh=f|0,this.Fl=d|0,this.Gh=u|0,this.Gl=p|0,this.Hh=g|0,this.Hl=x|0}process(t,e){for(let m=0;m<16;m++,e+=4)Wt[m]=t.getUint32(e),Yt[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let v=Wt[m-15]|0,_=Yt[m-15]|0,I=C.rotrSH(v,_,1)^C.rotrSH(v,_,8)^C.shrSH(v,_,7),y=C.rotrSL(v,_,1)^C.rotrSL(v,_,8)^C.shrSL(v,_,7),B=Wt[m-2]|0,T=Yt[m-2]|0,V=C.rotrSH(B,T,19)^C.rotrBH(B,T,61)^C.shrSH(B,T,6),F=C.rotrSL(B,T,19)^C.rotrBL(B,T,61)^C.shrSL(B,T,6),O=C.add4L(y,F,Yt[m-7],Yt[m-16]),N=C.add4H(O,I,V,Wt[m-7],Wt[m-16]);Wt[m]=N|0,Yt[m]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:h,Eh:f,El:d,Fh:u,Fl:p,Gh:g,Gl:x,Hh:w,Hl:b}=this;for(let m=0;m<80;m++){let v=C.rotrSH(f,d,14)^C.rotrSH(f,d,18)^C.rotrBH(f,d,41),_=C.rotrSL(f,d,14)^C.rotrSL(f,d,18)^C.rotrBL(f,d,41),I=f&u^~f&g,y=d&p^~d&x,B=C.add5L(b,_,y,Uc[m],Yt[m]),T=C.add5H(B,w,v,I,kc[m],Wt[m]),V=B|0,F=C.rotrSH(n,o,28)^C.rotrBH(n,o,34)^C.rotrBH(n,o,39),O=C.rotrSL(n,o,28)^C.rotrBL(n,o,34)^C.rotrBL(n,o,39),N=n&s^n&a^s&a,L=o&i^o&c^i&c;w=g|0,b=x|0,g=u|0,x=p|0,u=f|0,p=d|0,{h:f,l:d}=C.add(l|0,h|0,T|0,V|0),l=a|0,h=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let D=C.add3L(V,O,L);n=C.add3H(D,T,F,N),o=D|0}({h:n,l:o}=C.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=C.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=C.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=C.add(this.Dh|0,this.Dl|0,l|0,h|0),{h:f,l:d}=C.add(this.Eh|0,this.El|0,f|0,d|0),{h:u,l:p}=C.add(this.Fh|0,this.Fl|0,u|0,p|0),{h:g,l:x}=C.add(this.Gh|0,this.Gl|0,g|0,x|0),{h:w,l:b}=C.add(this.Hh|0,this.Hl|0,w|0,b|0),this.set(n,o,s,i,a,c,l,h,f,d,u,p,g,x,w,b)}roundClean(){Wt.fill(0),Yt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Us=hr(()=>new Bn);var xr={};dt(xr,{aInRange:()=>pt,abool:()=>vt,abytes:()=>Te,bitGet:()=>qc,bitLen:()=>Dn,bitMask:()=>Ge,bitSet:()=>Vc,bytesToHex:()=>Mt,bytesToNumberBE:()=>zt,bytesToNumberLE:()=>Jt,concatBytes:()=>qt,createHmacDrbg:()=>Nn,ensureBytes:()=>Y,equalBytes:()=>Mc,hexToBytes:()=>ue,hexToNumber:()=>Rn,inRange:()=>Ke,isBytes:()=>Qt,memoized:()=>le,notImplemented:()=>Kc,numberToBytesBE:()=>te,numberToBytesLE:()=>fe,numberToHexUnpadded:()=>ce,numberToVarBytesBE:()=>Fc,utf8ToBytes:()=>zc,validateObject:()=>Rt});var mr=BigInt(0),gr=BigInt(1),Cc=BigInt(2);function Qt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Te(r){if(!Qt(r))throw new Error("Uint8Array expected")}function vt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Oc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Mt(r){Te(r);let t="";for(let e=0;e<r.length;e++)t+=Oc[r[e]];return t}function ce(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Rn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?mr:BigInt("0x"+r)}var Ft={_0:48,_9:57,A:65,F:70,a:97,f:102};function Cs(r){if(r>=Ft._0&&r<=Ft._9)return r-Ft._0;if(r>=Ft.A&&r<=Ft.F)return r-(Ft.A-10);if(r>=Ft.a&&r<=Ft.f)return r-(Ft.a-10)}function ue(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("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=Cs(r.charCodeAt(s)),a=Cs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function zt(r){return Rn(Mt(r))}function Jt(r){return Te(r),Rn(Mt(Uint8Array.from(r).reverse()))}function te(r,t){return ue(r.toString(16).padStart(t*2,"0"))}function fe(r,t){return te(r,t).reverse()}function Fc(r){return ue(ce(r))}function Y(r,t,e){let n;if(typeof t=="string")try{n=ue(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Qt(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function qt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Te(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 Mc(r,t){if(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 zc(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Ln=r=>typeof r=="bigint"&&mr<=r;function Ke(r,t,e){return Ln(r)&&Ln(t)&&Ln(e)&&t<=r&&r<e}function pt(r,t,e,n){if(!Ke(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Dn(r){let t;for(t=0;r>mr;r>>=gr,t+=1);return t}function qc(r,t){return r>>BigInt(t)&gr}function Vc(r,t,e){return r|(e?gr:mr)<<BigInt(t)}var Ge=r=>(Cc<<BigInt(r-1))-gr,Tn=r=>new Uint8Array(r),Os=r=>Uint8Array.from(r);function Nn(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Tn(r),o=Tn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=Tn())=>{o=a(Os([0]),f),n=a(),f.length!==0&&(o=a(Os([1]),f),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,d=[];for(;f<t;){n=a();let u=n.slice();d.push(u),f+=n.length}return qt(...d)};return(f,d)=>{i(),c(f);let u;for(;!(u=d(l()));)c();return i(),u}}var Hc={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Qt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Rt(r,t,e={}){let n=(o,s,i)=>{let a=Hc[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var Kc=()=>{throw new Error("not implemented")};function le(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var J=BigInt(0),$=BigInt(1),he=BigInt(2),Gc=BigInt(3),Pn=BigInt(4),Fs=BigInt(5),Ms=BigInt(8),jc=BigInt(9),Zc=BigInt(16);function G(r,t){let e=r%t;return e>=J?e:t+e}function $c(r,t,e){if(t<J)throw new Error("invalid exponent, negatives unsupported");if(e<=J)throw new Error("invalid modulus");if(e===$)return J;let n=$;for(;t>J;)t&$&&(n=n*r%e),r=r*r%e,t>>=$;return n}function X(r,t,e){let n=r;for(;t-- >J;)n*=n,n%=e;return n}function wr(r,t){if(r===J)throw new Error("invert: expected non-zero number");if(t<=J)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=J,s=$,i=$,a=J;for(;e!==J;){let l=n/e,h=n%e,f=o-i*l,d=s-a*l;n=e,e=h,o=i,s=a,i=f,a=d}if(n!==$)throw new Error("invert: does not exist");return G(o,t)}function Xc(r){let t=(r-$)/he,e,n,o;for(e=r-$,n=0;e%he===J;e/=he,n++);for(o=he;o<r&&$c(o,t,r)!==r-$;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+$)/Pn;return function(c,l){let h=c.pow(l,i);if(!c.eql(c.sqr(h),l))throw new Error("Cannot find square root");return h}}let s=(e+$)/he;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,h=a.pow(a.mul(a.ONE,o),e),f=a.pow(c,s),d=a.pow(c,e);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let u=1;for(let g=a.sqr(d);u<l&&!a.eql(g,a.ONE);u++)g=a.sqr(g);let p=a.pow(h,$<<BigInt(l-u-1));h=a.sqr(p),f=a.mul(f,p),d=a.mul(d,h),l=u}return f}}function Wc(r){if(r%Pn===Gc){let t=(r+$)/Pn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%Ms===Fs){let t=(r-Fs)/Ms;return function(n,o){let s=n.mul(o,he),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,he),i),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%Zc,Xc(r)}var zs=(r,t)=>(G(r,t)&$)===$,Yc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function kn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Yc.reduce((n,o)=>(n[o]="function",n),t);return Rt(r,e)}function Qc(r,t,e){if(e<J)throw new Error("invalid exponent, negatives unsupported");if(e===J)return r.ONE;if(e===$)return t;let n=r.ONE,o=t;for(;e>J;)e&$&&(n=r.mul(n,o)),o=r.sqr(o),e>>=$;return n}function Jc(r,t){let e=new Array(t.length),n=t.reduce((s,i,a)=>r.is0(i)?s:(e[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,a)=>r.is0(i)?s:(e[a]=r.mul(s,e[a]),r.mul(s,i)),o),e}function Un(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ee(r,t,e=!1,n={}){if(r<=J)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Un(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:Ge(o),ZERO:J,ONE:$,create:c=>G(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return J<=c&&c<r},is0:c=>c===J,isOdd:c=>(c&$)===$,neg:c=>G(-c,r),eql:(c,l)=>c===l,sqr:c=>G(c*c,r),add:(c,l)=>G(c+l,r),sub:(c,l)=>G(c-l,r),mul:(c,l)=>G(c*l,r),pow:(c,l)=>Qc(a,c,l),div:(c,l)=>G(c*wr(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>wr(c,r),sqrt:n.sqrt||(c=>(i||(i=Wc(r)),i(a,c))),invertBatch:c=>Jc(a,c),cmov:(c,l,h)=>h?l:c,toBytes:c=>e?fe(c,s):te(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?Jt(c):zt(c)}});return Object.freeze(a)}function qs(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Cn(r){let t=qs(r);return t+Math.ceil(t/2)}function Vs(r,t,e=!1){let n=r.length,o=qs(t),s=Cn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Jt(r):zt(r),a=G(i,t-$)+$;return e?fe(a,o):te(a,o)}var Hs=BigInt(0),br=BigInt(1);function On(r,t){let e=t.negate();return r?e:t}function Ks(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Fn(r,t){Ks(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function eu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function ru(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var Mn=new WeakMap,Gs=new WeakMap;function zn(r){return Gs.get(r)||1}function yr(r,t){return{constTimeNegate:On,hasPrecomputes(e){return zn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Hs;)n&br&&(o=o.add(s)),s=s.double(),n>>=br;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Fn(n,t),i=[],a=e,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let h=1;h<s;h++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=Fn(e,t),a=r.ZERO,c=r.BASE,l=BigInt(2**e-1),h=2**e,f=BigInt(e);for(let d=0;d<s;d++){let u=d*i,p=Number(o&l);o>>=f,p>i&&(p-=h,o+=br);let g=u,x=u+Math.abs(p)-1,w=d%2!==0,b=p<0;p===0?c=c.add(On(w,n[g])):a=a.add(On(b,n[x]))}return{p:a,f:c}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:a}=Fn(e,t),c=BigInt(2**e-1),l=2**e,h=BigInt(e);for(let f=0;f<i;f++){let d=f*a;if(o===Hs)break;let u=Number(o&c);if(o>>=h,u>a&&(u-=l,o+=br),u===0)continue;let p=n[d+Math.abs(u)-1];u<0&&(p=p.negate()),s=s.add(p)}return s},getPrecomputes(e,n,o){let s=Mn.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&Mn.set(n,o(s))),s},wNAFCached(e,n,o){let s=zn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=zn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Ks(n,t),Gs.set(e,n),Mn.delete(e)}}}function Er(r,t,e,n){if(eu(e,r),ru(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Dn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=(1<<i)-1,c=new Array(a+1).fill(o),l=Math.floor((t.BITS-1)/i)*i,h=o;for(let f=l;f>=0;f-=i){c.fill(o);for(let u=0;u<n.length;u++){let p=n[u],g=Number(p>>BigInt(f)&BigInt(a));c[g]=c[g].add(e[u])}let d=o;for(let u=c.length-1,p=o;u>0;u--)p=p.add(c[u]),d=d.add(p);if(h=h.add(d),f!==0)for(let u=0;u<i;u++)h=h.double()}return h}function je(r){return kn(r.Fp),Rt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Un(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var St=BigInt(0),mt=BigInt(1),vr=BigInt(2),nu=BigInt(8),ou={zip215:!0};function su(r){let t=je(r);return Rt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function js(r){let t=su(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,l=vr<<BigInt(a*8)-mt,h=e.create,f=ee(t.n,t.nBitLength),d=t.uvRatio||((S,E)=>{try{return{isValid:!0,value:e.sqrt(S*e.inv(E))}}catch{return{isValid:!1,value:St}}}),u=t.adjustScalarBytes||(S=>S),p=t.domain||((S,E,A)=>{if(vt("phflag",A),E.length||A)throw new Error("Contexts/pre-hash are not supported");return S});function g(S,E){pt("coordinate "+S,E,St,l)}function x(S){if(!(S instanceof m))throw new Error("ExtendedPoint expected")}let w=le((S,E)=>{let{ex:A,ey:R,ez:P}=S,k=S.is0();E==null&&(E=k?nu:e.inv(P));let M=h(A*E),z=h(R*E),U=h(P*E);if(k)return{x:St,y:mt};if(U!==mt)throw new Error("invZ was invalid");return{x:M,y:z}}),b=le(S=>{let{a:E,d:A}=t;if(S.is0())throw new Error("bad point: ZERO");let{ex:R,ey:P,ez:k,et:M}=S,z=h(R*R),U=h(P*P),H=h(k*k),j=h(H*H),rt=h(z*E),nt=h(H*h(rt+U)),st=h(j+h(A*h(z*U)));if(nt!==st)throw new Error("bad point: equation left != right (1)");let it=h(R*P),ht=h(k*M);if(it!==ht)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(E,A,R,P){this.ex=E,this.ey=A,this.ez=R,this.et=P,g("x",E),g("y",A),g("z",R),g("t",P),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(E){if(E instanceof m)throw new Error("extended point not allowed");let{x:A,y:R}=E||{};return g("x",A),g("y",R),new m(A,R,mt,h(A*R))}static normalizeZ(E){let A=e.invertBatch(E.map(R=>R.ez));return E.map((R,P)=>R.toAffine(A[P])).map(m.fromAffine)}static msm(E,A){return Er(m,f,E,A)}_setWindowSize(E){I.setWindowSize(this,E)}assertValidity(){b(this)}equals(E){x(E);let{ex:A,ey:R,ez:P}=this,{ex:k,ey:M,ez:z}=E,U=h(A*z),H=h(k*P),j=h(R*z),rt=h(M*P);return U===H&&j===rt}is0(){return this.equals(m.ZERO)}negate(){return new m(h(-this.ex),this.ey,this.ez,h(-this.et))}double(){let{a:E}=t,{ex:A,ey:R,ez:P}=this,k=h(A*A),M=h(R*R),z=h(vr*h(P*P)),U=h(E*k),H=A+R,j=h(h(H*H)-k-M),rt=U+M,nt=rt-z,st=U-M,it=h(j*nt),ht=h(rt*st),ft=h(j*st),Lt=h(nt*rt);return new m(it,ht,Lt,ft)}add(E){x(E);let{a:A,d:R}=t,{ex:P,ey:k,ez:M,et:z}=this,{ex:U,ey:H,ez:j,et:rt}=E;if(A===BigInt(-1)){let rs=h((k-P)*(H+U)),ns=h((k+P)*(H-U)),hn=h(ns-rs);if(hn===St)return this.double();let os=h(M*vr*rt),ss=h(z*vr*j),is=ss+os,as=ns+rs,cs=ss-os,pa=h(is*hn),ma=h(as*cs),ga=h(is*cs),xa=h(hn*as);return new m(pa,ma,xa,ga)}let nt=h(P*U),st=h(k*H),it=h(z*R*rt),ht=h(M*j),ft=h((P+k)*(U+H)-nt-st),Lt=ht-it,Dt=ht+it,Ce=h(st-A*nt),fa=h(ft*Lt),la=h(Dt*Ce),ha=h(ft*Ce),da=h(Lt*Dt);return new m(fa,la,da,ha)}subtract(E){return this.add(E.negate())}wNAF(E){return I.wNAFCached(this,E,m.normalizeZ)}multiply(E){let A=E;pt("scalar",A,mt,n);let{p:R,f:P}=this.wNAF(A);return m.normalizeZ([R,P])[0]}multiplyUnsafe(E,A=m.ZERO){let R=E;return pt("scalar",R,St,n),R===St?_:this.is0()||R===mt?this:I.wNAFCachedUnsafe(this,R,m.normalizeZ,A)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return I.unsafeLadder(this,n).is0()}toAffine(E){return w(this,E)}clearCofactor(){let{h:E}=t;return E===mt?this:this.multiplyUnsafe(E)}static fromHex(E,A=!1){let{d:R,a:P}=t,k=e.BYTES;E=Y("pointHex",E,k),vt("zip215",A);let M=E.slice(),z=E[k-1];M[k-1]=z&-129;let U=Jt(M),H=A?l:e.ORDER;pt("pointHex.y",U,St,H);let j=h(U*U),rt=h(j-mt),nt=h(R*j-P),{isValid:st,value:it}=d(rt,nt);if(!st)throw new Error("Point.fromHex: invalid y coordinate");let ht=(it&mt)===mt,ft=(z&128)!==0;if(!A&&it===St&&ft)throw new Error("Point.fromHex: x=0 and x_0=1");return ft!==ht&&(it=h(-it)),m.fromAffine({x:it,y:U})}static fromPrivateKey(E){return T(E).point}toRawBytes(){let{x:E,y:A}=this.toAffine(),R=fe(A,e.BYTES);return R[R.length-1]|=E&mt?128:0,R}toHex(){return Mt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,mt,h(t.Gx*t.Gy)),m.ZERO=new m(St,mt,mt,St);let{BASE:v,ZERO:_}=m,I=yr(m,a*8);function y(S){return G(S,n)}function B(S){return y(Jt(S))}function T(S){let E=e.BYTES;S=Y("private key",S,E);let A=Y("hashed private key",s(S),2*E),R=u(A.slice(0,E)),P=A.slice(E,2*E),k=B(R),M=v.multiply(k),z=M.toRawBytes();return{head:R,prefix:P,scalar:k,point:M,pointBytes:z}}function V(S){return T(S).pointBytes}function F(S=new Uint8Array,...E){let A=qt(...E);return B(s(p(A,Y("context",S),!!o)))}function O(S,E,A={}){S=Y("message",S),o&&(S=o(S));let{prefix:R,scalar:P,pointBytes:k}=T(E),M=F(A.context,R,S),z=v.multiply(M).toRawBytes(),U=F(A.context,z,k,S),H=y(M+U*P);pt("signature.s",H,St,n);let j=qt(z,fe(H,e.BYTES));return Y("result",j,e.BYTES*2)}let N=ou;function L(S,E,A,R=N){let{context:P,zip215:k}=R,M=e.BYTES;S=Y("signature",S,2*M),E=Y("message",E),A=Y("publicKey",A,M),k!==void 0&&vt("zip215",k),o&&(E=o(E));let z=Jt(S.slice(M,2*M)),U,H,j;try{U=m.fromHex(A,k),H=m.fromHex(S.slice(0,M),k),j=v.multiplyUnsafe(z)}catch{return!1}if(!k&&U.isSmallOrder())return!1;let rt=F(P,H.toRawBytes(),U.toRawBytes(),E);return H.add(U.multiplyUnsafe(rt)).subtract(j).clearCofactor().equals(m.ZERO)}return v._setWindowSize(8),{CURVE:t,getPublicKey:V,sign:O,verify:L,ExtendedPoint:m,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>i(e.BYTES),precompute(S=8,E=m.BASE){return E._setWindowSize(S),E.multiply(BigInt(3)),E}}}}var qn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Zs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Sh=BigInt(0),iu=BigInt(1),$s=BigInt(2),_h=BigInt(3),au=BigInt(5),cu=BigInt(8);function uu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=qn,a=r*r%s*r%s,c=X(a,$s,s)*a%s,l=X(c,iu,s)*r%s,h=X(l,au,s)*l%s,f=X(h,t,s)*h%s,d=X(f,e,s)*f%s,u=X(d,n,s)*d%s,p=X(u,o,s)*u%s,g=X(p,o,s)*u%s,x=X(g,t,s)*h%s;return{pow_p_5_8:X(x,$s,s)*r%s,b2:a}}function fu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function lu(r,t){let e=qn,n=G(t*t*t,e),o=G(n*n*t,e),s=uu(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,l=G(i*Zs,e),h=a===r,f=a===G(-r,e),d=a===G(-r*Zs,e);return h&&(i=c),(f||d)&&(i=l),zs(i,e)&&(i=G(-i,e)),{isValid:h||f,value:i}}var hu=ee(qn,void 0,!0),du={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:hu,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:cu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Us,randomBytes:dr,adjustScalarBytes:fu,uvRatio:lu},Xs=js(du);var Sr=32;function Ws(r,t,e){return Xs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var _r=class{type="Ed25519";raw;constructor(t){this.raw=Vn(t,Sr)}toMultihash(){return Ot.digest(Ar(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return Ws(this.raw,e,t)}};function Qs(r){return r=Vn(r,Sr),new _r(r)}function Vn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Oe(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function _t(r=0){return new Uint8Array(r)}function gt(r=0){return new Uint8Array(r)}var mu=Math.pow(2,7),gu=Math.pow(2,14),xu=Math.pow(2,21),Hn=Math.pow(2,28),Kn=Math.pow(2,35),Gn=Math.pow(2,42),jn=Math.pow(2,49),q=128,at=127;function ct(r){if(r<mu)return 1;if(r<gu)return 2;if(r<xu)return 3;if(r<Hn)return 4;if(r<Kn)return 5;if(r<Gn)return 6;if(r<jn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Zn(r,t,e=0){switch(ct(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 wu(r,t,e=0){switch(ct(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 $n(r,t){let e=r[t],n=0;if(n+=e&at,e<q||(e=r[t+1],n+=(e&at)<<7,e<q)||(e=r[t+2],n+=(e&at)<<14,e<q)||(e=r[t+3],n+=(e&at)<<21,e<q)||(e=r[t+4],n+=(e&at)*Hn,e<q)||(e=r[t+5],n+=(e&at)*Kn,e<q)||(e=r[t+6],n+=(e&at)*Gn,e<q)||(e=r[t+7],n+=(e&at)*jn,e<q))return n;throw new RangeError("Could not decode varint")}function bu(r,t){let e=r.get(t),n=0;if(n+=e&at,e<q||(e=r.get(t+1),n+=(e&at)<<7,e<q)||(e=r.get(t+2),n+=(e&at)<<14,e<q)||(e=r.get(t+3),n+=(e&at)<<21,e<q)||(e=r.get(t+4),n+=(e&at)*Hn,e<q)||(e=r.get(t+5),n+=(e&at)*Kn,e<q)||(e=r.get(t+6),n+=(e&at)*Gn,e<q)||(e=r.get(t+7),n+=(e&at)*jn,e<q))return n;throw new RangeError("Could not decode varint")}function re(r,t,e=0){return t==null&&(t=gt(ct(r))),t instanceof Uint8Array?Zn(r,t,e):wu(r,t,e)}function Vt(r,t=0){return r instanceof Uint8Array?$n(r,t):bu(r,t)}var Wn=new Float32Array([-0]),ne=new Uint8Array(Wn.buffer);function Js(r,t,e){Wn[0]=r,t[e]=ne[0],t[e+1]=ne[1],t[e+2]=ne[2],t[e+3]=ne[3]}function ti(r,t){return ne[0]=r[t],ne[1]=r[t+1],ne[2]=r[t+2],ne[3]=r[t+3],Wn[0]}var Yn=new Float64Array([-0]),ut=new Uint8Array(Yn.buffer);function ei(r,t,e){Yn[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function ri(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],Yn[0]}var yu=BigInt(Number.MAX_SAFE_INTEGER),Eu=BigInt(Number.MIN_SAFE_INTEGER),wt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return de;if(t<yu&&t>Eu)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>ni&&(o=0n,++n>ni&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return de;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):de}},de=new wt(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var ni=4294967296n;function oi(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 si(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 Qn(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 At(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Ir(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Jn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,At(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 At(this,4);return Ir(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return Ir(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=ti(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=ri(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 At(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return si(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new wt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw At(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 At(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 At(this,8);let t=Ir(this.buf,this.pos+=4),e=Ir(this.buf,this.pos+=4);return new wt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=$n(this.buf,this.pos);return this.pos+=ct(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 to(r){return new Jn(r instanceof Uint8Array?r:r.subarray())}function Ht(r,t,e){let n=to(r);return t.decode(n,void 0,e)}var eo={};dt(eo,{base10:()=>vu});var vu=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var ro={};dt(ro,{base16:()=>Su,base16upper:()=>_u});var Su=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),_u=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var no={};dt(no,{base2:()=>Au});var Au=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var oo={};dt(oo,{base256emoji:()=>Ru});var ai=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}"),Iu=ai.reduce((r,t,e)=>(r[e]=t,r),[]),Bu=ai.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Lu(r){return r.reduce((t,e)=>(t+=Iu[e],t),"")}function Tu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Bu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Ru=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:Lu,decode:Tu});var so={};dt(so,{base64:()=>Du,base64pad:()=>Nu,base64url:()=>Pu,base64urlpad:()=>ku});var Du=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Nu=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pu=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ku=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var io={};dt(io,{base8:()=>Uu});var Uu=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ao={};dt(ao,{identity:()=>Cu});var Cu=Ee({prefix:"\0",name:"identity",encode:r=>ms(r),decode:r=>ps(r)});var id=new TextEncoder,ad=new TextDecoder;var fo={};dt(fo,{sha256:()=>Ze,sha512:()=>Mu});function uo({name:r,code:t,encode:e}){return new co(r,t,e)}var co=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?ie(this.code,e):e.then(n=>ie(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ui(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ze=uo({name:"sha2-256",code:18,encode:ui("SHA-256")}),Mu=uo({name:"sha2-512",code:19,encode:ui("SHA-512")});var $e={...ao,...no,...io,...eo,...ro,...yn,...En,...bn,...so,...oo},bd={...fo,..._n};function li(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var fi=li("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),lo=li("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=gt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),zu={utf8:fi,"utf-8":fi,hex:$e.base16,latin1:lo,ascii:lo,binary:lo,...$e},Br=zu;function tt(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function ho(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),a}}var pe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function po(){}var go=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},qu=ho();function Vu(r){return globalThis.Buffer!=null?gt(r):qu(r)}var We=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(po,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new pe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new xo((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(Lr,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=wt.fromBigInt(t);return this._push(Lr,e.length(),e)}uint64Number(t){return this._push(Zn,ct(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=wt.fromBigInt(t).zzEncode();return this._push(Lr,e.length(),e)}sint64Number(t){let e=wt.fromNumber(t).zzEncode();return this._push(Lr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(mo,1,t?1:0)}fixed32(t){return this._push(Xe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=wt.fromBigInt(t);return this._push(Xe,4,e.lo)._push(Xe,4,e.hi)}fixed64Number(t){let e=wt.fromNumber(t);return this._push(Xe,4,e.lo)._push(Xe,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(Js,4,t)}double(t){return this._push(ei,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(mo,1,0):this.uint32(e)._push(Ku,e,t)}string(t){let e=oi(t);return e!==0?this.uint32(e)._push(Qn,e,t):this._push(mo,1,0)}fork(){return this.states=new go(this),this.head=this.tail=new pe(po,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 pe(po,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=Vu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function mo(r,t,e){t[e]=r&255}function Hu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var xo=class extends pe{next;constructor(t,e){super(Hu,t,e),this.next=void 0}};function Lr(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 Xe(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 Ku(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(We.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Gu,t,r),this},We.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ju,t,r),this});function Gu(r,t,e){t.set(r,e)}function ju(r,t,e){r.length<40?Qn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(tt(r),e)}function wo(){return new We}function Kt(r,t){let e=wo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Re;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Re||(Re={}));function Tr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function De(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Tr("enum",Re.VARINT,e,n)}function Gt(r,t){return Tr("message",Re.LENGTH_DELIMITED,r,t)}var Rr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var yt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(yt||(yt={}));var bo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(bo||(bo={}));(function(r){r.codec=()=>De(bo)})(yt||(yt={}));var Ye;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),yt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=yt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Kt(e,r.codec()),r.decode=(e,n)=>Ht(e,r.codec(),n)})(Ye||(Ye={}));var yo;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),yt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=yt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Kt(e,r.codec()),r.decode=(e,n)=>Ht(e,r.codec(),n)})(yo||(yo={}));var $u=new Uint32Array([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]),oe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),se=new Uint32Array(64),Eo=class extends Le{constructor(){super(64,32,8,!1),this.A=oe[0]|0,this.B=oe[1]|0,this.C=oe[2]|0,this.D=oe[3]|0,this.E=oe[4]|0,this.F=oe[5]|0,this.G=oe[6]|0,this.H=oe[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)se[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=se[f-15],u=se[f-2],p=Et(d,7)^Et(d,18)^d>>>3,g=Et(u,17)^Et(u,19)^u>>>10;se[f]=g+se[f-7]+p+se[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:h}=this;for(let f=0;f<64;f++){let d=Et(a,6)^Et(a,11)^Et(a,25),u=h+d+Ns(a,c,l)+$u[f]+se[f]|0,g=(Et(n,2)^Et(n,13)^Et(n,22))+Ps(n,o,s)|0;h=l,l=c,c=a,a=i+u|0,i=s,s=o,o=n,n=u+g|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,l=l+this.G|0,h=h+this.H|0,this.set(n,o,s,i,a,c,l,h)}roundClean(){se.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var hi=hr(()=>new Eo);function et(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Qe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Dr=class extends Be{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ts(t);let n=He(e);if(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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(this),Ae(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){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}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},vo=(r,t,e)=>new Dr(r,t).update(e).digest();vo.create=(r,t)=>new Dr(r,t);function di(r){r.lowS!==void 0&&vt("lowS",r.lowS),r.prehash!==void 0&&vt("prehash",r.prehash)}function Xu(r){let t=je(r);Rt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Wu,hexToBytes:Yu}=xr,So=class extends Error{constructor(t=""){super(t)}},jt={Err:So,_tlv:{encode:(r,t)=>{let{Err:e}=jt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ce(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ce(o.length/2|128):"";return ce(r)+s+o+t},decode(r,t){let{Err:e}=jt,n=0;if(r<0||r>256)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 l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let h of l)i=i<<8|h;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=jt;if(r<Zt)throw new t("integer: negative integers are not allowed");let e=ce(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=jt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Wu(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=jt,o=typeof r=="string"?Yu(r):r;Te(o);let{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:l,l:h}=n.decode(2,c);if(h.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=jt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Zt=BigInt(0),ot=BigInt(1),a0=BigInt(2),pi=BigInt(3),c0=BigInt(4);function Qu(r){let t=Xu(r),{Fp:e}=t,n=ee(t.n,t.nBitLength),o=t.toBytes||((g,x,w)=>{let b=x.toAffine();return qt(Uint8Array.from([4]),e.toBytes(b.x),e.toBytes(b.y))}),s=t.fromBytes||(g=>{let x=g.subarray(1),w=e.fromBytes(x.subarray(0,e.BYTES)),b=e.fromBytes(x.subarray(e.BYTES,2*e.BYTES));return{x:w,y:b}});function i(g){let{a:x,b:w}=t,b=e.sqr(g),m=e.mul(b,g);return e.add(e.add(m,e.mul(g,x)),w)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(g){return Ke(g,ot,t.n)}function c(g){let{allowedPrivateKeyLengths:x,nByteLength:w,wrapPrivateKey:b,n:m}=t;if(x&&typeof g!="bigint"){if(Qt(g)&&(g=Mt(g)),typeof g!="string"||!x.includes(g.length))throw new Error("invalid private key");g=g.padStart(w*2,"0")}let v;try{v=typeof g=="bigint"?g:zt(Y("private key",g,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof g)}return b&&(v=G(v,m)),pt("private key",v,ot,m),v}function l(g){if(!(g instanceof d))throw new Error("ProjectivePoint expected")}let h=le((g,x)=>{let{px:w,py:b,pz:m}=g;if(e.eql(m,e.ONE))return{x:w,y:b};let v=g.is0();x==null&&(x=v?e.ONE:e.inv(m));let _=e.mul(w,x),I=e.mul(b,x),y=e.mul(m,x);if(v)return{x:e.ZERO,y:e.ZERO};if(!e.eql(y,e.ONE))throw new Error("invZ was invalid");return{x:_,y:I}}),f=le(g=>{if(g.is0()){if(t.allowInfinityPoint&&!e.is0(g.py))return;throw new Error("bad point: ZERO")}let{x,y:w}=g.toAffine();if(!e.isValid(x)||!e.isValid(w))throw new Error("bad point: x or y not FE");let b=e.sqr(w),m=i(x);if(!e.eql(b,m))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(x,w,b){if(this.px=x,this.py=w,this.pz=b,x==null||!e.isValid(x))throw new Error("x required");if(w==null||!e.isValid(w))throw new Error("y required");if(b==null||!e.isValid(b))throw new Error("z required");Object.freeze(this)}static fromAffine(x){let{x:w,y:b}=x||{};if(!x||!e.isValid(w)||!e.isValid(b))throw new Error("invalid affine point");if(x instanceof d)throw new Error("projective point not allowed");let m=v=>e.eql(v,e.ZERO);return m(w)&&m(b)?d.ZERO:new d(w,b,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(x){let w=e.invertBatch(x.map(b=>b.pz));return x.map((b,m)=>b.toAffine(w[m])).map(d.fromAffine)}static fromHex(x){let w=d.fromAffine(s(Y("pointHex",x)));return w.assertValidity(),w}static fromPrivateKey(x){return d.BASE.multiply(c(x))}static msm(x,w){return Er(d,n,x,w)}_setWindowSize(x){p.setWindowSize(this,x)}assertValidity(){f(this)}hasEvenY(){let{y:x}=this.toAffine();if(e.isOdd)return!e.isOdd(x);throw new Error("Field doesn't support isOdd")}equals(x){l(x);let{px:w,py:b,pz:m}=this,{px:v,py:_,pz:I}=x,y=e.eql(e.mul(w,I),e.mul(v,m)),B=e.eql(e.mul(b,I),e.mul(_,m));return y&&B}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:x,b:w}=t,b=e.mul(w,pi),{px:m,py:v,pz:_}=this,I=e.ZERO,y=e.ZERO,B=e.ZERO,T=e.mul(m,m),V=e.mul(v,v),F=e.mul(_,_),O=e.mul(m,v);return O=e.add(O,O),B=e.mul(m,_),B=e.add(B,B),I=e.mul(x,B),y=e.mul(b,F),y=e.add(I,y),I=e.sub(V,y),y=e.add(V,y),y=e.mul(I,y),I=e.mul(O,I),B=e.mul(b,B),F=e.mul(x,F),O=e.sub(T,F),O=e.mul(x,O),O=e.add(O,B),B=e.add(T,T),T=e.add(B,T),T=e.add(T,F),T=e.mul(T,O),y=e.add(y,T),F=e.mul(v,_),F=e.add(F,F),T=e.mul(F,O),I=e.sub(I,T),B=e.mul(F,V),B=e.add(B,B),B=e.add(B,B),new d(I,y,B)}add(x){l(x);let{px:w,py:b,pz:m}=this,{px:v,py:_,pz:I}=x,y=e.ZERO,B=e.ZERO,T=e.ZERO,V=t.a,F=e.mul(t.b,pi),O=e.mul(w,v),N=e.mul(b,_),L=e.mul(m,I),D=e.add(w,b),S=e.add(v,_);D=e.mul(D,S),S=e.add(O,N),D=e.sub(D,S),S=e.add(w,m);let E=e.add(v,I);return S=e.mul(S,E),E=e.add(O,L),S=e.sub(S,E),E=e.add(b,m),y=e.add(_,I),E=e.mul(E,y),y=e.add(N,L),E=e.sub(E,y),T=e.mul(V,S),y=e.mul(F,L),T=e.add(y,T),y=e.sub(N,T),T=e.add(N,T),B=e.mul(y,T),N=e.add(O,O),N=e.add(N,O),L=e.mul(V,L),S=e.mul(F,S),N=e.add(N,L),L=e.sub(O,L),L=e.mul(V,L),S=e.add(S,L),O=e.mul(N,S),B=e.add(B,O),O=e.mul(E,S),y=e.mul(D,y),y=e.sub(y,O),O=e.mul(D,N),T=e.mul(E,T),T=e.add(T,O),new d(y,B,T)}subtract(x){return this.add(x.negate())}is0(){return this.equals(d.ZERO)}wNAF(x){return p.wNAFCached(this,x,d.normalizeZ)}multiplyUnsafe(x){let{endo:w,n:b}=t;pt("scalar",x,Zt,b);let m=d.ZERO;if(x===Zt)return m;if(this.is0()||x===ot)return this;if(!w||p.hasPrecomputes(this))return p.wNAFCachedUnsafe(this,x,d.normalizeZ);let{k1neg:v,k1:_,k2neg:I,k2:y}=w.splitScalar(x),B=m,T=m,V=this;for(;_>Zt||y>Zt;)_&ot&&(B=B.add(V)),y&ot&&(T=T.add(V)),V=V.double(),_>>=ot,y>>=ot;return v&&(B=B.negate()),I&&(T=T.negate()),T=new d(e.mul(T.px,w.beta),T.py,T.pz),B.add(T)}multiply(x){let{endo:w,n:b}=t;pt("scalar",x,ot,b);let m,v;if(w){let{k1neg:_,k1:I,k2neg:y,k2:B}=w.splitScalar(x),{p:T,f:V}=this.wNAF(I),{p:F,f:O}=this.wNAF(B);T=p.constTimeNegate(_,T),F=p.constTimeNegate(y,F),F=new d(e.mul(F.px,w.beta),F.py,F.pz),m=T.add(F),v=V.add(O)}else{let{p:_,f:I}=this.wNAF(x);m=_,v=I}return d.normalizeZ([m,v])[0]}multiplyAndAddUnsafe(x,w,b){let m=d.BASE,v=(I,y)=>y===Zt||y===ot||!I.equals(m)?I.multiplyUnsafe(y):I.multiply(y),_=v(this,w).add(v(x,b));return _.is0()?void 0:_}toAffine(x){return h(this,x)}isTorsionFree(){let{h:x,isTorsionFree:w}=t;if(x===ot)return!0;if(w)return w(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:x,clearCofactor:w}=t;return x===ot?this:w?w(d,this):this.multiplyUnsafe(t.h)}toRawBytes(x=!0){return vt("isCompressed",x),this.assertValidity(),o(d,this,x)}toHex(x=!0){return vt("isCompressed",x),Mt(this.toRawBytes(x))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let u=t.nBitLength,p=yr(d,t.endo?Math.ceil(u/2):u);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function Ju(r){let t=je(r);return Rt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function mi(r){let t=Ju(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(L){return G(L,n)}function a(L){return wr(L,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:l,weierstrassEquation:h,isWithinCurveOrder:f}=Qu({...t,toBytes(L,D,S){let E=D.toAffine(),A=e.toBytes(E.x),R=qt;return vt("isCompressed",S),S?R(Uint8Array.from([D.hasEvenY()?2:3]),A):R(Uint8Array.from([4]),A,e.toBytes(E.y))},fromBytes(L){let D=L.length,S=L[0],E=L.subarray(1);if(D===o&&(S===2||S===3)){let A=zt(E);if(!Ke(A,ot,e.ORDER))throw new Error("Point is not on curve");let R=h(A),P;try{P=e.sqrt(R)}catch(z){let U=z instanceof Error?": "+z.message:"";throw new Error("Point is not on curve"+U)}let k=(P&ot)===ot;return(S&1)===1!==k&&(P=e.neg(P)),{x:A,y:P}}else if(D===s&&S===4){let A=e.fromBytes(E.subarray(0,e.BYTES)),R=e.fromBytes(E.subarray(e.BYTES,2*e.BYTES));return{x:A,y:R}}else{let A=o,R=s;throw new Error("invalid Point, expected length of "+A+", or uncompressed "+R+", got "+D)}}}),d=L=>Mt(te(L,t.nByteLength));function u(L){let D=n>>ot;return L>D}function p(L){return u(L)?i(-L):L}let g=(L,D,S)=>zt(L.slice(D,S));class x{constructor(D,S,E){this.r=D,this.s=S,this.recovery=E,this.assertValidity()}static fromCompact(D){let S=t.nByteLength;return D=Y("compactSignature",D,S*2),new x(g(D,0,S),g(D,S,2*S))}static fromDER(D){let{r:S,s:E}=jt.toSig(Y("DER",D));return new x(S,E)}assertValidity(){pt("r",this.r,ot,n),pt("s",this.s,ot,n)}addRecoveryBit(D){return new x(this.r,this.s,D)}recoverPublicKey(D){let{r:S,s:E,recovery:A}=this,R=I(Y("msgHash",D));if(A==null||![0,1,2,3].includes(A))throw new Error("recovery id invalid");let P=A===2||A===3?S+t.n:S;if(P>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let k=A&1?"03":"02",M=c.fromHex(k+d(P)),z=a(P),U=i(-R*z),H=i(E*z),j=c.BASE.multiplyAndAddUnsafe(M,U,H);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return u(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return ue(this.toDERHex())}toDERHex(){return jt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ue(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let w={isValidPrivateKey(L){try{return l(L),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let L=Cn(t.n);return Vs(t.randomBytes(L),t.n)},precompute(L=8,D=c.BASE){return D._setWindowSize(L),D.multiply(BigInt(3)),D}};function b(L,D=!0){return c.fromPrivateKey(L).toRawBytes(D)}function m(L){let D=Qt(L),S=typeof L=="string",E=(D||S)&&L.length;return D?E===o||E===s:S?E===2*o||E===2*s:L instanceof c}function v(L,D,S=!0){if(m(L))throw new Error("first arg must be private key");if(!m(D))throw new Error("second arg must be public key");return c.fromHex(D).multiply(l(L)).toRawBytes(S)}let _=t.bits2int||function(L){if(L.length>8192)throw new Error("input is too large");let D=zt(L),S=L.length*8-t.nBitLength;return S>0?D>>BigInt(S):D},I=t.bits2int_modN||function(L){return i(_(L))},y=Ge(t.nBitLength);function B(L){return pt("num < 2^"+t.nBitLength,L,Zt,y),te(L,t.nByteLength)}function T(L,D,S=V){if(["recovered","canonical"].some(nt=>nt in S))throw new Error("sign() legacy options not supported");let{hash:E,randomBytes:A}=t,{lowS:R,prehash:P,extraEntropy:k}=S;R==null&&(R=!0),L=Y("msgHash",L),di(S),P&&(L=Y("prehashed msgHash",E(L)));let M=I(L),z=l(D),U=[B(z),B(M)];if(k!=null&&k!==!1){let nt=k===!0?A(e.BYTES):k;U.push(Y("extraEntropy",nt))}let H=qt(...U),j=M;function rt(nt){let st=_(nt);if(!f(st))return;let it=a(st),ht=c.BASE.multiply(st).toAffine(),ft=i(ht.x);if(ft===Zt)return;let Lt=i(it*i(j+ft*z));if(Lt===Zt)return;let Dt=(ht.x===ft?0:2)|Number(ht.y&ot),Ce=Lt;return R&&u(Lt)&&(Ce=p(Lt),Dt^=1),new x(ft,Ce,Dt)}return{seed:H,k2sig:rt}}let V={lowS:t.lowS,prehash:!1},F={lowS:t.lowS,prehash:!1};function O(L,D,S=V){let{seed:E,k2sig:A}=T(L,D,S),R=t;return Nn(R.hash.outputLen,R.nByteLength,R.hmac)(E,A)}c.BASE._setWindowSize(8);function N(L,D,S,E=F){let A=L;D=Y("msgHash",D),S=Y("publicKey",S);let{lowS:R,prehash:P,format:k}=E;if(di(E),"strict"in E)throw new Error("options.strict was renamed to lowS");if(k!==void 0&&k!=="compact"&&k!=="der")throw new Error("format must be compact or der");let M=typeof A=="string"||Qt(A),z=!M&&!k&&typeof A=="object"&&A!==null&&typeof A.r=="bigint"&&typeof A.s=="bigint";if(!M&&!z)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let U,H;try{if(z&&(U=new x(A.r,A.s)),M){try{k!=="compact"&&(U=x.fromDER(A))}catch(Dt){if(!(Dt instanceof jt.Err))throw Dt}!U&&k!=="der"&&(U=x.fromCompact(A))}H=c.fromHex(S)}catch{return!1}if(!U||R&&U.hasHighS())return!1;P&&(D=t.hash(D));let{r:j,s:rt}=U,nt=I(D),st=a(rt),it=i(nt*st),ht=i(j*st),ft=c.BASE.multiplyAndAddUnsafe(H,it,ht)?.toAffine();return ft?i(ft.x)===j:!1}return{CURVE:t,getPublicKey:b,getSharedSecret:v,sign:O,verify:N,ProjectivePoint:c,Signature:x,utils:w}}function tf(r){return{hash:r,hmac:(t,...e)=>vo(r,t,An(...e)),randomBytes:dr}}function gi(r,t){let e=n=>mi({...r,...tf(n)});return{...e(t),create:e}}var bi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),xi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ef=BigInt(1),_o=BigInt(2),wi=(r,t)=>(r+t/_o)/t;function rf(r){let t=bi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,h=l*l*r%t,f=X(h,e,t)*h%t,d=X(f,e,t)*h%t,u=X(d,_o,t)*l%t,p=X(u,o,t)*u%t,g=X(p,s,t)*p%t,x=X(g,a,t)*g%t,w=X(x,c,t)*x%t,b=X(w,a,t)*g%t,m=X(b,e,t)*h%t,v=X(m,i,t)*p%t,_=X(v,n,t)*l%t,I=X(_,_o,t);if(!Ao.eql(Ao.sqr(I),r))throw new Error("Cannot find square root");return I}var Ao=ee(bi,void 0,void 0,{sqrt:rf}),me=gi({a:BigInt(0),b:BigInt(7),Fp:Ao,n:xi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=xi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ef*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=wi(s*r,t),c=wi(-n*r,t),l=G(r-a*e-c*o,t),h=G(-a*n-c*s,t),f=l>i,d=h>i;if(f&&(l=t-l),d&&(h=t-h),l>i||h>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:d,k2:h}}}},hi),x0=BigInt(0);var w0=me.ProjectivePoint;function bt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=gt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function yi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Ei(r,t,e){let n=Ze.digest(e instanceof Uint8Array?e:e.subarray());if(yi(n))return n.then(({digest:o})=>me.verify(t,o,r)).catch(o=>{throw new Qe(String(o))});try{return me.verify(t,n.digest,r)}catch(o){throw new Qe(String(o))}}var Nr=class{type="secp256k1";raw;_key;constructor(t){this._key=Si(t),this.raw=vi(this._key)}toMultihash(){return Ot.digest(Ar(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return Ei(this._key,e,t)}};function _i(r){return new Nr(r)}function vi(r){return me.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Si(r){try{return me.ProjectivePoint.fromHex(r),r}catch(t){throw new ar(String(t))}}function Ai(r){let{Type:t,Data:e}=Ye.decode(r.digest),n=e??new Uint8Array;switch(t){case yt.Ed25519:return Qs(n);case yt.secp256k1:return _i(n);default:throw new Fe}}function Ar(r){return Ye.encode({Type:yt[r.type],Data:r.raw})}var Ii=Symbol.for("nodejs.util.inspect.custom"),nf=114,Je=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()})`}[pn]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return lt.createV1(nf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ii](){return`PeerId(${this.toString()})`}},Pr=class extends Je{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},kr=class extends Je{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Ur=class extends Je{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},of=2336,Cr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ot.digest(tt(this.url))}[Ii](){return`PeerId(${this.url})`}[pn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return lt.createV1(of,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};function Or(r){if(af(r))return new Pr({multihash:r});if(sf(r))try{let t=Ai(r);if(t.type==="Ed25519")return new kr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Ur({multihash:r,publicKey:t})}catch{let e=et(r.digest);return new Cr(new URL(e))}throw new cr("Supplied PeerID Multihash is invalid")}function sf(r){return r.code===Ot.code}function af(r){return r.code===Ze.code}function Io(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 Fr(r){let t=Ut(W.decode(`z${r}`));return Or(t)}var Mr=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 Io(this.set.entries(),t=>{let e=Fr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Fr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Io(this.set.values(),t=>Fr(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 Bo(){return new Mr}var Di=Symbol.for("@achingbrain/uint8arraylist");function Ri(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 qr(r){return!!r?.[Di]}var $t=class r{bufs;length;[Di]=!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(qr(n))e+=n.byteLength,this.bufs.push(...n.bufs);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(qr(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=Ri(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ri(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(qr(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 bt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:bt(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 l=t>=a&&t<c,h=e>a&&e<=c;if(l&&h){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(h){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(!qr(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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,h;for(let f=e;f<=c;f+=h){h=0;for(let d=l;d>=0;d--){let u=this.get(f+d);if(n[d]!==u){h=Math.max(1,d-a[u]);break}}if(h===0)return f}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=gt(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=_t(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=_t(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=_t(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=gt(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=_t(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=_t(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=_t(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=_t(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=_t(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(!xt(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 Lo=64,It=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Lo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=_t(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?xt(this.fp,t.fp):!1}};function ge(r,t){return Math.floor(Math.random()*(t-r))+r}var xe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof It))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 It))throw new TypeError("Invalid Fingerprint");let e=ge(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var To={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ni={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Pi=new globalThis.TextEncoder;function cf(r,t){let e=To[t],n=Ni[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function uf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=To[t],o=Ni[t],s=r;for(;s.length>0;){let i=Pi.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 Ro(r,{size:t=32,utf8Buffer:e}={}){if(!To[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 uf(r,t,e);r=Pi.encode(r)}return cf(r,t)}var ff=fs(Ti(),1);var er={hash:r=>Number(Ro(r,{size:32})),hashV:(r,t)=>lf(er.hash(r,t))};function lf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),tt(t,"base16")}var hf=500,rr=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??er,this.seed=t.seed??ge(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=tt(t));let e=new It(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new xe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new xe(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[ge(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize));for(let a=0;a<hf;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=tt(t));let e=new It(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=tt(t));let e=new It(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}},df={1:.5,2:.84,4:.95,8:.98};function pf(r=.001){return r>.002?2:r>1e-5?4:8}function ki(r,t=.001){let e=pf(t),n=df[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Lo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Vr=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??er,this.seed=t.seed??ge(0,Math.pow(2,10)),this.filterSeries=[new rr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=tt(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 rr({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=tt(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=tt(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 Do(r,t=.001,e){return new Vr({...ki(r,t),...e??{}})}var Hr=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",l=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let d=Number.parseInt(f,t);if(!Number.isNaN(d))return d});if(h===void 0)break;if(s*=t,s+=h,s>l||(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 Ui=45,mf=15,Ne=new Hr;function Kr(r){if(!(r.length>mf))return Ne.new(r).parseWith(()=>Ne.readIPv4Addr())}function Gr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ui))return Ne.new(r).parseWith(()=>Ne.readIPv6Addr())}function we(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ui))return Ne.new(r).parseWith(()=>Ne.readIPAddr())}function Ci(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 Oi(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 No(r){switch(r.length){case be:return r.join(".");case ye:{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 Fi(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;n&128;)t++,n=n<<1;if(n&128)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function Mi(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var be=4,ye=16,dm=parseInt("0xFFFF",16),gf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function nr(r,t){t.length===ye&&r.length===be&&Ci(t,0,11)&&(t=t.slice(12)),t.length===be&&r.length===ye&&Oi(r,gf,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 zi(r,t){if(typeof t=="string"&&(t=we(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Po(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=be,o=Kr(t);if(o==null&&(n=ye,o=Gr(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=ko(s,8*n);return{network:nr(o,i),mask:i}}function ko(r,t){if(t!==8*be&&t!==8*ye)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 Pe=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Po(t));else{let n=we(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=we(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ko(o,8*n.length);this.network=nr(n,this.mask)}}contains(t){return zi({network:this.network,mask:this.mask},t)}toString(){let t=Fi(this.mask),e=t!==-1?String(t):Mi(this.mask);return No(this.network)+"/"+e}};function qi(r,t){return new Pe(r).contains(t)}var xf=41;function Vi(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===xf)return qi("2000::/3",e)}catch{}return!1}function jr(r){return!!Kr(r)}function Zr(r){return!!Gr(r)}function $r(r){return!!we(r)}var Ki=fs(Hi(),1),wf=["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"],bf=wf.map(r=>new Ki.Netmask(r));function Uo(r){for(let t of bf)if(t.contains(r))return!0;return!1}function yf(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Ef(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 Uo(o)}function vf(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Sf(r){let t=r.split(":"),e=t[t.length-1];return Uo(e)}function _f(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 Gi(r){return jr(r)?Uo(r):yf(r)?Ef(r):vf(r)?Sf(r):Zr(r)?_f(r):void 0}var Af=4,If=41,Bf=53,Lf=54,Tf=55,Rf=56;function Co(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!0;if(t===Bf||t===Lf||t===Tf||t===Rf)return!1;if(t===Af||t===If)return Gi(e)??!1}catch{}return!0}function Bt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Xr=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)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}},ke=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Xr(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 Xr(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 Oo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ji(r={}){return Df(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 Df(r,t){t=t??{};let e=t.onEnd,n=new ke,o,s,i,a=Bt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,w)=>{s=b=>{s=null,n.push(b);try{x(r(n))}catch(m){w(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Bt()})}},l=x=>s!=null?s(x):(n.push(x),o),h=x=>(n=new ke,s!=null?s({error:x}):(n.push({error:x}),o)),f=x=>{if(i)return o;if(t?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:x})},d=x=>i?o:(i=!0,x!=null?h(x):l({done:!0})),u=()=>(n=new ke,d(),{done:!0}),p=x=>(d(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:u,throw:p,push:f,end:d,get readableLength(){return n.size},onEmpty:async x=>{let w=x?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let b,m;w!=null&&(b=new Promise((v,_)=>{m=()=>{_(new Oo)},w.addEventListener("abort",m)}));try{await Promise.race([a.promise,b])}finally{m!=null&&w!=null&&w?.removeEventListener("abort",m)}}},e==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(x){return g.throw(x),e!=null&&(e(x),e=void 0),{done:!0}},return(){return g.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(x){return g.end(x),e!=null&&(e(x),e=void 0),o},get readableLength(){return g.readableLength},onEmpty:x=>g.onEmpty(x)},o}var Fo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function Wr(r,t,e,n){let o=new Fo(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",h),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,l)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(d){a(),i(d);return}a(),s(f)},l=f=>{a(),i(f.detail)},h=()=>{a(),i(o)};e?.addEventListener("abort",h),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,l)})}var Yr=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Qr=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Jr(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Qr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Qr(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var tn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Bt(),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 Nf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var en=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=Nf(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,Tt(1/0,this.controller.signal),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 tn(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Jr(this.fn({...this.options??{},signal:this.controller.signal}),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 rn=class extends ur{concurrency;maxSize;queue;pending;sort;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,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=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!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 Yr;let n=new en(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("error",{detail:o}),this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),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 Wr(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await Wr(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Wr(this,"idle",t?.signal)}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=ji({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)},i=()=>{n()},a=()=>{n(new Nt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var nn=class extends rn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function on(r){let t=new globalThis.AbortController;function e(){t.abort();for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}function Zi(r,t,e){let n,o;function s(){let a={signal:o.signal};if(e?.timeout!=null){let c=on([o.signal,AbortSignal.timeout(e.timeout)]);Tt(1/0,c),a.signal=c}Promise.resolve().then(async()=>{await r(a)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{start:()=>{i||(i=!0,o=new AbortController,Tt(1/0,o.signal),e?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),i=!1}}}var $i=jr,Pf=Zr,Mo=function(r){let t=0;if(r=r.toString().trim(),$i(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Pf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=$i(e[n]),i;s&&(i=Mo(e[n]),e[n]=et(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,et(i.slice(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++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},Xi=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ue={},zo={},Uf=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Uf.forEach(r=>{let t=Cf(...r);zo[t.code]=t,Ue[t.name]=t});function Cf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function K(r){if(typeof r=="number"){if(zo[r]!=null)return zo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ue[r]!=null)return Ue[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ig=K("ip4"),Bg=K("ip6"),Lg=K("ipcidr");function Ko(r,t){switch(K(r).code){case 4:case 41:return Ff(t);case 42:return Ho(t);case 43:return et(t,"base10");case 6:case 273:case 33:case 132:return Qi(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ho(t);case 421:return Vf(t);case 444:return Yi(t);case 445:return Yi(t);case 466:return qf(t);case 481:return globalThis.encodeURIComponent(Ho(t));default:return et(t,"base16")}}function Go(r,t){switch(K(r).code){case 4:return Wi(t);case 41:return Wi(t);case 42:return Vo(t);case 43:return tt(t,"base10");case 6:case 273:case 33:case 132:return jo(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Vo(t);case 421:return Mf(t);case 444:return Hf(t);case 445:return Kf(t);case 466:return zf(t);case 481:return Vo(globalThis.decodeURIComponent(t));default:return tt(t,"base16")}}var qo=Object.values($e).map(r=>r.decoder),Of=function(){let r=qo[0].or(qo[1]);return qo.slice(2).forEach(t=>r=r.or(t)),r}();function Wi(r){if(!$r(r))throw new Error("invalid ip address");return Mo(r)}function Ff(r){let t=Xi(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!$r(t))throw new Error("invalid ip address");return t}function jo(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Qi(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Vo(r){let t=tt(r),e=Uint8Array.from(re(t.length));return bt([e,t],e.length+t.length)}function Ho(r){let t=Vt(r);if(r=r.slice(ct(t)),r.length!==t)throw new Error("inconsistent lengths");return et(r)}function Mf(r){let t;r[0]==="Q"||r[0]==="1"?t=Ut(W.decode(`z${r}`)).bytes:t=lt.parse(r).multihash.bytes;let e=Uint8Array.from(re(t.length));return bt([e,t],e.length+t.length)}function zf(r){let t=Of.decode(r),e=Uint8Array.from(re(t.length));return bt([e,t],e.length+t.length)}function qf(r){let t=Vt(r),e=r.slice(ct(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+et(e,"base64url")}function Vf(r){let t=Vt(r),e=r.slice(ct(t));if(e.length!==t)throw new Error("inconsistent lengths");return et(e,"base58btc")}function Hf(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=kt.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=jo(n);return bt([e,o],e.length+o.length)}function Kf(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=kt.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=jo(n);return bt([e,o],e.length+o.length)}function Yi(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=et(t,"base32"),o=Qi(e);return`${n}:${o}`}function Ji(r){r=Zo(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=K(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw ea("invalid address: "+r);if(a.path===!0){n=Zo(o.slice(s).join("/")),t.push([a.code,Go(a.code,n)]),e.push([a.code,n]);break}let c=Go(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Ko(a.code,c)])}return{string:ta(e),bytes:Xo(t),tuples:t,stringTuples:e,path:n}}function $o(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Vt(r,o),i=ct(s),a=K(s),c=Gf(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let l=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw ea("Invalid address Uint8Array: "+et(r,"base16"));t.push([s,l]);let h=Ko(s,l);if(e.push([s,h]),a.path===!0){n=h;break}}return{bytes:Uint8Array.from(r),string:ta(e),tuples:t,stringTuples:e,path:n}}function ta(r){let t=[];return r.map(e=>{let n=K(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Zo(t.join("/"))}function Xo(r){return bt(r.map(t=>{let e=K(t[0]),n=Uint8Array.from(re(e.code));return t.length>1&&t[1]!=null&&(n=bt([n,t[1]])),n}))}function Gf(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Vt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ct(e)}}function Zo(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function ea(r){return new Error("Error parsing address: "+r)}var jf=Symbol.for("nodejs.util.inspect.custom"),Yo=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Zf=[K("dns").code,K("dns4").code,K("dns6").code,K("dnsaddr").code],Wo=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},sn=class r{bytes;#t;#e;#r;#n;[Yo]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=$o(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Ji(t)}else if(na(t))e=$o(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=K("tcp"),a=K("udp"),c=K("ip4"),l=K("ip6"),h=K("dns6"),f=K("ip6zone");for(let[u,p]of this.stringTuples())u===f.code&&(s=`%${p??""}`),Zf.includes(u)&&(e=i.name,o=443,n=`${p??""}${s}`,t=u===h.code?6:4),(u===i.code||u===a.code)&&(e=K(u).name,o=parseInt(p??"")),(u===c.code||u===l.code)&&(e=K(u).name,n=`${p??""}${s}`,t=u===l.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#e.map(([t])=>Object.assign({},K(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>K(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(Xo(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ue.p2p.code&&t.push([n,o]),n===Ue["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?et(W.decode(`z${n}`),"base58btc"):et(lt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return xt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=ra.get(e.name);if(n==null)throw new Wo(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>sr(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[jf](){return`Multiaddr(${this.#t})`}};var ra=new Map;function na(r){return!!r?.[Yo]}function sr(r){return new sn(r)}var Qo=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Bt(),this.haveNext=Bt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Bt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Bt(),await Jr(this.readNext.promise,e?.signal,e)}};function oa(){return new Qo}var an=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Jo=class extends Error{code;constructor(t,e){super(t),this.code=e}},ts=class extends Jo{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function sa(r,t){let e=oa();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new $t;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((h,f)=>{c=()=>{f(new ts("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:d}=await Promise.race([n.next(),l]);return f===!0?new $t:d}for(;o.byteLength<i;){let{value:f,done:d}=await Promise.race([n.next(),l]);if(d===!0)throw new an("unexpected end of input");o.append(f)}let h=o.sublist(0,i);return o.consume(i),h}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var cn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},un=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},fn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ia(r,t={}){let e=sa(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=ct(t.maxDataLength));let n=t?.lengthDecoder??Vt,o=t?.lengthEncoder??re;return{read:async i=>{let a=-1,c=new $t;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new cn("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new fn("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new un("message length too long");return e.read(a,i)},write:async(i,a)=>{await e.write(new $t(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new $t(...i.flatMap(l=>[o(l.byteLength),l]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function es(r,t){let e=ia(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 aa="libp2p",ca="autonat",ua="1.0.0";var Z;(function(r){let t;(function(l){l.DIAL="DIAL",l.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(l){l[l.DIAL=0]="DIAL",l[l.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(l){l.codec=()=>De(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(l){l.OK="OK",l.E_DIAL_ERROR="E_DIAL_ERROR",l.E_DIAL_REFUSED="E_DIAL_REFUSED",l.E_BAD_REQUEST="E_BAD_REQUEST",l.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(l){l[l.OK=0]="OK",l[l.E_DIAL_ERROR=100]="E_DIAL_ERROR",l[l.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",l[l.E_BAD_REQUEST=200]="E_BAD_REQUEST",l[l.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(l){l.codec=()=>De(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(l){let h;l.codec=()=>(h==null&&(h=Gt((f,d,u={})=>{if(u.lengthDelimited!==!1&&d.fork(),f.id!=null&&(d.uint32(10),d.bytes(f.id)),f.addrs!=null)for(let p of f.addrs)d.uint32(18),d.bytes(p);u.lengthDelimited!==!1&&d.ldelim()},(f,d,u={})=>{let p={addrs:[]},g=d==null?f.len:f.pos+d;for(;f.pos<g;){let x=f.uint32();switch(x>>>3){case 1:{p.id=f.bytes();break}case 2:{if(u.limits?.addrs!=null&&p.addrs.length===u.limits.addrs)throw new Rr('Decode error - map field "addrs" had too many elements');p.addrs.push(f.bytes());break}default:{f.skipType(x&7);break}}}return p})),h),l.encode=f=>Kt(f,l.codec()),l.decode=(f,d)=>Ht(f,l.codec(),d)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(l){let h;l.codec=()=>(h==null&&(h=Gt((f,d,u={})=>{u.lengthDelimited!==!1&&d.fork(),f.peer!=null&&(d.uint32(10),r.PeerInfo.codec().encode(f.peer,d)),u.lengthDelimited!==!1&&d.ldelim()},(f,d,u={})=>{let p={},g=d==null?f.len:f.pos+d;for(;f.pos<g;){let x=f.uint32();switch(x>>>3){case 1:{p.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:u.limits?.peer});break}default:{f.skipType(x&7);break}}}return p})),h),l.encode=f=>Kt(f,l.codec()),l.decode=(f,d)=>Ht(f,l.codec(),d)})(i=r.Dial||(r.Dial={}));let a;(function(l){let h;l.codec=()=>(h==null&&(h=Gt((f,d,u={})=>{u.lengthDelimited!==!1&&d.fork(),f.status!=null&&(d.uint32(8),r.ResponseStatus.codec().encode(f.status,d)),f.statusText!=null&&(d.uint32(18),d.string(f.statusText)),f.addr!=null&&(d.uint32(26),d.bytes(f.addr)),u.lengthDelimited!==!1&&d.ldelim()},(f,d,u={})=>{let p={},g=d==null?f.len:f.pos+d;for(;f.pos<g;){let x=f.uint32();switch(x>>>3){case 1:{p.status=r.ResponseStatus.codec().decode(f);break}case 2:{p.statusText=f.string();break}case 3:{p.addr=f.bytes();break}default:{f.skipType(x&7);break}}}return p})),h),l.encode=f=>Kt(f,l.codec()),l.decode=(f,d)=>Ht(f,l.codec(),d)})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=Gt((l,h,f={})=>{f.lengthDelimited!==!1&&h.fork(),l.type!=null&&(h.uint32(8),r.MessageType.codec().encode(l.type,h)),l.dial!=null&&(h.uint32(18),r.Dial.codec().encode(l.dial,h)),l.dialResponse!=null&&(h.uint32(26),r.DialResponse.codec().encode(l.dialResponse,h)),f.lengthDelimited!==!1&&h.ldelim()},(l,h,f={})=>{let d={},u=h==null?l.len:l.pos+h;for(;l.pos<u;){let p=l.uint32();switch(p>>>3){case 1:{d.type=r.MessageType.codec().decode(l);break}case 2:{d.dial=r.Dial.codec().decode(l,l.uint32(),{limits:f.limits?.dial});break}case 3:{d.dialResponse=r.DialResponse.codec().decode(l,l.uint32(),{limits:f.limits?.dialResponse});break}default:{l.skipType(p&7);break}}}return d})),c),r.encode=l=>Kt(l,r.codec()),r.decode=(l,h)=>Ht(l,r.codec(),h)})(Z||(Z={}));var Jf=4,tl=8,ln=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??aa}/${ca}/${ua}`,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=new Map,this.findPeers=Zi(this.findRandomPeers.bind(this),6e4),this.addressFilter=Do(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ls]=["@libp2p/autonat"];get[hs](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream - %e",e)})},{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=on([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){let e=AbortSignal.timeout(this.timeout);Tt(1/0,e);let n=es(t.stream,{maxDataLength:this.maxMessageSize}).pb(Z);try{let o=await n.read({signal:e}),s=await this.handleAutonatMessage(o,t.connection,{signal:e});await n.write(s,{signal:e}),await n.unwrap().unwrap().close({signal:e})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.stream.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(f=>f.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.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:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Ut(a.id);i=Or(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.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:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(f=>sr(f)).filter(f=>{let d=f.toOptions();return Co(f)?!1:d.host!==e.remoteAddr.toOptions().host?(this.log.trace("not dialing %a - target host did not match remote host %a",f,e.remoteAddr),!1):o.includes(d.host)?!1:this.components.transportManager.dialTransportForMultiaddr(f)==null?(this.log.trace("not dialing %a - transport unsupported",f),!1):!0}).map(f=>(f.getPeerId()==null&&(f=f.encapsulate(`/p2p/${i.toString()}`)),f));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(f=>f.toString()).join(", "),i);let l="",h=c[0];for await(let f of c){let d;h=f;try{if(d=await this.components.connectionManager.openConnection(f,n),!d.remoteAddr.equals(f))throw this.log.error("tried to dial %a but dialed %a",f,d.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,f),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.OK,addr:d.remoteAddr.decapsulateCode(K("p2p").code).bytes}}}catch(u){this.log.error("could not dial %p - %e",i,u),l=u.message}finally{d!=null&&await d.close()}}return{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_DIAL_ERROR,statusText:l,addr:h.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())||o.multiaddr.toOptions().family===6&&(!e||!Vi(o.multiaddr))||Co(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:Bo(),queue:new nn({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})=>i.toOptions().family===6),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);Tt(1/0,s),this.log.trace("asking %p to verify multiaddr %s",t.remotePeer,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=es(i).pb(Z),[,c]=await Promise.all([a.write({type:Z.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==Z.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let l=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,l),l!==Z.ResponseStatus.OK&&l!==Z.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),l===Z.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else l===Z.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Jf&&this.confirmAddress(o),o.failure===tl&&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=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};function el(r={}){return t=>new ln(t,r)}return Sa(rl);})();
|
|
2
|
+
"use strict";var Libp2PAutonat=(()=>{var wa=Object.create;var ir=Object.defineProperty;var ba=Object.getOwnPropertyDescriptor;var ya=Object.getOwnPropertyNames;var Ea=Object.getPrototypeOf,va=Object.prototype.hasOwnProperty;var dn=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)ir(r,e,{get:t[e],enumerable:!0})},us=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ya(t))!va.call(r,o)&&o!==e&&ir(r,o,{get:()=>t[o],enumerable:!(n=ba(t,o))||n.enumerable});return r};var fs=(r,t,e)=>(e=r!=null?wa(Ea(r)):{},us(t||!r||!r.__esModule?ir(e,"default",{value:r,enumerable:!0}):e,r)),Sa=r=>us(ir({},"__esModule",{value:!0}),r);var Bi=dn((tr,zr)=>{(function(r,t){"use strict";var e={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(u){if(!Array.isArray(u)&&!ArrayBuffer.isView(u))return!1;for(var p=0;p<u.length;p++)if(!Number.isInteger(u[p])||u[p]<0||u[p]>255)return!1;return!0}function o(u,p){return(u&65535)*p+(((u>>>16)*p&65535)<<16)}function s(u,p){return u<<p|u>>>32-p}function i(u){return u^=u>>>16,u=o(u,2246822507),u^=u>>>13,u=o(u,3266489909),u^=u>>>16,u}function a(u,p){u=[u[0]>>>16,u[0]&65535,u[1]>>>16,u[1]&65535],p=[p[0]>>>16,p[0]&65535,p[1]>>>16,p[1]&65535];var g=[0,0,0,0];return g[3]+=u[3]+p[3],g[2]+=g[3]>>>16,g[3]&=65535,g[2]+=u[2]+p[2],g[1]+=g[2]>>>16,g[2]&=65535,g[1]+=u[1]+p[1],g[0]+=g[1]>>>16,g[1]&=65535,g[0]+=u[0]+p[0],g[0]&=65535,[g[0]<<16|g[1],g[2]<<16|g[3]]}function c(u,p){u=[u[0]>>>16,u[0]&65535,u[1]>>>16,u[1]&65535],p=[p[0]>>>16,p[0]&65535,p[1]>>>16,p[1]&65535];var g=[0,0,0,0];return g[3]+=u[3]*p[3],g[2]+=g[3]>>>16,g[3]&=65535,g[2]+=u[2]*p[3],g[1]+=g[2]>>>16,g[2]&=65535,g[2]+=u[3]*p[2],g[1]+=g[2]>>>16,g[2]&=65535,g[1]+=u[1]*p[3],g[0]+=g[1]>>>16,g[1]&=65535,g[1]+=u[2]*p[2],g[0]+=g[1]>>>16,g[1]&=65535,g[1]+=u[3]*p[1],g[0]+=g[1]>>>16,g[1]&=65535,g[0]+=u[0]*p[3]+u[1]*p[2]+u[2]*p[1]+u[3]*p[0],g[0]&=65535,[g[0]<<16|g[1],g[2]<<16|g[3]]}function l(u,p){return p%=64,p===32?[u[1],u[0]]:p<32?[u[0]<<p|u[1]>>>32-p,u[1]<<p|u[0]>>>32-p]:(p-=32,[u[1]<<p|u[0]>>>32-p,u[0]<<p|u[1]>>>32-p])}function h(u,p){return p%=64,p===0?u:p<32?[u[0]<<p|u[1]>>>32-p,u[1]<<p]:[u[1]<<p-32,0]}function f(u,p){return[u[0]^p[0],u[1]^p[1]]}function d(u){return u=f(u,[0,u[0]>>>1]),u=c(u,[4283543511,3981806797]),u=f(u,[0,u[0]>>>1]),u=c(u,[3301882366,444984403]),u=f(u,[0,u[0]>>>1]),u}e.x86.hash32=function(u,p){if(e.inputValidation&&!n(u))return t;p=p||0;for(var g=u.length%4,x=u.length-g,w=p,b=0,m=3432918353,v=461845907,_=0;_<x;_=_+4)b=u[_]|u[_+1]<<8|u[_+2]<<16|u[_+3]<<24,b=o(b,m),b=s(b,15),b=o(b,v),w^=b,w=s(w,13),w=o(w,5)+3864292196;switch(b=0,g){case 3:b^=u[_+2]<<16;case 2:b^=u[_+1]<<8;case 1:b^=u[_],b=o(b,m),b=s(b,15),b=o(b,v),w^=b}return w^=u.length,w=i(w),w>>>0},e.x86.hash128=function(u,p){if(e.inputValidation&&!n(u))return t;p=p||0;for(var g=u.length%16,x=u.length-g,w=p,b=p,m=p,v=p,_=0,I=0,y=0,B=0,T=597399067,V=2869860233,F=951274213,O=2716044179,N=0;N<x;N=N+16)_=u[N]|u[N+1]<<8|u[N+2]<<16|u[N+3]<<24,I=u[N+4]|u[N+5]<<8|u[N+6]<<16|u[N+7]<<24,y=u[N+8]|u[N+9]<<8|u[N+10]<<16|u[N+11]<<24,B=u[N+12]|u[N+13]<<8|u[N+14]<<16|u[N+15]<<24,_=o(_,T),_=s(_,15),_=o(_,V),w^=_,w=s(w,19),w+=b,w=o(w,5)+1444728091,I=o(I,V),I=s(I,16),I=o(I,F),b^=I,b=s(b,17),b+=m,b=o(b,5)+197830471,y=o(y,F),y=s(y,17),y=o(y,O),m^=y,m=s(m,15),m+=v,m=o(m,5)+2530024501,B=o(B,O),B=s(B,18),B=o(B,T),v^=B,v=s(v,13),v+=w,v=o(v,5)+850148119;switch(_=0,I=0,y=0,B=0,g){case 15:B^=u[N+14]<<16;case 14:B^=u[N+13]<<8;case 13:B^=u[N+12],B=o(B,O),B=s(B,18),B=o(B,T),v^=B;case 12:y^=u[N+11]<<24;case 11:y^=u[N+10]<<16;case 10:y^=u[N+9]<<8;case 9:y^=u[N+8],y=o(y,F),y=s(y,17),y=o(y,O),m^=y;case 8:I^=u[N+7]<<24;case 7:I^=u[N+6]<<16;case 6:I^=u[N+5]<<8;case 5:I^=u[N+4],I=o(I,V),I=s(I,16),I=o(I,F),b^=I;case 4:_^=u[N+3]<<24;case 3:_^=u[N+2]<<16;case 2:_^=u[N+1]<<8;case 1:_^=u[N],_=o(_,T),_=s(_,15),_=o(_,V),w^=_}return w^=u.length,b^=u.length,m^=u.length,v^=u.length,w+=b,w+=m,w+=v,b+=w,m+=w,v+=w,w=i(w),b=i(b),m=i(m),v=i(v),w+=b,w+=m,w+=v,b+=w,m+=w,v+=w,("00000000"+(w>>>0).toString(16)).slice(-8)+("00000000"+(b>>>0).toString(16)).slice(-8)+("00000000"+(m>>>0).toString(16)).slice(-8)+("00000000"+(v>>>0).toString(16)).slice(-8)},e.x64.hash128=function(u,p){if(e.inputValidation&&!n(u))return t;p=p||0;for(var g=u.length%16,x=u.length-g,w=[0,p],b=[0,p],m=[0,0],v=[0,0],_=[2277735313,289559509],I=[1291169091,658871167],y=0;y<x;y=y+16)m=[u[y+4]|u[y+5]<<8|u[y+6]<<16|u[y+7]<<24,u[y]|u[y+1]<<8|u[y+2]<<16|u[y+3]<<24],v=[u[y+12]|u[y+13]<<8|u[y+14]<<16|u[y+15]<<24,u[y+8]|u[y+9]<<8|u[y+10]<<16|u[y+11]<<24],m=c(m,_),m=l(m,31),m=c(m,I),w=f(w,m),w=l(w,27),w=a(w,b),w=a(c(w,[0,5]),[0,1390208809]),v=c(v,I),v=l(v,33),v=c(v,_),b=f(b,v),b=l(b,31),b=a(b,w),b=a(c(b,[0,5]),[0,944331445]);switch(m=[0,0],v=[0,0],g){case 15:v=f(v,h([0,u[y+14]],48));case 14:v=f(v,h([0,u[y+13]],40));case 13:v=f(v,h([0,u[y+12]],32));case 12:v=f(v,h([0,u[y+11]],24));case 11:v=f(v,h([0,u[y+10]],16));case 10:v=f(v,h([0,u[y+9]],8));case 9:v=f(v,[0,u[y+8]]),v=c(v,I),v=l(v,33),v=c(v,_),b=f(b,v);case 8:m=f(m,h([0,u[y+7]],56));case 7:m=f(m,h([0,u[y+6]],48));case 6:m=f(m,h([0,u[y+5]],40));case 5:m=f(m,h([0,u[y+4]],32));case 4:m=f(m,h([0,u[y+3]],24));case 3:m=f(m,h([0,u[y+2]],16));case 2:m=f(m,h([0,u[y+1]],8));case 1:m=f(m,[0,u[y]]),m=c(m,_),m=l(m,31),m=c(m,I),w=f(w,m)}return w=f(w,[0,u.length]),b=f(b,[0,u.length]),w=a(w,b),b=a(b,w),w=d(w),b=d(b),w=a(w,b),b=a(b,w),("00000000"+(w[0]>>>0).toString(16)).slice(-8)+("00000000"+(w[1]>>>0).toString(16)).slice(-8)+("00000000"+(b[0]>>>0).toString(16)).slice(-8)+("00000000"+(b[1]>>>0).toString(16)).slice(-8)},typeof tr<"u"?(typeof zr<"u"&&zr.exports&&(tr=zr.exports=e),tr.murmurHash3=e):typeof define=="function"&&define.amd?define([],function(){return e}):(e._murmurHash3=r.murmurHash3,e.noConflict=function(){return r.murmurHash3=e._murmurHash3,e._murmurHash3=t,e.noConflict=t,e},r.murmurHash3=e)})(tr)});var Ti=dn((Rp,Li)=>{Li.exports=Bi()});var Hi=dn(or=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var l,h,f,d;return l=(c&255<<24)>>>24,h=(c&255<<16)>>>16,f=(c&65280)>>>8,d=c&255,[l,h,f,d].join(".")},i=function(c){var l,h,f,d,u,p;for(l=[],f=d=0;d<=3&&c.length!==0;f=++d){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}p=t(c),u=p[0],h=p[1],c=c.substring(h),l.push(u)}if(c.length!==0)throw new Error("Invalid IP");switch(l.length){case 1:if(l[0]>4294967295)throw new Error("Invalid IP");return l[0]>>>0;case 2:if(l[0]>255||l[1]>16777215)throw new Error("Invalid IP");return(l[0]<<24|l[1])>>>0;case 3:if(l[0]>255||l[1]>255||l[2]>65535)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2])>>>0;case 4:if(l[0]>255||l[1]>255||l[2]>255||l[3]>255)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2]<<8|l[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var l,h,f,d,u;for(d=0,l=10,h="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,l=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,l=8,h="7")),u=f;f<c.length;){if("0"<=c[f]&&c[f]<=h)d=d*l+(e(c[f])-n)>>>0;else if(l===16)if("a"<=c[f]&&c[f]<="f")d=d*l+(10+e(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")d=d*l+(10+e(c[f])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");f++}if(f===u)throw new Error("empty octet");return[d,f]},r=function(){function c(l,h){var f,d,u,p;if(typeof l!="string")throw new Error("Missing `net' parameter");if(h||(p=l.split("/",2),l=p[0],h=p[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(g){throw f=g,new Error("Invalid mask: "+h)}for(d=u=32;u>=0;d=--u)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(h||h===0)this.bitmask=parseInt(h,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(l)&this.maskLong)>>>0}catch(g){throw f=g,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+h);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new c(l)),l instanceof c?this.contains(l.base)&&this.contains(l.broadcast||l.last):(i(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(l){return l==null&&(l=1),new c(a(this.netLong+this.size*l),this.mask)},c.prototype.forEach=function(l){var h,f,d;for(d=i(this.first),f=i(this.last),h=0;d<=f;)l(a(d),d,h),h++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),or.ip2long=i,or.long2ip=a,or.Netmask=r}).call(or)});var el={};dt(el,{autoNAT:()=>tl});var pn=Symbol.for("@libp2p/peer-id");var Nt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Oe=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ar=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var cr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Fe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Tt=(r,...t)=>{try{[...t]}catch{}};var ur=class extends EventTarget{#t=new Map;constructor(){super(),Tt(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}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))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ls=Symbol.for("@libp2p/service-capabilities"),hs=Symbol.for("@libp2p/service-dependencies");var bn={};dt(bn,{base58btc:()=>W,base58flickr:()=>Ta});var Dl=new Uint8Array(0);function ds(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 Pt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ps(r){return new TextEncoder().encode(r)}function ms(r){return new TextDecoder().decode(r)}function _a(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),l=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,x=0,w=0,b=p.length;w!==b&&p[w]===0;)w++,g++;for(var m=(b-w)*h+1>>>0,v=new Uint8Array(m);w!==b;){for(var _=p[w],I=0,y=m-1;(_!==0||I<x)&&y!==-1;y--,I++)_+=256*v[y]>>>0,v[y]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");x=I,w++}for(var B=m-x;B!==m&&v[B]===0;)B++;for(var T=c.repeat(g);B<m;++B)T+=r.charAt(v[B]);return T}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var x=0,w=0;p[g]===c;)x++,g++;for(var b=(p.length-g)*l+1>>>0,m=new Uint8Array(b);p[g];){var v=e[p.charCodeAt(g)];if(v===255)return;for(var _=0,I=b-1;(v!==0||_<w)&&I!==-1;I--,_++)v+=a*m[I]>>>0,m[I]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");w=_,g++}if(p[g]!==" "){for(var y=b-w;y!==b&&m[y]===0;)y++;for(var B=new Uint8Array(x+(b-y)),T=x;y!==b;)B[T++]=m[y++];return B}}}function u(p){var g=d(p);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:d,decode:u}}var Aa=_a,Ia=Aa,xs=Ia;var mn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},gn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ws(this,t)}},xn=class{decoders;constructor(t){this.decoders=t}or(t){return ws(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 ws(r,t){return new xn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var wn=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 mn(t,e,n),this.decoder=new gn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ee({name:r,prefix:t,encode:e,decode:n}){return new wn(r,t,e,n)}function Xt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=xs(e,r);return Ee({prefix:t,name:r,encode:n,decode:s=>Pt(o(s))})}function Ba(r,t,e,n){let o={};for(let h=0;h<t.length;++h)o[t[h]]=h;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),a=0,c=0,l=0;for(let h=0;h<s;++h){let f=o[r[h]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,a+=e,a>=8&&(a-=8,i[l++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function La(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;)s+="=";return s}function Q({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ee({prefix:t,name:r,encode(o){return La(o,n,e)},decode(o){return Ba(o,n,e,r)}})}var W=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ta=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yn={};dt(yn,{base32:()=>kt,base32hex:()=>Pa,base32hexpad:()=>Ua,base32hexpadupper:()=>Ca,base32hexupper:()=>ka,base32pad:()=>Da,base32padupper:()=>Na,base32upper:()=>Ra,base32z:()=>Oa});var kt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ra=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Da=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Na=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Pa=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ka=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ua=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ca=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Oa=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var En={};dt(En,{base36:()=>Me,base36upper:()=>Fa});var Me=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fa=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ma=Es,bs=128,za=127,qa=~za,Va=Math.pow(2,31);function Es(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Va;)t[e++]=r&255|bs,r/=128;for(;r&qa;)t[e++]=r&255|bs,r>>>=7;return t[e]=r|0,Es.bytes=e-n+1,t}var Ha=vn,Ka=128,ys=127;function vn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw vn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ys)<<o:(i&ys)*Math.pow(2,o),o+=7}while(i>=Ka);return vn.bytes=s-n,e}var Ga=Math.pow(2,7),ja=Math.pow(2,14),Za=Math.pow(2,21),$a=Math.pow(2,28),Xa=Math.pow(2,35),Wa=Math.pow(2,42),Ya=Math.pow(2,49),Qa=Math.pow(2,56),Ja=Math.pow(2,63),tc=function(r){return r<Ga?1:r<ja?2:r<Za?3:r<$a?4:r<Xa?5:r<Wa?6:r<Ya?7:r<Qa?8:r<Ja?9:10},ec={encode:Ma,decode:Ha,encodingLength:tc},rc=ec,ze=rc;function qe(r,t=0){return[ze.decode(r,t),ze.decode.bytes]}function ve(r,t,e=0){return ze.encode(r,t,e),t}function Se(r){return ze.encodingLength(r)}function ie(r,t){let e=t.byteLength,n=Se(r),o=n+Se(e),s=new Uint8Array(o+e);return ve(r,s,0),ve(e,s,n),s.set(t,o),new _e(r,e,t,s)}function Ut(r){let t=Pt(r),[e,n]=qe(t),[o,s]=qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new _e(e,o,i,t)}function vs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ds(r.bytes,e.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ss(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return oc(e,Sn(r),t??W.encoder);default:return sc(e,Sn(r),t??kt.encoder)}}var _s=new WeakMap;function Sn(r){let t=_s.get(r);if(t==null){let e=new Map;return _s.set(r,e),e}return t}var lt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ic)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=ie(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&&vs(t.multihash,n.multihash)}toString(t){return Ss(this,t)}toJSON(){return{"/":Ss(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??As(n,o,s.bytes))}else if(e[ac]===!0){let{version:n,multihash:o,code:s}=e,i=Ut(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!==Ve)throw new Error(`Version 0 CID must use dag-pb (code: ${Ve}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=As(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ve,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=Pt(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 _e(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[f,d]=qe(t.subarray(e));return e+=d,f},o=n(),s=Ve;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(),l=e+c,h=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(t,e){let[n,o]=nc(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 Sn(s).set(n,t),s}};function nc(r,t){switch(r[0]){case"Q":{let e=t??W;return[W.prefix,e.decode(`${W.prefix}${r}`)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}case kt.prefix:{let e=t??kt;return[kt.prefix,e.decode(r)]}case Me.prefix:{let e=t??Me;return[Me.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 oc(r,t,e){let{prefix:n}=e;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function sc(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 Ve=112,ic=18;function As(r,t,e){let n=Se(r),o=n+Se(t),s=new Uint8Array(o+e.byteLength);return ve(r,s,0),ve(t,s,n),s.set(e,o),s}var ac=Symbol.for("@ipld/js-cid/CID");var _n={};dt(_n,{identity:()=>Ot});var Is=0,cc="identity",Bs=Pt;function uc(r){return ie(Is,Bs(r))}var Ot={code:Is,name:cc,encode:Bs,digest:uc};function xt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ls(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function fc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ae(r,...t){if(!fc(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Ts(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ls(r.outputLen),Ls(r.blockLen)}function Ie(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 Rs(r,t){Ae(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function lr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Et(r,t){return r<<32-t|r>>>t}function Ds(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function He(r){return typeof r=="string"&&(r=Ds(r)),Ae(r),r}function An(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ae(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}var Be=class{clone(){return this._cloneInto()}};function hr(r){let t=n=>r().update(He(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function dr(r=32){if(ae&&typeof ae.getRandomValues=="function")return ae.getRandomValues(new Uint8Array(r));if(ae&&typeof ae.randomBytes=="function")return ae.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function lc(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function Ns(r,t,e){return r&t^~r&e}function Ps(r,t,e){return r&t^r&e^t&e}var Le=class extends Be{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=lr(this.buffer)}update(t){Ie(this);let{view:e,buffer:n,blockLen:o}=this;t=He(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=lr(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){Ie(this),Rs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;lc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=lr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,h[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){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.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var pr=BigInt(4294967295),In=BigInt(32);function ks(r,t=!1){return t?{h:Number(r&pr),l:Number(r>>In&pr)}:{h:Number(r>>In&pr)|0,l:Number(r&pr)|0}}function hc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=ks(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var dc=(r,t)=>BigInt(r>>>0)<<In|BigInt(t>>>0),pc=(r,t,e)=>r>>>e,mc=(r,t,e)=>r<<32-e|t>>>e,gc=(r,t,e)=>r>>>e|t<<32-e,xc=(r,t,e)=>r<<32-e|t>>>e,wc=(r,t,e)=>r<<64-e|t>>>e-32,bc=(r,t,e)=>r>>>e-32|t<<64-e,yc=(r,t)=>t,Ec=(r,t)=>r,vc=(r,t,e)=>r<<e|t>>>32-e,Sc=(r,t,e)=>t<<e|r>>>32-e,_c=(r,t,e)=>t<<e-32|r>>>64-e,Ac=(r,t,e)=>r<<e-32|t>>>64-e;function Ic(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Bc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Lc=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Tc=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Rc=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Dc=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Nc=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Pc={fromBig:ks,split:hc,toBig:dc,shrSH:pc,shrSL:mc,rotrSH:gc,rotrSL:xc,rotrBH:wc,rotrBL:bc,rotr32H:yc,rotr32L:Ec,rotlSH:vc,rotlSL:Sc,rotlBH:_c,rotlBL:Ac,add:Ic,add3L:Bc,add3H:Lc,add4L:Tc,add4H:Rc,add5H:Nc,add5L:Dc},C=Pc;var[kc,Uc]=C.split(["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))),Wt=new Uint32Array(80),Yt=new Uint32Array(80),Bn=class extends Le{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:h,Fh:f,Fl:d,Gh:u,Gl:p,Hh:g,Hl:x}=this;return[t,e,n,o,s,i,a,c,l,h,f,d,u,p,g,x]}set(t,e,n,o,s,i,a,c,l,h,f,d,u,p,g,x){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=l|0,this.El=h|0,this.Fh=f|0,this.Fl=d|0,this.Gh=u|0,this.Gl=p|0,this.Hh=g|0,this.Hl=x|0}process(t,e){for(let m=0;m<16;m++,e+=4)Wt[m]=t.getUint32(e),Yt[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let v=Wt[m-15]|0,_=Yt[m-15]|0,I=C.rotrSH(v,_,1)^C.rotrSH(v,_,8)^C.shrSH(v,_,7),y=C.rotrSL(v,_,1)^C.rotrSL(v,_,8)^C.shrSL(v,_,7),B=Wt[m-2]|0,T=Yt[m-2]|0,V=C.rotrSH(B,T,19)^C.rotrBH(B,T,61)^C.shrSH(B,T,6),F=C.rotrSL(B,T,19)^C.rotrBL(B,T,61)^C.shrSL(B,T,6),O=C.add4L(y,F,Yt[m-7],Yt[m-16]),N=C.add4H(O,I,V,Wt[m-7],Wt[m-16]);Wt[m]=N|0,Yt[m]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:h,Eh:f,El:d,Fh:u,Fl:p,Gh:g,Gl:x,Hh:w,Hl:b}=this;for(let m=0;m<80;m++){let v=C.rotrSH(f,d,14)^C.rotrSH(f,d,18)^C.rotrBH(f,d,41),_=C.rotrSL(f,d,14)^C.rotrSL(f,d,18)^C.rotrBL(f,d,41),I=f&u^~f&g,y=d&p^~d&x,B=C.add5L(b,_,y,Uc[m],Yt[m]),T=C.add5H(B,w,v,I,kc[m],Wt[m]),V=B|0,F=C.rotrSH(n,o,28)^C.rotrBH(n,o,34)^C.rotrBH(n,o,39),O=C.rotrSL(n,o,28)^C.rotrBL(n,o,34)^C.rotrBL(n,o,39),N=n&s^n&a^s&a,L=o&i^o&c^i&c;w=g|0,b=x|0,g=u|0,x=p|0,u=f|0,p=d|0,{h:f,l:d}=C.add(l|0,h|0,T|0,V|0),l=a|0,h=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let D=C.add3L(V,O,L);n=C.add3H(D,T,F,N),o=D|0}({h:n,l:o}=C.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=C.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=C.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=C.add(this.Dh|0,this.Dl|0,l|0,h|0),{h:f,l:d}=C.add(this.Eh|0,this.El|0,f|0,d|0),{h:u,l:p}=C.add(this.Fh|0,this.Fl|0,u|0,p|0),{h:g,l:x}=C.add(this.Gh|0,this.Gl|0,g|0,x|0),{h:w,l:b}=C.add(this.Hh|0,this.Hl|0,w|0,b|0),this.set(n,o,s,i,a,c,l,h,f,d,u,p,g,x,w,b)}roundClean(){Wt.fill(0),Yt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Us=hr(()=>new Bn);var xr={};dt(xr,{aInRange:()=>pt,abool:()=>vt,abytes:()=>Te,bitGet:()=>qc,bitLen:()=>Dn,bitMask:()=>Ge,bitSet:()=>Vc,bytesToHex:()=>Mt,bytesToNumberBE:()=>zt,bytesToNumberLE:()=>Jt,concatBytes:()=>qt,createHmacDrbg:()=>Nn,ensureBytes:()=>Y,equalBytes:()=>Mc,hexToBytes:()=>ue,hexToNumber:()=>Rn,inRange:()=>Ke,isBytes:()=>Qt,memoized:()=>le,notImplemented:()=>Kc,numberToBytesBE:()=>te,numberToBytesLE:()=>fe,numberToHexUnpadded:()=>ce,numberToVarBytesBE:()=>Fc,utf8ToBytes:()=>zc,validateObject:()=>Rt});var mr=BigInt(0),gr=BigInt(1),Cc=BigInt(2);function Qt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Te(r){if(!Qt(r))throw new Error("Uint8Array expected")}function vt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Oc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Mt(r){Te(r);let t="";for(let e=0;e<r.length;e++)t+=Oc[r[e]];return t}function ce(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Rn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?mr:BigInt("0x"+r)}var Ft={_0:48,_9:57,A:65,F:70,a:97,f:102};function Cs(r){if(r>=Ft._0&&r<=Ft._9)return r-Ft._0;if(r>=Ft.A&&r<=Ft.F)return r-(Ft.A-10);if(r>=Ft.a&&r<=Ft.f)return r-(Ft.a-10)}function ue(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("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=Cs(r.charCodeAt(s)),a=Cs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function zt(r){return Rn(Mt(r))}function Jt(r){return Te(r),Rn(Mt(Uint8Array.from(r).reverse()))}function te(r,t){return ue(r.toString(16).padStart(t*2,"0"))}function fe(r,t){return te(r,t).reverse()}function Fc(r){return ue(ce(r))}function Y(r,t,e){let n;if(typeof t=="string")try{n=ue(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Qt(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function qt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Te(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 Mc(r,t){if(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 zc(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Ln=r=>typeof r=="bigint"&&mr<=r;function Ke(r,t,e){return Ln(r)&&Ln(t)&&Ln(e)&&t<=r&&r<e}function pt(r,t,e,n){if(!Ke(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Dn(r){let t;for(t=0;r>mr;r>>=gr,t+=1);return t}function qc(r,t){return r>>BigInt(t)&gr}function Vc(r,t,e){return r|(e?gr:mr)<<BigInt(t)}var Ge=r=>(Cc<<BigInt(r-1))-gr,Tn=r=>new Uint8Array(r),Os=r=>Uint8Array.from(r);function Nn(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Tn(r),o=Tn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=Tn())=>{o=a(Os([0]),f),n=a(),f.length!==0&&(o=a(Os([1]),f),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,d=[];for(;f<t;){n=a();let u=n.slice();d.push(u),f+=n.length}return qt(...d)};return(f,d)=>{i(),c(f);let u;for(;!(u=d(l()));)c();return i(),u}}var Hc={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Qt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Rt(r,t,e={}){let n=(o,s,i)=>{let a=Hc[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var Kc=()=>{throw new Error("not implemented")};function le(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var J=BigInt(0),$=BigInt(1),he=BigInt(2),Gc=BigInt(3),Pn=BigInt(4),Fs=BigInt(5),Ms=BigInt(8),jc=BigInt(9),Zc=BigInt(16);function G(r,t){let e=r%t;return e>=J?e:t+e}function $c(r,t,e){if(t<J)throw new Error("invalid exponent, negatives unsupported");if(e<=J)throw new Error("invalid modulus");if(e===$)return J;let n=$;for(;t>J;)t&$&&(n=n*r%e),r=r*r%e,t>>=$;return n}function X(r,t,e){let n=r;for(;t-- >J;)n*=n,n%=e;return n}function wr(r,t){if(r===J)throw new Error("invert: expected non-zero number");if(t<=J)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=J,s=$,i=$,a=J;for(;e!==J;){let l=n/e,h=n%e,f=o-i*l,d=s-a*l;n=e,e=h,o=i,s=a,i=f,a=d}if(n!==$)throw new Error("invert: does not exist");return G(o,t)}function Xc(r){let t=(r-$)/he,e,n,o;for(e=r-$,n=0;e%he===J;e/=he,n++);for(o=he;o<r&&$c(o,t,r)!==r-$;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+$)/Pn;return function(c,l){let h=c.pow(l,i);if(!c.eql(c.sqr(h),l))throw new Error("Cannot find square root");return h}}let s=(e+$)/he;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,h=a.pow(a.mul(a.ONE,o),e),f=a.pow(c,s),d=a.pow(c,e);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let u=1;for(let g=a.sqr(d);u<l&&!a.eql(g,a.ONE);u++)g=a.sqr(g);let p=a.pow(h,$<<BigInt(l-u-1));h=a.sqr(p),f=a.mul(f,p),d=a.mul(d,h),l=u}return f}}function Wc(r){if(r%Pn===Gc){let t=(r+$)/Pn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%Ms===Fs){let t=(r-Fs)/Ms;return function(n,o){let s=n.mul(o,he),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,he),i),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%Zc,Xc(r)}var zs=(r,t)=>(G(r,t)&$)===$,Yc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function kn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Yc.reduce((n,o)=>(n[o]="function",n),t);return Rt(r,e)}function Qc(r,t,e){if(e<J)throw new Error("invalid exponent, negatives unsupported");if(e===J)return r.ONE;if(e===$)return t;let n=r.ONE,o=t;for(;e>J;)e&$&&(n=r.mul(n,o)),o=r.sqr(o),e>>=$;return n}function Jc(r,t){let e=new Array(t.length),n=t.reduce((s,i,a)=>r.is0(i)?s:(e[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,a)=>r.is0(i)?s:(e[a]=r.mul(s,e[a]),r.mul(s,i)),o),e}function Un(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ee(r,t,e=!1,n={}){if(r<=J)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Un(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:Ge(o),ZERO:J,ONE:$,create:c=>G(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return J<=c&&c<r},is0:c=>c===J,isOdd:c=>(c&$)===$,neg:c=>G(-c,r),eql:(c,l)=>c===l,sqr:c=>G(c*c,r),add:(c,l)=>G(c+l,r),sub:(c,l)=>G(c-l,r),mul:(c,l)=>G(c*l,r),pow:(c,l)=>Qc(a,c,l),div:(c,l)=>G(c*wr(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>wr(c,r),sqrt:n.sqrt||(c=>(i||(i=Wc(r)),i(a,c))),invertBatch:c=>Jc(a,c),cmov:(c,l,h)=>h?l:c,toBytes:c=>e?fe(c,s):te(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?Jt(c):zt(c)}});return Object.freeze(a)}function qs(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Cn(r){let t=qs(r);return t+Math.ceil(t/2)}function Vs(r,t,e=!1){let n=r.length,o=qs(t),s=Cn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Jt(r):zt(r),a=G(i,t-$)+$;return e?fe(a,o):te(a,o)}var Hs=BigInt(0),br=BigInt(1);function On(r,t){let e=t.negate();return r?e:t}function Ks(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Fn(r,t){Ks(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function tu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function eu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var Mn=new WeakMap,Gs=new WeakMap;function zn(r){return Gs.get(r)||1}function yr(r,t){return{constTimeNegate:On,hasPrecomputes(e){return zn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Hs;)n&br&&(o=o.add(s)),s=s.double(),n>>=br;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Fn(n,t),i=[],a=e,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let h=1;h<s;h++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=Fn(e,t),a=r.ZERO,c=r.BASE,l=BigInt(2**e-1),h=2**e,f=BigInt(e);for(let d=0;d<s;d++){let u=d*i,p=Number(o&l);o>>=f,p>i&&(p-=h,o+=br);let g=u,x=u+Math.abs(p)-1,w=d%2!==0,b=p<0;p===0?c=c.add(On(w,n[g])):a=a.add(On(b,n[x]))}return{p:a,f:c}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:a}=Fn(e,t),c=BigInt(2**e-1),l=2**e,h=BigInt(e);for(let f=0;f<i;f++){let d=f*a;if(o===Hs)break;let u=Number(o&c);if(o>>=h,u>a&&(u-=l,o+=br),u===0)continue;let p=n[d+Math.abs(u)-1];u<0&&(p=p.negate()),s=s.add(p)}return s},getPrecomputes(e,n,o){let s=Mn.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&Mn.set(n,o(s))),s},wNAFCached(e,n,o){let s=zn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=zn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Ks(n,t),Gs.set(e,n),Mn.delete(e)}}}function Er(r,t,e,n){if(tu(e,r),eu(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Dn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=(1<<i)-1,c=new Array(a+1).fill(o),l=Math.floor((t.BITS-1)/i)*i,h=o;for(let f=l;f>=0;f-=i){c.fill(o);for(let u=0;u<n.length;u++){let p=n[u],g=Number(p>>BigInt(f)&BigInt(a));c[g]=c[g].add(e[u])}let d=o;for(let u=c.length-1,p=o;u>0;u--)p=p.add(c[u]),d=d.add(p);if(h=h.add(d),f!==0)for(let u=0;u<i;u++)h=h.double()}return h}function je(r){return kn(r.Fp),Rt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Un(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var St=BigInt(0),mt=BigInt(1),vr=BigInt(2),ru=BigInt(8),nu={zip215:!0};function ou(r){let t=je(r);return Rt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function js(r){let t=ou(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,l=vr<<BigInt(a*8)-mt,h=e.create,f=ee(t.n,t.nBitLength),d=t.uvRatio||((S,E)=>{try{return{isValid:!0,value:e.sqrt(S*e.inv(E))}}catch{return{isValid:!1,value:St}}}),u=t.adjustScalarBytes||(S=>S),p=t.domain||((S,E,A)=>{if(vt("phflag",A),E.length||A)throw new Error("Contexts/pre-hash are not supported");return S});function g(S,E){pt("coordinate "+S,E,St,l)}function x(S){if(!(S instanceof m))throw new Error("ExtendedPoint expected")}let w=le((S,E)=>{let{ex:A,ey:R,ez:P}=S,k=S.is0();E==null&&(E=k?ru:e.inv(P));let M=h(A*E),z=h(R*E),U=h(P*E);if(k)return{x:St,y:mt};if(U!==mt)throw new Error("invZ was invalid");return{x:M,y:z}}),b=le(S=>{let{a:E,d:A}=t;if(S.is0())throw new Error("bad point: ZERO");let{ex:R,ey:P,ez:k,et:M}=S,z=h(R*R),U=h(P*P),H=h(k*k),j=h(H*H),rt=h(z*E),nt=h(H*h(rt+U)),st=h(j+h(A*h(z*U)));if(nt!==st)throw new Error("bad point: equation left != right (1)");let it=h(R*P),ht=h(k*M);if(it!==ht)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(E,A,R,P){this.ex=E,this.ey=A,this.ez=R,this.et=P,g("x",E),g("y",A),g("z",R),g("t",P),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(E){if(E instanceof m)throw new Error("extended point not allowed");let{x:A,y:R}=E||{};return g("x",A),g("y",R),new m(A,R,mt,h(A*R))}static normalizeZ(E){let A=e.invertBatch(E.map(R=>R.ez));return E.map((R,P)=>R.toAffine(A[P])).map(m.fromAffine)}static msm(E,A){return Er(m,f,E,A)}_setWindowSize(E){I.setWindowSize(this,E)}assertValidity(){b(this)}equals(E){x(E);let{ex:A,ey:R,ez:P}=this,{ex:k,ey:M,ez:z}=E,U=h(A*z),H=h(k*P),j=h(R*z),rt=h(M*P);return U===H&&j===rt}is0(){return this.equals(m.ZERO)}negate(){return new m(h(-this.ex),this.ey,this.ez,h(-this.et))}double(){let{a:E}=t,{ex:A,ey:R,ez:P}=this,k=h(A*A),M=h(R*R),z=h(vr*h(P*P)),U=h(E*k),H=A+R,j=h(h(H*H)-k-M),rt=U+M,nt=rt-z,st=U-M,it=h(j*nt),ht=h(rt*st),ft=h(j*st),Lt=h(nt*rt);return new m(it,ht,Lt,ft)}add(E){x(E);let{a:A,d:R}=t,{ex:P,ey:k,ez:M,et:z}=this,{ex:U,ey:H,ez:j,et:rt}=E;if(A===BigInt(-1)){let rs=h((k-P)*(H+U)),ns=h((k+P)*(H-U)),hn=h(ns-rs);if(hn===St)return this.double();let os=h(M*vr*rt),ss=h(z*vr*j),is=ss+os,as=ns+rs,cs=ss-os,pa=h(is*hn),ma=h(as*cs),ga=h(is*cs),xa=h(hn*as);return new m(pa,ma,xa,ga)}let nt=h(P*U),st=h(k*H),it=h(z*R*rt),ht=h(M*j),ft=h((P+k)*(U+H)-nt-st),Lt=ht-it,Dt=ht+it,Ce=h(st-A*nt),fa=h(ft*Lt),la=h(Dt*Ce),ha=h(ft*Ce),da=h(Lt*Dt);return new m(fa,la,da,ha)}subtract(E){return this.add(E.negate())}wNAF(E){return I.wNAFCached(this,E,m.normalizeZ)}multiply(E){let A=E;pt("scalar",A,mt,n);let{p:R,f:P}=this.wNAF(A);return m.normalizeZ([R,P])[0]}multiplyUnsafe(E,A=m.ZERO){let R=E;return pt("scalar",R,St,n),R===St?_:this.is0()||R===mt?this:I.wNAFCachedUnsafe(this,R,m.normalizeZ,A)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return I.unsafeLadder(this,n).is0()}toAffine(E){return w(this,E)}clearCofactor(){let{h:E}=t;return E===mt?this:this.multiplyUnsafe(E)}static fromHex(E,A=!1){let{d:R,a:P}=t,k=e.BYTES;E=Y("pointHex",E,k),vt("zip215",A);let M=E.slice(),z=E[k-1];M[k-1]=z&-129;let U=Jt(M),H=A?l:e.ORDER;pt("pointHex.y",U,St,H);let j=h(U*U),rt=h(j-mt),nt=h(R*j-P),{isValid:st,value:it}=d(rt,nt);if(!st)throw new Error("Point.fromHex: invalid y coordinate");let ht=(it&mt)===mt,ft=(z&128)!==0;if(!A&&it===St&&ft)throw new Error("Point.fromHex: x=0 and x_0=1");return ft!==ht&&(it=h(-it)),m.fromAffine({x:it,y:U})}static fromPrivateKey(E){return T(E).point}toRawBytes(){let{x:E,y:A}=this.toAffine(),R=fe(A,e.BYTES);return R[R.length-1]|=E&mt?128:0,R}toHex(){return Mt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,mt,h(t.Gx*t.Gy)),m.ZERO=new m(St,mt,mt,St);let{BASE:v,ZERO:_}=m,I=yr(m,a*8);function y(S){return G(S,n)}function B(S){return y(Jt(S))}function T(S){let E=e.BYTES;S=Y("private key",S,E);let A=Y("hashed private key",s(S),2*E),R=u(A.slice(0,E)),P=A.slice(E,2*E),k=B(R),M=v.multiply(k),z=M.toRawBytes();return{head:R,prefix:P,scalar:k,point:M,pointBytes:z}}function V(S){return T(S).pointBytes}function F(S=new Uint8Array,...E){let A=qt(...E);return B(s(p(A,Y("context",S),!!o)))}function O(S,E,A={}){S=Y("message",S),o&&(S=o(S));let{prefix:R,scalar:P,pointBytes:k}=T(E),M=F(A.context,R,S),z=v.multiply(M).toRawBytes(),U=F(A.context,z,k,S),H=y(M+U*P);pt("signature.s",H,St,n);let j=qt(z,fe(H,e.BYTES));return Y("result",j,e.BYTES*2)}let N=nu;function L(S,E,A,R=N){let{context:P,zip215:k}=R,M=e.BYTES;S=Y("signature",S,2*M),E=Y("message",E),A=Y("publicKey",A,M),k!==void 0&&vt("zip215",k),o&&(E=o(E));let z=Jt(S.slice(M,2*M)),U,H,j;try{U=m.fromHex(A,k),H=m.fromHex(S.slice(0,M),k),j=v.multiplyUnsafe(z)}catch{return!1}if(!k&&U.isSmallOrder())return!1;let rt=F(P,H.toRawBytes(),U.toRawBytes(),E);return H.add(U.multiplyUnsafe(rt)).subtract(j).clearCofactor().equals(m.ZERO)}return v._setWindowSize(8),{CURVE:t,getPublicKey:V,sign:O,verify:L,ExtendedPoint:m,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>i(e.BYTES),precompute(S=8,E=m.BASE){return E._setWindowSize(S),E.multiply(BigInt(3)),E}}}}var qn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Zs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Sh=BigInt(0),su=BigInt(1),$s=BigInt(2),_h=BigInt(3),iu=BigInt(5),au=BigInt(8);function cu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=qn,a=r*r%s*r%s,c=X(a,$s,s)*a%s,l=X(c,su,s)*r%s,h=X(l,iu,s)*l%s,f=X(h,t,s)*h%s,d=X(f,e,s)*f%s,u=X(d,n,s)*d%s,p=X(u,o,s)*u%s,g=X(p,o,s)*u%s,x=X(g,t,s)*h%s;return{pow_p_5_8:X(x,$s,s)*r%s,b2:a}}function uu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function fu(r,t){let e=qn,n=G(t*t*t,e),o=G(n*n*t,e),s=cu(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,l=G(i*Zs,e),h=a===r,f=a===G(-r,e),d=a===G(-r*Zs,e);return h&&(i=c),(f||d)&&(i=l),zs(i,e)&&(i=G(-i,e)),{isValid:h||f,value:i}}var lu=ee(qn,void 0,!0),hu={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:lu,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:au,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Us,randomBytes:dr,adjustScalarBytes:uu,uvRatio:fu},Xs=js(hu);var Sr=32;function Ws(r,t,e){return Xs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var _r=class{type="Ed25519";raw;constructor(t){this.raw=Vn(t,Sr)}toMultihash(){return Ot.digest(Ar(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return Ws(this.raw,e,t)}};function Qs(r){return r=Vn(r,Sr),new _r(r)}function Vn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Oe(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function _t(r=0){return new Uint8Array(r)}function gt(r=0){return new Uint8Array(r)}var pu=Math.pow(2,7),mu=Math.pow(2,14),gu=Math.pow(2,21),Hn=Math.pow(2,28),Kn=Math.pow(2,35),Gn=Math.pow(2,42),jn=Math.pow(2,49),q=128,at=127;function ct(r){if(r<pu)return 1;if(r<mu)return 2;if(r<gu)return 3;if(r<Hn)return 4;if(r<Kn)return 5;if(r<Gn)return 6;if(r<jn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Zn(r,t,e=0){switch(ct(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 xu(r,t,e=0){switch(ct(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 $n(r,t){let e=r[t],n=0;if(n+=e&at,e<q||(e=r[t+1],n+=(e&at)<<7,e<q)||(e=r[t+2],n+=(e&at)<<14,e<q)||(e=r[t+3],n+=(e&at)<<21,e<q)||(e=r[t+4],n+=(e&at)*Hn,e<q)||(e=r[t+5],n+=(e&at)*Kn,e<q)||(e=r[t+6],n+=(e&at)*Gn,e<q)||(e=r[t+7],n+=(e&at)*jn,e<q))return n;throw new RangeError("Could not decode varint")}function wu(r,t){let e=r.get(t),n=0;if(n+=e&at,e<q||(e=r.get(t+1),n+=(e&at)<<7,e<q)||(e=r.get(t+2),n+=(e&at)<<14,e<q)||(e=r.get(t+3),n+=(e&at)<<21,e<q)||(e=r.get(t+4),n+=(e&at)*Hn,e<q)||(e=r.get(t+5),n+=(e&at)*Kn,e<q)||(e=r.get(t+6),n+=(e&at)*Gn,e<q)||(e=r.get(t+7),n+=(e&at)*jn,e<q))return n;throw new RangeError("Could not decode varint")}function re(r,t,e=0){return t==null&&(t=gt(ct(r))),t instanceof Uint8Array?Zn(r,t,e):xu(r,t,e)}function Vt(r,t=0){return r instanceof Uint8Array?$n(r,t):wu(r,t)}var Wn=new Float32Array([-0]),ne=new Uint8Array(Wn.buffer);function Js(r,t,e){Wn[0]=r,t[e]=ne[0],t[e+1]=ne[1],t[e+2]=ne[2],t[e+3]=ne[3]}function ti(r,t){return ne[0]=r[t],ne[1]=r[t+1],ne[2]=r[t+2],ne[3]=r[t+3],Wn[0]}var Yn=new Float64Array([-0]),ut=new Uint8Array(Yn.buffer);function ei(r,t,e){Yn[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function ri(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],Yn[0]}var bu=BigInt(Number.MAX_SAFE_INTEGER),yu=BigInt(Number.MIN_SAFE_INTEGER),wt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return de;if(t<bu&&t>yu)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>ni&&(o=0n,++n>ni&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return de;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):de}},de=new wt(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var ni=4294967296n;function oi(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 si(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 Qn(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 At(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Ir(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Jn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,At(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 At(this,4);return Ir(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return Ir(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=ti(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=ri(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 At(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return si(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new wt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw At(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 At(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 At(this,8);let t=Ir(this.buf,this.pos+=4),e=Ir(this.buf,this.pos+=4);return new wt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=$n(this.buf,this.pos);return this.pos+=ct(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 to(r){return new Jn(r instanceof Uint8Array?r:r.subarray())}function Ht(r,t,e){let n=to(r);return t.decode(n,void 0,e)}var eo={};dt(eo,{base10:()=>Eu});var Eu=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var ro={};dt(ro,{base16:()=>vu,base16upper:()=>Su});var vu=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Su=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var no={};dt(no,{base2:()=>_u});var _u=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var oo={};dt(oo,{base256emoji:()=>Tu});var ai=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}"),Au=ai.reduce((r,t,e)=>(r[e]=t,r),[]),Iu=ai.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Bu(r){return r.reduce((t,e)=>(t+=Au[e],t),"")}function Lu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Iu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Tu=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:Bu,decode:Lu});var so={};dt(so,{base64:()=>Ru,base64pad:()=>Du,base64url:()=>Nu,base64urlpad:()=>Pu});var Ru=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Du=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Nu=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Pu=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var io={};dt(io,{base8:()=>ku});var ku=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ao={};dt(ao,{identity:()=>Uu});var Uu=Ee({prefix:"\0",name:"identity",encode:r=>ms(r),decode:r=>ps(r)});var id=new TextEncoder,ad=new TextDecoder;var fo={};dt(fo,{sha256:()=>Ze,sha512:()=>Fu});function uo({name:r,code:t,encode:e}){return new co(r,t,e)}var co=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?ie(this.code,e):e.then(n=>ie(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ui(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ze=uo({name:"sha2-256",code:18,encode:ui("SHA-256")}),Fu=uo({name:"sha2-512",code:19,encode:ui("SHA-512")});var $e={...ao,...no,...io,...eo,...ro,...yn,...En,...bn,...so,...oo},bd={...fo,..._n};function li(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var fi=li("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),lo=li("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=gt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Mu={utf8:fi,"utf-8":fi,hex:$e.base16,latin1:lo,ascii:lo,binary:lo,...$e},Br=Mu;function tt(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function ho(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),a}}var pe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function po(){}var go=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},zu=ho();function qu(r){return globalThis.Buffer!=null?gt(r):zu(r)}var We=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(po,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new pe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new xo((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(Lr,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=wt.fromBigInt(t);return this._push(Lr,e.length(),e)}uint64Number(t){return this._push(Zn,ct(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=wt.fromBigInt(t).zzEncode();return this._push(Lr,e.length(),e)}sint64Number(t){let e=wt.fromNumber(t).zzEncode();return this._push(Lr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(mo,1,t?1:0)}fixed32(t){return this._push(Xe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=wt.fromBigInt(t);return this._push(Xe,4,e.lo)._push(Xe,4,e.hi)}fixed64Number(t){let e=wt.fromNumber(t);return this._push(Xe,4,e.lo)._push(Xe,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(Js,4,t)}double(t){return this._push(ei,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(mo,1,0):this.uint32(e)._push(Hu,e,t)}string(t){let e=oi(t);return e!==0?this.uint32(e)._push(Qn,e,t):this._push(mo,1,0)}fork(){return this.states=new go(this),this.head=this.tail=new pe(po,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 pe(po,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=qu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function mo(r,t,e){t[e]=r&255}function Vu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var xo=class extends pe{next;constructor(t,e){super(Vu,t,e),this.next=void 0}};function Lr(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 Xe(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 Hu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(We.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ku,t,r),this},We.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Gu,t,r),this});function Ku(r,t,e){t.set(r,e)}function Gu(r,t,e){r.length<40?Qn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(tt(r),e)}function wo(){return new We}function Kt(r,t){let e=wo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Re;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Re||(Re={}));function Tr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function De(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Tr("enum",Re.VARINT,e,n)}function Gt(r,t){return Tr("message",Re.LENGTH_DELIMITED,r,t)}var Rr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var yt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(yt||(yt={}));var bo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(bo||(bo={}));(function(r){r.codec=()=>De(bo)})(yt||(yt={}));var Ye;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),yt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=yt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Kt(e,r.codec()),r.decode=(e,n)=>Ht(e,r.codec(),n)})(Ye||(Ye={}));var yo;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),yt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=yt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Kt(e,r.codec()),r.decode=(e,n)=>Ht(e,r.codec(),n)})(yo||(yo={}));var Zu=new Uint32Array([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]),oe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),se=new Uint32Array(64),Eo=class extends Le{constructor(){super(64,32,8,!1),this.A=oe[0]|0,this.B=oe[1]|0,this.C=oe[2]|0,this.D=oe[3]|0,this.E=oe[4]|0,this.F=oe[5]|0,this.G=oe[6]|0,this.H=oe[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)se[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=se[f-15],u=se[f-2],p=Et(d,7)^Et(d,18)^d>>>3,g=Et(u,17)^Et(u,19)^u>>>10;se[f]=g+se[f-7]+p+se[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:h}=this;for(let f=0;f<64;f++){let d=Et(a,6)^Et(a,11)^Et(a,25),u=h+d+Ns(a,c,l)+Zu[f]+se[f]|0,g=(Et(n,2)^Et(n,13)^Et(n,22))+Ps(n,o,s)|0;h=l,l=c,c=a,a=i+u|0,i=s,s=o,o=n,n=u+g|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,l=l+this.G|0,h=h+this.H|0,this.set(n,o,s,i,a,c,l,h)}roundClean(){se.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var hi=hr(()=>new Eo);function et(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Qe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Dr=class extends Be{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ts(t);let n=He(e);if(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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(this),Ae(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){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}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},vo=(r,t,e)=>new Dr(r,t).update(e).digest();vo.create=(r,t)=>new Dr(r,t);function di(r){r.lowS!==void 0&&vt("lowS",r.lowS),r.prehash!==void 0&&vt("prehash",r.prehash)}function $u(r){let t=je(r);Rt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Xu,hexToBytes:Wu}=xr,So=class extends Error{constructor(t=""){super(t)}},jt={Err:So,_tlv:{encode:(r,t)=>{let{Err:e}=jt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ce(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ce(o.length/2|128):"";return ce(r)+s+o+t},decode(r,t){let{Err:e}=jt,n=0;if(r<0||r>256)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 l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let h of l)i=i<<8|h;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=jt;if(r<Zt)throw new t("integer: negative integers are not allowed");let e=ce(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=jt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Xu(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=jt,o=typeof r=="string"?Wu(r):r;Te(o);let{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:l,l:h}=n.decode(2,c);if(h.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=jt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Zt=BigInt(0),ot=BigInt(1),c0=BigInt(2),pi=BigInt(3),u0=BigInt(4);function Yu(r){let t=$u(r),{Fp:e}=t,n=ee(t.n,t.nBitLength),o=t.toBytes||((g,x,w)=>{let b=x.toAffine();return qt(Uint8Array.from([4]),e.toBytes(b.x),e.toBytes(b.y))}),s=t.fromBytes||(g=>{let x=g.subarray(1),w=e.fromBytes(x.subarray(0,e.BYTES)),b=e.fromBytes(x.subarray(e.BYTES,2*e.BYTES));return{x:w,y:b}});function i(g){let{a:x,b:w}=t,b=e.sqr(g),m=e.mul(b,g);return e.add(e.add(m,e.mul(g,x)),w)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(g){return Ke(g,ot,t.n)}function c(g){let{allowedPrivateKeyLengths:x,nByteLength:w,wrapPrivateKey:b,n:m}=t;if(x&&typeof g!="bigint"){if(Qt(g)&&(g=Mt(g)),typeof g!="string"||!x.includes(g.length))throw new Error("invalid private key");g=g.padStart(w*2,"0")}let v;try{v=typeof g=="bigint"?g:zt(Y("private key",g,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof g)}return b&&(v=G(v,m)),pt("private key",v,ot,m),v}function l(g){if(!(g instanceof d))throw new Error("ProjectivePoint expected")}let h=le((g,x)=>{let{px:w,py:b,pz:m}=g;if(e.eql(m,e.ONE))return{x:w,y:b};let v=g.is0();x==null&&(x=v?e.ONE:e.inv(m));let _=e.mul(w,x),I=e.mul(b,x),y=e.mul(m,x);if(v)return{x:e.ZERO,y:e.ZERO};if(!e.eql(y,e.ONE))throw new Error("invZ was invalid");return{x:_,y:I}}),f=le(g=>{if(g.is0()){if(t.allowInfinityPoint&&!e.is0(g.py))return;throw new Error("bad point: ZERO")}let{x,y:w}=g.toAffine();if(!e.isValid(x)||!e.isValid(w))throw new Error("bad point: x or y not FE");let b=e.sqr(w),m=i(x);if(!e.eql(b,m))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(x,w,b){if(this.px=x,this.py=w,this.pz=b,x==null||!e.isValid(x))throw new Error("x required");if(w==null||!e.isValid(w))throw new Error("y required");if(b==null||!e.isValid(b))throw new Error("z required");Object.freeze(this)}static fromAffine(x){let{x:w,y:b}=x||{};if(!x||!e.isValid(w)||!e.isValid(b))throw new Error("invalid affine point");if(x instanceof d)throw new Error("projective point not allowed");let m=v=>e.eql(v,e.ZERO);return m(w)&&m(b)?d.ZERO:new d(w,b,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(x){let w=e.invertBatch(x.map(b=>b.pz));return x.map((b,m)=>b.toAffine(w[m])).map(d.fromAffine)}static fromHex(x){let w=d.fromAffine(s(Y("pointHex",x)));return w.assertValidity(),w}static fromPrivateKey(x){return d.BASE.multiply(c(x))}static msm(x,w){return Er(d,n,x,w)}_setWindowSize(x){p.setWindowSize(this,x)}assertValidity(){f(this)}hasEvenY(){let{y:x}=this.toAffine();if(e.isOdd)return!e.isOdd(x);throw new Error("Field doesn't support isOdd")}equals(x){l(x);let{px:w,py:b,pz:m}=this,{px:v,py:_,pz:I}=x,y=e.eql(e.mul(w,I),e.mul(v,m)),B=e.eql(e.mul(b,I),e.mul(_,m));return y&&B}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:x,b:w}=t,b=e.mul(w,pi),{px:m,py:v,pz:_}=this,I=e.ZERO,y=e.ZERO,B=e.ZERO,T=e.mul(m,m),V=e.mul(v,v),F=e.mul(_,_),O=e.mul(m,v);return O=e.add(O,O),B=e.mul(m,_),B=e.add(B,B),I=e.mul(x,B),y=e.mul(b,F),y=e.add(I,y),I=e.sub(V,y),y=e.add(V,y),y=e.mul(I,y),I=e.mul(O,I),B=e.mul(b,B),F=e.mul(x,F),O=e.sub(T,F),O=e.mul(x,O),O=e.add(O,B),B=e.add(T,T),T=e.add(B,T),T=e.add(T,F),T=e.mul(T,O),y=e.add(y,T),F=e.mul(v,_),F=e.add(F,F),T=e.mul(F,O),I=e.sub(I,T),B=e.mul(F,V),B=e.add(B,B),B=e.add(B,B),new d(I,y,B)}add(x){l(x);let{px:w,py:b,pz:m}=this,{px:v,py:_,pz:I}=x,y=e.ZERO,B=e.ZERO,T=e.ZERO,V=t.a,F=e.mul(t.b,pi),O=e.mul(w,v),N=e.mul(b,_),L=e.mul(m,I),D=e.add(w,b),S=e.add(v,_);D=e.mul(D,S),S=e.add(O,N),D=e.sub(D,S),S=e.add(w,m);let E=e.add(v,I);return S=e.mul(S,E),E=e.add(O,L),S=e.sub(S,E),E=e.add(b,m),y=e.add(_,I),E=e.mul(E,y),y=e.add(N,L),E=e.sub(E,y),T=e.mul(V,S),y=e.mul(F,L),T=e.add(y,T),y=e.sub(N,T),T=e.add(N,T),B=e.mul(y,T),N=e.add(O,O),N=e.add(N,O),L=e.mul(V,L),S=e.mul(F,S),N=e.add(N,L),L=e.sub(O,L),L=e.mul(V,L),S=e.add(S,L),O=e.mul(N,S),B=e.add(B,O),O=e.mul(E,S),y=e.mul(D,y),y=e.sub(y,O),O=e.mul(D,N),T=e.mul(E,T),T=e.add(T,O),new d(y,B,T)}subtract(x){return this.add(x.negate())}is0(){return this.equals(d.ZERO)}wNAF(x){return p.wNAFCached(this,x,d.normalizeZ)}multiplyUnsafe(x){let{endo:w,n:b}=t;pt("scalar",x,Zt,b);let m=d.ZERO;if(x===Zt)return m;if(this.is0()||x===ot)return this;if(!w||p.hasPrecomputes(this))return p.wNAFCachedUnsafe(this,x,d.normalizeZ);let{k1neg:v,k1:_,k2neg:I,k2:y}=w.splitScalar(x),B=m,T=m,V=this;for(;_>Zt||y>Zt;)_&ot&&(B=B.add(V)),y&ot&&(T=T.add(V)),V=V.double(),_>>=ot,y>>=ot;return v&&(B=B.negate()),I&&(T=T.negate()),T=new d(e.mul(T.px,w.beta),T.py,T.pz),B.add(T)}multiply(x){let{endo:w,n:b}=t;pt("scalar",x,ot,b);let m,v;if(w){let{k1neg:_,k1:I,k2neg:y,k2:B}=w.splitScalar(x),{p:T,f:V}=this.wNAF(I),{p:F,f:O}=this.wNAF(B);T=p.constTimeNegate(_,T),F=p.constTimeNegate(y,F),F=new d(e.mul(F.px,w.beta),F.py,F.pz),m=T.add(F),v=V.add(O)}else{let{p:_,f:I}=this.wNAF(x);m=_,v=I}return d.normalizeZ([m,v])[0]}multiplyAndAddUnsafe(x,w,b){let m=d.BASE,v=(I,y)=>y===Zt||y===ot||!I.equals(m)?I.multiplyUnsafe(y):I.multiply(y),_=v(this,w).add(v(x,b));return _.is0()?void 0:_}toAffine(x){return h(this,x)}isTorsionFree(){let{h:x,isTorsionFree:w}=t;if(x===ot)return!0;if(w)return w(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:x,clearCofactor:w}=t;return x===ot?this:w?w(d,this):this.multiplyUnsafe(t.h)}toRawBytes(x=!0){return vt("isCompressed",x),this.assertValidity(),o(d,this,x)}toHex(x=!0){return vt("isCompressed",x),Mt(this.toRawBytes(x))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let u=t.nBitLength,p=yr(d,t.endo?Math.ceil(u/2):u);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function Qu(r){let t=je(r);return Rt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function mi(r){let t=Qu(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(L){return G(L,n)}function a(L){return wr(L,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:l,weierstrassEquation:h,isWithinCurveOrder:f}=Yu({...t,toBytes(L,D,S){let E=D.toAffine(),A=e.toBytes(E.x),R=qt;return vt("isCompressed",S),S?R(Uint8Array.from([D.hasEvenY()?2:3]),A):R(Uint8Array.from([4]),A,e.toBytes(E.y))},fromBytes(L){let D=L.length,S=L[0],E=L.subarray(1);if(D===o&&(S===2||S===3)){let A=zt(E);if(!Ke(A,ot,e.ORDER))throw new Error("Point is not on curve");let R=h(A),P;try{P=e.sqrt(R)}catch(z){let U=z instanceof Error?": "+z.message:"";throw new Error("Point is not on curve"+U)}let k=(P&ot)===ot;return(S&1)===1!==k&&(P=e.neg(P)),{x:A,y:P}}else if(D===s&&S===4){let A=e.fromBytes(E.subarray(0,e.BYTES)),R=e.fromBytes(E.subarray(e.BYTES,2*e.BYTES));return{x:A,y:R}}else{let A=o,R=s;throw new Error("invalid Point, expected length of "+A+", or uncompressed "+R+", got "+D)}}}),d=L=>Mt(te(L,t.nByteLength));function u(L){let D=n>>ot;return L>D}function p(L){return u(L)?i(-L):L}let g=(L,D,S)=>zt(L.slice(D,S));class x{constructor(D,S,E){this.r=D,this.s=S,this.recovery=E,this.assertValidity()}static fromCompact(D){let S=t.nByteLength;return D=Y("compactSignature",D,S*2),new x(g(D,0,S),g(D,S,2*S))}static fromDER(D){let{r:S,s:E}=jt.toSig(Y("DER",D));return new x(S,E)}assertValidity(){pt("r",this.r,ot,n),pt("s",this.s,ot,n)}addRecoveryBit(D){return new x(this.r,this.s,D)}recoverPublicKey(D){let{r:S,s:E,recovery:A}=this,R=I(Y("msgHash",D));if(A==null||![0,1,2,3].includes(A))throw new Error("recovery id invalid");let P=A===2||A===3?S+t.n:S;if(P>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let k=A&1?"03":"02",M=c.fromHex(k+d(P)),z=a(P),U=i(-R*z),H=i(E*z),j=c.BASE.multiplyAndAddUnsafe(M,U,H);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return u(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return ue(this.toDERHex())}toDERHex(){return jt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ue(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let w={isValidPrivateKey(L){try{return l(L),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let L=Cn(t.n);return Vs(t.randomBytes(L),t.n)},precompute(L=8,D=c.BASE){return D._setWindowSize(L),D.multiply(BigInt(3)),D}};function b(L,D=!0){return c.fromPrivateKey(L).toRawBytes(D)}function m(L){let D=Qt(L),S=typeof L=="string",E=(D||S)&&L.length;return D?E===o||E===s:S?E===2*o||E===2*s:L instanceof c}function v(L,D,S=!0){if(m(L))throw new Error("first arg must be private key");if(!m(D))throw new Error("second arg must be public key");return c.fromHex(D).multiply(l(L)).toRawBytes(S)}let _=t.bits2int||function(L){if(L.length>8192)throw new Error("input is too large");let D=zt(L),S=L.length*8-t.nBitLength;return S>0?D>>BigInt(S):D},I=t.bits2int_modN||function(L){return i(_(L))},y=Ge(t.nBitLength);function B(L){return pt("num < 2^"+t.nBitLength,L,Zt,y),te(L,t.nByteLength)}function T(L,D,S=V){if(["recovered","canonical"].some(nt=>nt in S))throw new Error("sign() legacy options not supported");let{hash:E,randomBytes:A}=t,{lowS:R,prehash:P,extraEntropy:k}=S;R==null&&(R=!0),L=Y("msgHash",L),di(S),P&&(L=Y("prehashed msgHash",E(L)));let M=I(L),z=l(D),U=[B(z),B(M)];if(k!=null&&k!==!1){let nt=k===!0?A(e.BYTES):k;U.push(Y("extraEntropy",nt))}let H=qt(...U),j=M;function rt(nt){let st=_(nt);if(!f(st))return;let it=a(st),ht=c.BASE.multiply(st).toAffine(),ft=i(ht.x);if(ft===Zt)return;let Lt=i(it*i(j+ft*z));if(Lt===Zt)return;let Dt=(ht.x===ft?0:2)|Number(ht.y&ot),Ce=Lt;return R&&u(Lt)&&(Ce=p(Lt),Dt^=1),new x(ft,Ce,Dt)}return{seed:H,k2sig:rt}}let V={lowS:t.lowS,prehash:!1},F={lowS:t.lowS,prehash:!1};function O(L,D,S=V){let{seed:E,k2sig:A}=T(L,D,S),R=t;return Nn(R.hash.outputLen,R.nByteLength,R.hmac)(E,A)}c.BASE._setWindowSize(8);function N(L,D,S,E=F){let A=L;D=Y("msgHash",D),S=Y("publicKey",S);let{lowS:R,prehash:P,format:k}=E;if(di(E),"strict"in E)throw new Error("options.strict was renamed to lowS");if(k!==void 0&&k!=="compact"&&k!=="der")throw new Error("format must be compact or der");let M=typeof A=="string"||Qt(A),z=!M&&!k&&typeof A=="object"&&A!==null&&typeof A.r=="bigint"&&typeof A.s=="bigint";if(!M&&!z)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let U,H;try{if(z&&(U=new x(A.r,A.s)),M){try{k!=="compact"&&(U=x.fromDER(A))}catch(Dt){if(!(Dt instanceof jt.Err))throw Dt}!U&&k!=="der"&&(U=x.fromCompact(A))}H=c.fromHex(S)}catch{return!1}if(!U||R&&U.hasHighS())return!1;P&&(D=t.hash(D));let{r:j,s:rt}=U,nt=I(D),st=a(rt),it=i(nt*st),ht=i(j*st),ft=c.BASE.multiplyAndAddUnsafe(H,it,ht)?.toAffine();return ft?i(ft.x)===j:!1}return{CURVE:t,getPublicKey:b,getSharedSecret:v,sign:O,verify:N,ProjectivePoint:c,Signature:x,utils:w}}function Ju(r){return{hash:r,hmac:(t,...e)=>vo(r,t,An(...e)),randomBytes:dr}}function gi(r,t){let e=n=>mi({...r,...Ju(n)});return{...e(t),create:e}}var bi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),xi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),tf=BigInt(1),_o=BigInt(2),wi=(r,t)=>(r+t/_o)/t;function ef(r){let t=bi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,h=l*l*r%t,f=X(h,e,t)*h%t,d=X(f,e,t)*h%t,u=X(d,_o,t)*l%t,p=X(u,o,t)*u%t,g=X(p,s,t)*p%t,x=X(g,a,t)*g%t,w=X(x,c,t)*x%t,b=X(w,a,t)*g%t,m=X(b,e,t)*h%t,v=X(m,i,t)*p%t,_=X(v,n,t)*l%t,I=X(_,_o,t);if(!Ao.eql(Ao.sqr(I),r))throw new Error("Cannot find square root");return I}var Ao=ee(bi,void 0,void 0,{sqrt:ef}),me=gi({a:BigInt(0),b:BigInt(7),Fp:Ao,n:xi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=xi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-tf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=wi(s*r,t),c=wi(-n*r,t),l=G(r-a*e-c*o,t),h=G(-a*n-c*s,t),f=l>i,d=h>i;if(f&&(l=t-l),d&&(h=t-h),l>i||h>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:d,k2:h}}}},hi),w0=BigInt(0);var b0=me.ProjectivePoint;function bt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=gt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function yi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Ei(r,t,e){let n=Ze.digest(e instanceof Uint8Array?e:e.subarray());if(yi(n))return n.then(({digest:o})=>me.verify(t,o,r)).catch(o=>{throw new Qe(String(o))});try{return me.verify(t,n.digest,r)}catch(o){throw new Qe(String(o))}}var Nr=class{type="secp256k1";raw;_key;constructor(t){this._key=Si(t),this.raw=vi(this._key)}toMultihash(){return Ot.digest(Ar(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return Ei(this._key,e,t)}};function _i(r){return new Nr(r)}function vi(r){return me.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Si(r){try{return me.ProjectivePoint.fromHex(r),r}catch(t){throw new ar(String(t))}}function Ai(r){let{Type:t,Data:e}=Ye.decode(r.digest),n=e??new Uint8Array;switch(t){case yt.Ed25519:return Qs(n);case yt.secp256k1:return _i(n);default:throw new Fe}}function Ar(r){return Ye.encode({Type:yt[r.type],Data:r.raw})}var Ii=Symbol.for("nodejs.util.inspect.custom"),rf=114,Je=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()})`}[pn]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return lt.createV1(rf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ii](){return`PeerId(${this.toString()})`}},Pr=class extends Je{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},kr=class extends Je{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Ur=class extends Je{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},nf=2336,Cr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ot.digest(tt(this.url))}[Ii](){return`PeerId(${this.url})`}[pn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return lt.createV1(nf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};function Or(r){if(sf(r))return new Pr({multihash:r});if(of(r))try{let t=Ai(r);if(t.type==="Ed25519")return new kr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Ur({multihash:r,publicKey:t})}catch{let e=et(r.digest);return new Cr(new URL(e))}throw new cr("Supplied PeerID Multihash is invalid")}function of(r){return r.code===Ot.code}function sf(r){return r.code===Ze.code}function Io(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 Fr(r){let t=Ut(W.decode(`z${r}`));return Or(t)}var Mr=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 Io(this.set.entries(),t=>{let e=Fr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Fr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Io(this.set.values(),t=>Fr(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 Bo(){return new Mr}var Di=Symbol.for("@achingbrain/uint8arraylist");function Ri(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 qr(r){return!!r?.[Di]}var $t=class r{bufs;length;[Di]=!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(qr(n))e+=n.byteLength,this.bufs.push(...n.bufs);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(qr(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=Ri(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ri(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(qr(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 bt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:bt(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 l=t>=a&&t<c,h=e>a&&e<=c;if(l&&h){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(h){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(!qr(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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,h;for(let f=e;f<=c;f+=h){h=0;for(let d=l;d>=0;d--){let u=this.get(f+d);if(n[d]!==u){h=Math.max(1,d-a[u]);break}}if(h===0)return f}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=gt(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=_t(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=_t(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=_t(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=gt(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=_t(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=_t(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=_t(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=_t(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=_t(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(!xt(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 Lo=64,It=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Lo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=_t(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?xt(this.fp,t.fp):!1}};function ge(r,t){return Math.floor(Math.random()*(t-r))+r}var xe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof It))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 It))throw new TypeError("Invalid Fingerprint");let e=ge(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var To={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ni={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Pi=new globalThis.TextEncoder;function af(r,t){let e=To[t],n=Ni[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function cf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=To[t],o=Ni[t],s=r;for(;s.length>0;){let i=Pi.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 Ro(r,{size:t=32,utf8Buffer:e}={}){if(!To[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 cf(r,t,e);r=Pi.encode(r)}return af(r,t)}var uf=fs(Ti(),1);var er={hash:r=>Number(Ro(r,{size:32})),hashV:(r,t)=>ff(er.hash(r,t))};function ff(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),tt(t,"base16")}var lf=500,rr=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??er,this.seed=t.seed??ge(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=tt(t));let e=new It(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new xe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new xe(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[ge(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize));for(let a=0;a<lf;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=tt(t));let e=new It(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=tt(t));let e=new It(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}},hf={1:.5,2:.84,4:.95,8:.98};function df(r=.001){return r>.002?2:r>1e-5?4:8}function ki(r,t=.001){let e=df(t),n=hf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Lo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Vr=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??er,this.seed=t.seed??ge(0,Math.pow(2,10)),this.filterSeries=[new rr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=tt(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 rr({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=tt(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=tt(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 Do(r,t=.001,e){return new Vr({...ki(r,t),...e??{}})}var Hr=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",l=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let d=Number.parseInt(f,t);if(!Number.isNaN(d))return d});if(h===void 0)break;if(s*=t,s+=h,s>l||(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 Ui=45,pf=15,Ne=new Hr;function Kr(r){if(!(r.length>pf))return Ne.new(r).parseWith(()=>Ne.readIPv4Addr())}function Gr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ui))return Ne.new(r).parseWith(()=>Ne.readIPv6Addr())}function we(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Ui)return;let e=Ne.new(r).parseWith(()=>Ne.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 Ci(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 Oi(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 No(r){switch(r.length){case be:return r.join(".");case ye:{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 Fi(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;n&128;)t++,n=n<<1;if(n&128)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function Mi(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var be=4,ye=16,pm=parseInt("0xFFFF",16),mf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function nr(r,t){t.length===ye&&r.length===be&&Ci(t,0,11)&&(t=t.slice(12)),t.length===be&&r.length===ye&&Oi(r,mf,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 zi(r,t){if(typeof t=="string"&&(t=we(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Po(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=be,o=Kr(t);if(o==null&&(n=ye,o=Gr(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=ko(s,8*n);return{network:nr(o,i),mask:i}}function ko(r,t){if(t!==8*be&&t!==8*ye)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 Pe=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Po(t));else{let n=we(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=we(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ko(o,8*n.length);this.network=nr(n,this.mask)}}contains(t){return zi({network:this.network,mask:this.mask},t)}toString(){let t=Fi(this.mask),e=t!==-1?String(t):Mi(this.mask);return No(this.network)+"/"+e}};function qi(r,t){return new Pe(r).contains(t)}var gf=41;function Vi(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===gf)return qi("2000::/3",e)}catch{}return!1}function jr(r){return!!Kr(r)}function Zr(r){return!!Gr(r)}function $r(r){return!!we(r)}var Ki=fs(Hi(),1),xf=["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"],wf=xf.map(r=>new Ki.Netmask(r));function Uo(r){for(let t of wf)if(t.contains(r))return!0;return!1}function bf(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function yf(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 Uo(o)}function Ef(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function vf(r){let t=r.split(":"),e=t[t.length-1];return Uo(e)}function Sf(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 Gi(r){return jr(r)?Uo(r):bf(r)?yf(r):Ef(r)?vf(r):Zr(r)?Sf(r):void 0}var _f=4,Af=41,If=53,Bf=54,Lf=55,Tf=56;function Co(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!0;if(t===If||t===Bf||t===Lf||t===Tf)return!1;if(t===_f||t===Af)return Gi(e)??!1}catch{}return!0}function Bt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Xr=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)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}},ke=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Xr(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 Xr(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 Oo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ji(r={}){return Rf(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 Rf(r,t){t=t??{};let e=t.onEnd,n=new ke,o,s,i,a=Bt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,w)=>{s=b=>{s=null,n.push(b);try{x(r(n))}catch(m){w(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Bt()})}},l=x=>s!=null?s(x):(n.push(x),o),h=x=>(n=new ke,s!=null?s({error:x}):(n.push({error:x}),o)),f=x=>{if(i)return o;if(t?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:x})},d=x=>i?o:(i=!0,x!=null?h(x):l({done:!0})),u=()=>(n=new ke,d(),{done:!0}),p=x=>(d(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:u,throw:p,push:f,end:d,get readableLength(){return n.size},onEmpty:async x=>{let w=x?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let b,m;w!=null&&(b=new Promise((v,_)=>{m=()=>{_(new Oo)},w.addEventListener("abort",m)}));try{await Promise.race([a.promise,b])}finally{m!=null&&w!=null&&w?.removeEventListener("abort",m)}}},e==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(x){return g.throw(x),e!=null&&(e(x),e=void 0),{done:!0}},return(){return g.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(x){return g.end(x),e!=null&&(e(x),e=void 0),o},get readableLength(){return g.readableLength},onEmpty:x=>g.onEmpty(x)},o}var Fo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function Wr(r,t,e,n){let o=new Fo(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",h),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,l)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(d){a(),i(d);return}a(),s(f)},l=f=>{a(),i(f.detail)},h=()=>{a(),i(o)};e?.addEventListener("abort",h),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,l)})}var Yr=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Qr=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Jr(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Qr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Qr(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var tn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Bt(),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 Df(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var en=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=Df(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,Tt(1/0,this.controller.signal),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 tn(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Jr(this.fn({...this.options??{},signal:this.controller.signal}),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 rn=class extends ur{concurrency;maxSize;queue;pending;sort;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,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=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!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 Yr;let n=new en(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("error",{detail:o}),this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),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 Wr(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await Wr(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Wr(this,"idle",t?.signal)}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=ji({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)},i=()=>{n()},a=()=>{n(new Nt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var nn=class extends rn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function on(r){let t=new globalThis.AbortController;function e(){t.abort();for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}function Zi(r,t,e){let n,o;function s(){let a={signal:o.signal};if(e?.timeout!=null){let c=on([o.signal,AbortSignal.timeout(e.timeout)]);Tt(1/0,c),a.signal=c}Promise.resolve().then(async()=>{await r(a)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{start:()=>{i||(i=!0,o=new AbortController,Tt(1/0,o.signal),e?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),i=!1}}}var $i=jr,Nf=Zr,Mo=function(r){let t=0;if(r=r.toString().trim(),$i(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Nf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=$i(e[n]),i;s&&(i=Mo(e[n]),e[n]=et(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,et(i.slice(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++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},Xi=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ue={},zo={},kf=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];kf.forEach(r=>{let t=Uf(...r);zo[t.code]=t,Ue[t.name]=t});function Uf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function K(r){if(typeof r=="number"){if(zo[r]!=null)return zo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ue[r]!=null)return Ue[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Bg=K("ip4"),Lg=K("ip6"),Tg=K("ipcidr");function Ko(r,t){switch(K(r).code){case 4:case 41:return Of(t);case 42:return Ho(t);case 43:return et(t,"base10");case 6:case 273:case 33:case 132:return Qi(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ho(t);case 421:return qf(t);case 444:return Yi(t);case 445:return Yi(t);case 466:return zf(t);case 481:return globalThis.encodeURIComponent(Ho(t));default:return et(t,"base16")}}function Go(r,t){switch(K(r).code){case 4:return Wi(t);case 41:return Wi(t);case 42:return Vo(t);case 43:return tt(t,"base10");case 6:case 273:case 33:case 132:return jo(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Vo(t);case 421:return Ff(t);case 444:return Vf(t);case 445:return Hf(t);case 466:return Mf(t);case 481:return Vo(globalThis.decodeURIComponent(t));default:return tt(t,"base16")}}var qo=Object.values($e).map(r=>r.decoder),Cf=function(){let r=qo[0].or(qo[1]);return qo.slice(2).forEach(t=>r=r.or(t)),r}();function Wi(r){if(!$r(r))throw new Error("invalid ip address");return Mo(r)}function Of(r){let t=Xi(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!$r(t))throw new Error("invalid ip address");return t}function jo(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Qi(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Vo(r){let t=tt(r),e=Uint8Array.from(re(t.length));return bt([e,t],e.length+t.length)}function Ho(r){let t=Vt(r);if(r=r.slice(ct(t)),r.length!==t)throw new Error("inconsistent lengths");return et(r)}function Ff(r){let t;r[0]==="Q"||r[0]==="1"?t=Ut(W.decode(`z${r}`)).bytes:t=lt.parse(r).multihash.bytes;let e=Uint8Array.from(re(t.length));return bt([e,t],e.length+t.length)}function Mf(r){let t=Cf.decode(r),e=Uint8Array.from(re(t.length));return bt([e,t],e.length+t.length)}function zf(r){let t=Vt(r),e=r.slice(ct(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+et(e,"base64url")}function qf(r){let t=Vt(r),e=r.slice(ct(t));if(e.length!==t)throw new Error("inconsistent lengths");return et(e,"base58btc")}function Vf(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=kt.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=jo(n);return bt([e,o],e.length+o.length)}function Hf(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=kt.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=jo(n);return bt([e,o],e.length+o.length)}function Yi(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=et(t,"base32"),o=Qi(e);return`${n}:${o}`}function Ji(r){r=Zo(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=K(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw ea("invalid address: "+r);if(a.path===!0){n=Zo(o.slice(s).join("/")),t.push([a.code,Go(a.code,n)]),e.push([a.code,n]);break}let c=Go(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Ko(a.code,c)])}return{string:ta(e),bytes:Xo(t),tuples:t,stringTuples:e,path:n}}function $o(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Vt(r,o),i=ct(s),a=K(s),c=Kf(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let l=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw ea("Invalid address Uint8Array: "+et(r,"base16"));t.push([s,l]);let h=Ko(s,l);if(e.push([s,h]),a.path===!0){n=h;break}}return{bytes:Uint8Array.from(r),string:ta(e),tuples:t,stringTuples:e,path:n}}function ta(r){let t=[];return r.map(e=>{let n=K(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Zo(t.join("/"))}function Xo(r){return bt(r.map(t=>{let e=K(t[0]),n=Uint8Array.from(re(e.code));return t.length>1&&t[1]!=null&&(n=bt([n,t[1]])),n}))}function Kf(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Vt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ct(e)}}function Zo(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function ea(r){return new Error("Error parsing address: "+r)}var Gf=Symbol.for("nodejs.util.inspect.custom"),Yo=Symbol.for("@multiformats/js-multiaddr/multiaddr"),jf=[K("dns").code,K("dns4").code,K("dns6").code,K("dnsaddr").code],Wo=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},sn=class r{bytes;#t;#e;#r;#n;[Yo]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=$o(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Ji(t)}else if(na(t))e=$o(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=K("tcp"),a=K("udp"),c=K("ip4"),l=K("ip6"),h=K("dns6"),f=K("ip6zone");for(let[u,p]of this.stringTuples())u===f.code&&(s=`%${p??""}`),jf.includes(u)&&(e=i.name,o=443,n=`${p??""}${s}`,t=u===h.code?6:4),(u===i.code||u===a.code)&&(e=K(u).name,o=parseInt(p??"")),(u===c.code||u===l.code)&&(e=K(u).name,n=`${p??""}${s}`,t=u===l.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#e.map(([t])=>Object.assign({},K(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>K(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(Xo(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ue.p2p.code&&t.push([n,o]),n===Ue["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?et(W.decode(`z${n}`),"base58btc"):et(lt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return xt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=ra.get(e.name);if(n==null)throw new Wo(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>sr(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Gf](){return`Multiaddr(${this.#t})`}};var ra=new Map;function na(r){return!!r?.[Yo]}function sr(r){return new sn(r)}var Qo=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Bt(),this.haveNext=Bt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Bt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Bt(),await Jr(this.readNext.promise,e?.signal,e)}};function oa(){return new Qo}var an=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Jo=class extends Error{code;constructor(t,e){super(t),this.code=e}},ts=class extends Jo{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function sa(r,t){let e=oa();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new $t;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((h,f)=>{c=()=>{f(new ts("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:d}=await Promise.race([n.next(),l]);return f===!0?new $t:d}for(;o.byteLength<i;){let{value:f,done:d}=await Promise.race([n.next(),l]);if(d===!0)throw new an("unexpected end of input");o.append(f)}let h=o.sublist(0,i);return o.consume(i),h}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var cn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},un=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},fn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ia(r,t={}){let e=sa(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=ct(t.maxDataLength));let n=t?.lengthDecoder??Vt,o=t?.lengthEncoder??re;return{read:async i=>{let a=-1,c=new $t;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new cn("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new fn("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new un("message length too long");return e.read(a,i)},write:async(i,a)=>{await e.write(new $t(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new $t(...i.flatMap(l=>[o(l.byteLength),l]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function es(r,t){let e=ia(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 aa="libp2p",ca="autonat",ua="1.0.0";var Z;(function(r){let t;(function(l){l.DIAL="DIAL",l.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(l){l[l.DIAL=0]="DIAL",l[l.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(l){l.codec=()=>De(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(l){l.OK="OK",l.E_DIAL_ERROR="E_DIAL_ERROR",l.E_DIAL_REFUSED="E_DIAL_REFUSED",l.E_BAD_REQUEST="E_BAD_REQUEST",l.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(l){l[l.OK=0]="OK",l[l.E_DIAL_ERROR=100]="E_DIAL_ERROR",l[l.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",l[l.E_BAD_REQUEST=200]="E_BAD_REQUEST",l[l.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(l){l.codec=()=>De(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(l){let h;l.codec=()=>(h==null&&(h=Gt((f,d,u={})=>{if(u.lengthDelimited!==!1&&d.fork(),f.id!=null&&(d.uint32(10),d.bytes(f.id)),f.addrs!=null)for(let p of f.addrs)d.uint32(18),d.bytes(p);u.lengthDelimited!==!1&&d.ldelim()},(f,d,u={})=>{let p={addrs:[]},g=d==null?f.len:f.pos+d;for(;f.pos<g;){let x=f.uint32();switch(x>>>3){case 1:{p.id=f.bytes();break}case 2:{if(u.limits?.addrs!=null&&p.addrs.length===u.limits.addrs)throw new Rr('Decode error - map field "addrs" had too many elements');p.addrs.push(f.bytes());break}default:{f.skipType(x&7);break}}}return p})),h),l.encode=f=>Kt(f,l.codec()),l.decode=(f,d)=>Ht(f,l.codec(),d)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(l){let h;l.codec=()=>(h==null&&(h=Gt((f,d,u={})=>{u.lengthDelimited!==!1&&d.fork(),f.peer!=null&&(d.uint32(10),r.PeerInfo.codec().encode(f.peer,d)),u.lengthDelimited!==!1&&d.ldelim()},(f,d,u={})=>{let p={},g=d==null?f.len:f.pos+d;for(;f.pos<g;){let x=f.uint32();switch(x>>>3){case 1:{p.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:u.limits?.peer});break}default:{f.skipType(x&7);break}}}return p})),h),l.encode=f=>Kt(f,l.codec()),l.decode=(f,d)=>Ht(f,l.codec(),d)})(i=r.Dial||(r.Dial={}));let a;(function(l){let h;l.codec=()=>(h==null&&(h=Gt((f,d,u={})=>{u.lengthDelimited!==!1&&d.fork(),f.status!=null&&(d.uint32(8),r.ResponseStatus.codec().encode(f.status,d)),f.statusText!=null&&(d.uint32(18),d.string(f.statusText)),f.addr!=null&&(d.uint32(26),d.bytes(f.addr)),u.lengthDelimited!==!1&&d.ldelim()},(f,d,u={})=>{let p={},g=d==null?f.len:f.pos+d;for(;f.pos<g;){let x=f.uint32();switch(x>>>3){case 1:{p.status=r.ResponseStatus.codec().decode(f);break}case 2:{p.statusText=f.string();break}case 3:{p.addr=f.bytes();break}default:{f.skipType(x&7);break}}}return p})),h),l.encode=f=>Kt(f,l.codec()),l.decode=(f,d)=>Ht(f,l.codec(),d)})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=Gt((l,h,f={})=>{f.lengthDelimited!==!1&&h.fork(),l.type!=null&&(h.uint32(8),r.MessageType.codec().encode(l.type,h)),l.dial!=null&&(h.uint32(18),r.Dial.codec().encode(l.dial,h)),l.dialResponse!=null&&(h.uint32(26),r.DialResponse.codec().encode(l.dialResponse,h)),f.lengthDelimited!==!1&&h.ldelim()},(l,h,f={})=>{let d={},u=h==null?l.len:l.pos+h;for(;l.pos<u;){let p=l.uint32();switch(p>>>3){case 1:{d.type=r.MessageType.codec().decode(l);break}case 2:{d.dial=r.Dial.codec().decode(l,l.uint32(),{limits:f.limits?.dial});break}case 3:{d.dialResponse=r.DialResponse.codec().decode(l,l.uint32(),{limits:f.limits?.dialResponse});break}default:{l.skipType(p&7);break}}}return d})),c),r.encode=l=>Kt(l,r.codec()),r.decode=(l,h)=>Ht(l,r.codec(),h)})(Z||(Z={}));var Qf=4,Jf=8,ln=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??aa}/${ca}/${ua}`,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=new Map,this.findPeers=Zi(this.findRandomPeers.bind(this),6e4),this.addressFilter=Do(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ls]=["@libp2p/autonat"];get[hs](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream - %e",e)})},{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=on([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){let e=AbortSignal.timeout(this.timeout);Tt(1/0,e);let n=es(t.stream,{maxDataLength:this.maxMessageSize}).pb(Z);try{let o=await n.read({signal:e}),s=await this.handleAutonatMessage(o,t.connection,{signal:e});await n.write(s,{signal:e}),await n.unwrap().unwrap().close({signal:e})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.stream.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(f=>f.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.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:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Ut(a.id);i=Or(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.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:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(f=>sr(f)).filter(f=>{let d=f.toOptions();return Co(f)?!1:d.host!==e.remoteAddr.toOptions().host?(this.log.trace("not dialing %a - target host did not match remote host %a",f,e.remoteAddr),!1):o.includes(d.host)?!1:this.components.transportManager.dialTransportForMultiaddr(f)==null?(this.log.trace("not dialing %a - transport unsupported",f),!1):!0}).map(f=>(f.getPeerId()==null&&(f=f.encapsulate(`/p2p/${i.toString()}`)),f));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(f=>f.toString()).join(", "),i);let l="",h=c[0];for await(let f of c){let d;h=f;try{if(d=await this.components.connectionManager.openConnection(f,n),!d.remoteAddr.equals(f))throw this.log.error("tried to dial %a but dialed %a",f,d.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,f),{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.OK,addr:d.remoteAddr.decapsulateCode(K("p2p").code).bytes}}}catch(u){this.log.error("could not dial %p - %e",i,u),l=u.message}finally{d!=null&&await d.close()}}return{type:Z.MessageType.DIAL_RESPONSE,dialResponse:{status:Z.ResponseStatus.E_DIAL_ERROR,statusText:l,addr:h.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())||o.multiaddr.toOptions().family===6&&(!e||!Vi(o.multiaddr))||Co(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:Bo(),queue:new nn({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})=>i.toOptions().family===6),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);Tt(1/0,s),this.log.trace("asking %p to verify multiaddr %s",t.remotePeer,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=es(i).pb(Z),[,c]=await Promise.all([a.write({type:Z.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==Z.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let l=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,l),l!==Z.ResponseStatus.OK&&l!==Z.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),l===Z.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else l===Z.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Qf&&this.confirmAddress(o),o.failure===Jf&&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=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};function tl(r={}){return t=>new ln(t,r)}return Sa(el);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/autonat",
|
|
3
|
-
"version": "2.0.16-
|
|
3
|
+
"version": "2.0.16-e2ec7bdaa",
|
|
4
4
|
"description": "Implementation of Autonat Protocol",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-autonat#readme",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"doc-check": "aegir doc-check"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@libp2p/interface": "2.4.0-
|
|
56
|
-
"@libp2p/interface-internal": "2.2.2-
|
|
57
|
-
"@libp2p/peer-collections": "6.0.14-
|
|
58
|
-
"@libp2p/peer-id": "5.0.10-
|
|
59
|
-
"@libp2p/utils": "6.3.1-
|
|
55
|
+
"@libp2p/interface": "2.4.0-e2ec7bdaa",
|
|
56
|
+
"@libp2p/interface-internal": "2.2.2-e2ec7bdaa",
|
|
57
|
+
"@libp2p/peer-collections": "6.0.14-e2ec7bdaa",
|
|
58
|
+
"@libp2p/peer-id": "5.0.10-e2ec7bdaa",
|
|
59
|
+
"@libp2p/utils": "6.3.1-e2ec7bdaa",
|
|
60
60
|
"@multiformats/multiaddr": "^12.3.3",
|
|
61
61
|
"any-signal": "^4.1.1",
|
|
62
62
|
"it-protobuf-stream": "^1.1.5",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"uint8arraylist": "^2.4.8"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@libp2p/crypto": "5.0.9-
|
|
69
|
-
"@libp2p/logger": "5.1.6-
|
|
68
|
+
"@libp2p/crypto": "5.0.9-e2ec7bdaa",
|
|
69
|
+
"@libp2p/logger": "5.1.6-e2ec7bdaa",
|
|
70
70
|
"aegir": "^45.0.5",
|
|
71
71
|
"it-all": "^3.0.6",
|
|
72
72
|
"it-drain": "^3.0.7",
|