@libp2p/autonat-v2 1.0.0 → 1.0.1-a02cb0461
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/client.d.ts +2 -2
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +9 -15
- package/dist/src/client.js.map +1 -1
- package/dist/src/server.d.ts +2 -2
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +60 -71
- package/dist/src/server.js.map +1 -1
- package/package.json +16 -17
- package/src/client.ts +11 -18
- package/src/server.ts +71 -80
- package/dist/typedoc-urls.json +0 -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.Libp2PAutonatV2 = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PAutonatV2=(()=>{var wc=Object.create;var Tr=Object.defineProperty;var Ec=Object.getOwnPropertyDescriptor;var Sc=Object.getOwnPropertyNames;var _c=Object.getPrototypeOf,vc=Object.prototype.hasOwnProperty;var Ac=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)Tr(r,e,{get:t[e],enumerable:!0})},Ns=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sc(t))!vc.call(r,o)&&o!==e&&Tr(r,o,{get:()=>t[o],enumerable:!(n=Ec(t,o))||n.enumerable});return r};var Ic=(r,t,e)=>(e=r!=null?wc(_c(r)):{},Ns(t||!r||!r.__esModule?Tr(e,"default",{value:r,enumerable:!0}):e,r)),Bc=r=>Ns(Tr({},"__esModule",{value:!0}),r);var ec=Ac(Br=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,f,l,h;return u=(c&255<<24)>>>24,f=(c&255<<16)>>>16,l=(c&65280)>>>8,h=c&255,[u,f,l,h].join(".")},i=function(c){var u,f,l,h,m,x;for(u=[],l=h=0;h<=3&&c.length!==0;l=++h){if(l>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}x=t(c),m=x[0],f=x[1],c=c.substring(f),u.push(m)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[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 u,f,l,h,m;for(h=0,u=10,f="9",l=0,c.length>1&&c[l]==="0"&&(c[l+1]==="x"||c[l+1]==="X"?(l+=2,u=16):"0"<=c[l+1]&&c[l+1]<="9"&&(l++,u=8,f="7")),m=l;l<c.length;){if("0"<=c[l]&&c[l]<=f)h=h*u+(e(c[l])-n)>>>0;else if(u===16)if("a"<=c[l]&&c[l]<="f")h=h*u+(10+e(c[l])-s)>>>0;else if("A"<=c[l]&&c[l]<="F")h=h*u+(10+e(c[l])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");l++}if(l===m)throw new Error("empty octet");return[h,l]},r=function(){function c(u,f){var l,h,m,x;if(typeof u!="string")throw new Error("Missing `net' parameter");if(f||(x=u.split("/",2),u=x[0],f=x[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(w){throw l=w,new Error("Invalid mask: "+f)}for(h=m=32;m>=0;h=--m)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(f||f===0)this.bitmask=parseInt(f,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(u)&this.maskLong)>>>0}catch(w){throw l=w,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+f);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(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var f,l,h;for(h=i(this.first),l=i(this.last),f=0;h<=l;)u(a(h),h,f),f++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),Br.ip2long=i,Br.long2ip=a,Br.Netmask=r}).call(Br)});var fd={};dt(fd,{autoNATv2:()=>ud});var $n=Symbol.for("@libp2p/peer-id");var Rt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Lt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Pr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Rr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var bt=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var je=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Lr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){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))}};function Us(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Ms(...r){let t=[];for(let e of r)Us(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(t.map(async e=>{await e.start()})),await Promise.all(t.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function Ks(...r){let t=[];for(let e of r)Us(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(t.map(async e=>{await e.stop()})),await Promise.all(t.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var Or=Symbol.for("@libp2p/service-capabilities"),kr=Symbol.for("@libp2p/service-dependencies");var Yn={};dt(Yn,{base58btc:()=>H,base58flickr:()=>Oc});var Ud=new Uint8Array(0);function zs(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 Ot(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 Fs(r){return new TextEncoder().encode(r)}function qs(r){return new TextDecoder().decode(r)}function Dc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var w=0,p=0,_=0,D=x.length;_!==D&&x[_]===0;)_++,w++;for(var v=(D-_)*f+1>>>0,R=new Uint8Array(v);_!==D;){for(var y=x[_],P=0,T=v-1;(y!==0||P<p)&&T!==-1;T--,P++)y+=256*R[T]>>>0,R[T]=y%a>>>0,y=y/a>>>0;if(y!==0)throw new Error("Non-zero carry");p=P,_++}for(var I=v-p;I!==v&&R[I]===0;)I++;for(var d=c.repeat(w);I<v;++I)d+=r.charAt(R[I]);return d}function h(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var w=0;if(x[w]!==" "){for(var p=0,_=0;x[w]===c;)p++,w++;for(var D=(x.length-w)*u+1>>>0,v=new Uint8Array(D);x[w];){var R=e[x.charCodeAt(w)];if(R===255)return;for(var y=0,P=D-1;(R!==0||y<_)&&P!==-1;P--,y++)R+=a*v[P]>>>0,v[P]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");_=y,w++}if(x[w]!==" "){for(var T=D-_;T!==D&&v[T]===0;)T++;for(var I=new Uint8Array(p+(D-T)),d=p;T!==D;)I[d++]=v[T++];return I}}}function m(x){var w=h(x);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:h,decode:m}}var Cc=Dc,Tc=Cc,Vs=Tc;var Zn=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")}},jn=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 Gs(this,t)}},Wn=class{decoders;constructor(t){this.decoders=t}or(t){return Gs(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 Gs(r,t){return new Wn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Xn=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 Zn(t,e,n),this.decoder=new jn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function we({name:r,prefix:t,encode:e,decode:n}){return new Xn(r,t,e,n)}function Ht({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Vs(e,r);return we({prefix:t,name:r,encode:n,decode:s=>Ot(o(s))})}function Pc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Rc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Lc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function G({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Lc(n);return we({prefix:t,name:r,encode(s){return Rc(s,n,e)},decode(s){return Pc(s,o,e,r)}})}var H=Ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Oc=Ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Qn={};dt(Qn,{base32:()=>Vt,base32hex:()=>Mc,base32hexpad:()=>zc,base32hexpadupper:()=>Fc,base32hexupper:()=>Kc,base32pad:()=>Nc,base32padupper:()=>Uc,base32upper:()=>kc,base32z:()=>qc});var Vt=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),kc=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Nc=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Uc=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Mc=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Kc=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),zc=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Fc=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),qc=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jn={};dt(Jn,{base36:()=>We,base36upper:()=>Hc});var We=Ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Hc=Ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Vc=js,$s=128,Gc=127,$c=~Gc,Zc=Math.pow(2,31);function js(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Zc;)t[e++]=r&255|$s,r/=128;for(;r&$c;)t[e++]=r&255|$s,r>>>=7;return t[e]=r|0,js.bytes=e-n+1,t}var jc=to,Wc=128,Zs=127;function to(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw to.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Zs)<<o:(i&Zs)*Math.pow(2,o),o+=7}while(i>=Wc);return to.bytes=s-n,e}var Xc=Math.pow(2,7),Yc=Math.pow(2,14),Qc=Math.pow(2,21),Jc=Math.pow(2,28),tu=Math.pow(2,35),eu=Math.pow(2,42),ru=Math.pow(2,49),nu=Math.pow(2,56),ou=Math.pow(2,63),su=function(r){return r<Xc?1:r<Yc?2:r<Qc?3:r<Jc?4:r<tu?5:r<eu?6:r<ru?7:r<nu?8:r<ou?9:10},iu={encode:Vc,decode:jc,encodingLength:su},au=iu,Xe=au;function Ye(r,t=0){return[Xe.decode(r,t),Xe.decode.bytes]}function Ee(r,t,e=0){return Xe.encode(r,t,e),t}function Se(r){return Xe.encodingLength(r)}function te(r,t){let e=t.byteLength,n=Se(r),o=n+Se(e),s=new Uint8Array(o+e);return Ee(r,s,0),Ee(e,s,n),s.set(t,o),new _e(r,e,t,s)}function Qe(r){let t=Ot(r),[e,n]=Ye(t),[o,s]=Ye(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 Ws(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&zs(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 Xs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return uu(e,eo(r),t??H.encoder);default:return fu(e,eo(r),t??Vt.encoder)}}var Ys=new WeakMap;function eo(r){let t=Ys.get(r);if(t==null){let e=new Map;return Ys.set(r,e),e}return t}var X=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!==Je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==lu)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=te(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&&Ws(t.multihash,n.multihash)}toString(t){return Xs(this,t)}toJSON(){return{"/":Xs(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??Qs(n,o,s.bytes))}else if(e[du]===!0){let{version:n,multihash:o,code:s}=e,i=Qe(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!==Je)throw new Error(`Version 0 CID must use dag-pb (code: ${Je}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Qs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Je,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=Ot(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[l,h]=Ye(t.subarray(e));return e+=h,l},o=n(),s=Je;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,e){let[n,o]=cu(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return eo(s).set(n,t),s}};function cu(r,t){switch(r[0]){case"Q":{let e=t??H;return[H.prefix,e.decode(`${H.prefix}${r}`)]}case H.prefix:{let e=t??H;return[H.prefix,e.decode(r)]}case Vt.prefix:{let e=t??Vt;return[Vt.prefix,e.decode(r)]}case We.prefix:{let e=t??We;return[We.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 uu(r,t,e){let{prefix:n}=e;if(n!==H.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 fu(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 Je=112,lu=18;function Qs(r,t,e){let n=Se(r),o=n+Se(t),s=new Uint8Array(o+e.byteLength);return Ee(r,s,0),Ee(t,s,n),s.set(e,o),s}var du=Symbol.for("@ipld/js-cid/CID");var ro={};dt(ro,{identity:()=>St});var Js=0,hu="identity",ti=Ot;function pu(r){return te(Js,ti(r))}var St={code:Js,name:hu,encode:ti,digest:pu};function at(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function ht(r=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function kt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ri=Symbol.for("@achingbrain/uint8arraylist");function ei(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 Ur(r){return!!r?.[ri]}var j=class r{bufs;length;[ri]=!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(Ur(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(Ur(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=ei(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ei(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(Ur(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 kt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:kt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=e>a&&e<=c;if(u&&f){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ur(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=e;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let m=this.get(l+h);if(n[h]!==m){f=Math.max(1,h-a[m]);break}}if(f===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!at(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 no={};dt(no,{base10:()=>mu});var mu=Ht({prefix:"9",name:"base10",alphabet:"0123456789"});var oo={};dt(oo,{base16:()=>gu,base16upper:()=>yu});var gu=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yu=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var so={};dt(so,{base2:()=>bu});var bu=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var io={};dt(io,{base256emoji:()=>_u});var ni=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}"),xu=ni.reduce((r,t,e)=>(r[e]=t,r),[]),wu=ni.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Eu(r){return r.reduce((t,e)=>(t+=xu[e],t),"")}function Su(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=wu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var _u=we({prefix:"\u{1F680}",name:"base256emoji",encode:Eu,decode:Su});var co={};dt(co,{base64:()=>vu,base64pad:()=>Au,base64url:()=>ao,base64urlpad:()=>Iu});var vu=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Au=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ao=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Iu=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var uo={};dt(uo,{base8:()=>Bu});var Bu=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var fo={};dt(fo,{identity:()=>Du});var Du=we({prefix:"\0",name:"identity",encode:r=>qs(r),decode:r=>Fs(r)});var wh=new TextEncoder,Eh=new TextDecoder;var po={};dt(po,{sha256:()=>tr,sha512:()=>Pu});function ho({name:r,code:t,encode:e}){return new lo(r,t,e)}var lo=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?te(this.code,e):e.then(n=>te(this.code,n))}else throw Error("Unknown type, must be binary type")}};function si(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var tr=ho({name:"sha2-256",code:18,encode:si("SHA-256")}),Pu=ho({name:"sha2-512",code:19,encode:si("SHA-512")});var er={...fo,...so,...uo,...no,...oo,...Qn,...Jn,...Yn,...co,...io},Lh={...po,...ro};function ai(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ii=ai("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),mo=ai("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ru={utf8:ii,"utf-8":ii,hex:er.base16,latin1:mo,ascii:mo,binary:mo,...er},Mr=Ru;function M(r,t="utf8"){let e=Mr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function z(r,t="utf8"){let e=Mr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Lu=parseInt("11111",2),go=parseInt("10000000",2),Ou=parseInt("01111111",2),ci={0:rr,1:rr,2:ku,3:Mu,4:Ku,5:Uu,6:Nu,16:rr,22:rr,48:rr};function yo(r,t={offset:0}){let e=r[t.offset]&Lu;if(t.offset++,ci[e]!=null)return ci[e](r,t);throw new Error("No decoder for tag "+e)}function nr(r,t){let e=0;if((r[t.offset]&go)===go){let n=r[t.offset]&Ou,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function rr(r,t){nr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=yo(r,t);if(n===null)break;e.push(n)}return e}function ku(r,t){let e=nr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Nu(r,t){let e=nr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Uu(r,t){return t.offset++,null}function Mu(r,t){let e=nr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Ku(r,t){let e=nr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function zu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new j;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function bo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=zu(r.byteLength);return new j(Uint8Array.from([t.byteLength|go]),t)}function ui(r){let t=new j,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new j(Uint8Array.from([2]),bo(t),t)}function fi(r){let t=Uint8Array.from([0]),e=new j(t,r);return new j(Uint8Array.from([3]),bo(e),e)}function Kr(r,t=48){let e=new j;for(let n of r)e.append(n);return new j(Uint8Array.from([t]),bo(e),e)}async function li(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Fu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),qu=Uint8Array.from([6,5,43,129,4,0,34]),Hu=Uint8Array.from([6,5,43,129,4,0,35]),Vu={ext:!0,kty:"EC",crv:"P-256"},Gu={ext:!0,kty:"EC",crv:"P-384"},$u={ext:!0,kty:"EC",crv:"P-521"},xo=32,wo=48,Eo=66;function di(r){let t=yo(r);return hi(t)}function hi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===xo*2+1)return n=z(t.subarray(e,e+xo),"base64url"),o=z(t.subarray(e+xo),"base64url"),new ve({...Vu,key_ops:["verify"],x:n,y:o});if(t.byteLength===wo*2+1)return n=z(t.subarray(e,e+wo),"base64url"),o=z(t.subarray(e+wo),"base64url"),new ve({...Gu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Eo*2+1)return n=z(t.subarray(e,e+Eo),"base64url"),o=z(t.subarray(e+Eo),"base64url"),new ve({...$u,key_ops:["verify"],x:n,y:o});throw new Lt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function pi(r){return Kr([ui(Uint8Array.from([1])),Kr([Zu(r.crv)],160),Kr([fi(new j(Uint8Array.from([4]),M(r.x??"","base64url"),M(r.y??"","base64url")))],161)]).subarray()}function Zu(r){if(r==="P-256")return Fu;if(r==="P-384")return qu;if(r==="P-521")return Hu;throw new Lt(`Invalid curve ${r}`)}var ve=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=pi(this.jwk)),this._raw}toMultihash(){return St.digest(Ae(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async verify(t,e,n){return li(this.jwk,e,t,n)}};var re=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Be(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function or(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function rt(r,...t){if(!Be(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 gi(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");or(r.outputLen),or(r.blockLen)}function De(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 yi(r,t){rt(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Ut(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function zr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _t(r,t){return r<<32-t|r>>>t}var bi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ju=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Ct(r){if(rt(r),bi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=ju[r[e]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function mi(r){if(r>=Nt._0&&r<=Nt._9)return r-Nt._0;if(r>=Nt.A&&r<=Nt.F)return r-(Nt.A-10);if(r>=Nt.a&&r<=Nt.f)return r-(Nt.a-10)}function Ce(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(bi)return Uint8Array.fromHex(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=mi(r.charCodeAt(s)),a=mi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function xi(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function sr(r){return typeof r=="string"&&(r=xi(r)),rt(r),r}function pt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];rt(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 Ie=class{};function So(r){let t=n=>r().update(sr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function ir(r=32){if(re&&typeof re.getRandomValues=="function")return re.getRandomValues(new Uint8Array(r));if(re&&typeof re.randomBytes=="function")return Uint8Array.from(re.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Wu(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,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function wi(r,t,e){return r&t^~r&e}function Ei(r,t,e){return r&t^r&e^t&e}var ar=class extends Ie{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=zr(this.buffer)}update(t){De(this),t=sr(t),rt(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=zr(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){De(this),yi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;Wu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=zr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Fr=BigInt(4294967295),Si=BigInt(32);function Xu(r,t=!1){return t?{h:Number(r&Fr),l:Number(r>>Si&Fr)}:{h:Number(r>>Si&Fr)|0,l:Number(r&Fr)|0}}function _i(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Xu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var _o=(r,t,e)=>r>>>e,vo=(r,t,e)=>r<<32-e|t>>>e,ne=(r,t,e)=>r>>>e|t<<32-e,oe=(r,t,e)=>r<<32-e|t>>>e,cr=(r,t,e)=>r<<64-e|t>>>e-32,ur=(r,t,e)=>r>>>e-32|t<<64-e;function Tt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var vi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ai=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ii=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Bi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Di=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ci=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Qu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Gt=new Uint32Array(64),Ao=class extends ar{constructor(t=32){super(64,t,8,!1),this.A=Mt[0]|0,this.B=Mt[1]|0,this.C=Mt[2]|0,this.D=Mt[3]|0,this.E=Mt[4]|0,this.F=Mt[5]|0,this.G=Mt[6]|0,this.H=Mt[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 l=0;l<16;l++,e+=4)Gt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let h=Gt[l-15],m=Gt[l-2],x=_t(h,7)^_t(h,18)^h>>>3,w=_t(m,17)^_t(m,19)^m>>>10;Gt[l]=w+Gt[l-7]+x+Gt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=_t(a,6)^_t(a,11)^_t(a,25),m=f+h+wi(a,c,u)+Qu[l]+Gt[l]|0,w=(_t(n,2)^_t(n,13)^_t(n,22))+Ei(n,o,s)|0;f=u,u=c,c=a,a=i+m|0,i=s,s=o,o=n,n=m+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Ut(Gt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}};var Ti=_i(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Ju=Ti[0],tf=Ti[1],$t=new Uint32Array(80),Zt=new Uint32Array(80),Io=class extends ar{constructor(t=64){super(128,t,16,!1),this.Ah=J[0]|0,this.Al=J[1]|0,this.Bh=J[2]|0,this.Bl=J[3]|0,this.Ch=J[4]|0,this.Cl=J[5]|0,this.Dh=J[6]|0,this.Dl=J[7]|0,this.Eh=J[8]|0,this.El=J[9]|0,this.Fh=J[10]|0,this.Fl=J[11]|0,this.Gh=J[12]|0,this.Gl=J[13]|0,this.Hh=J[14]|0,this.Hl=J[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:m,Gl:x,Hh:w,Hl:p}=this;return[t,e,n,o,s,i,a,c,u,f,l,h,m,x,w,p]}set(t,e,n,o,s,i,a,c,u,f,l,h,m,x,w,p){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=x|0,this.Hh=w|0,this.Hl=p|0}process(t,e){for(let v=0;v<16;v++,e+=4)$t[v]=t.getUint32(e),Zt[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let R=$t[v-15]|0,y=Zt[v-15]|0,P=ne(R,y,1)^ne(R,y,8)^_o(R,y,7),T=oe(R,y,1)^oe(R,y,8)^vo(R,y,7),I=$t[v-2]|0,d=Zt[v-2]|0,E=ne(I,d,19)^cr(I,d,61)^_o(I,d,6),g=oe(I,d,19)^ur(I,d,61)^vo(I,d,6),b=Ii(T,g,Zt[v-7],Zt[v-16]),S=Bi(b,P,E,$t[v-7],$t[v-16]);$t[v]=S|0,Zt[v]=b|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:m,Fl:x,Gh:w,Gl:p,Hh:_,Hl:D}=this;for(let v=0;v<80;v++){let R=ne(l,h,14)^ne(l,h,18)^cr(l,h,41),y=oe(l,h,14)^oe(l,h,18)^ur(l,h,41),P=l&m^~l&w,T=h&x^~h&p,I=Di(D,y,T,tf[v],Zt[v]),d=Ci(I,_,R,P,Ju[v],$t[v]),E=I|0,g=ne(n,o,28)^cr(n,o,34)^cr(n,o,39),b=oe(n,o,28)^ur(n,o,34)^ur(n,o,39),S=n&s^n&a^s&a,B=o&i^o&c^i&c;_=w|0,D=p|0,w=m|0,p=x|0,m=l|0,x=h|0,{h:l,l:h}=Tt(u|0,f|0,d|0,E|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let A=vi(E,b,B);n=Ai(A,d,g,S),o=A|0}({h:n,l:o}=Tt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Tt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Tt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Tt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Tt(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:x}=Tt(this.Fh|0,this.Fl|0,m|0,x|0),{h:w,l:p}=Tt(this.Gh|0,this.Gl|0,w|0,p|0),{h:_,l:D}=Tt(this.Hh|0,this.Hl|0,_|0,D|0),this.set(n,o,s,i,a,c,u,f,l,h,m,x,w,p,_,D)}roundClean(){Ut($t,Zt)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Pi=So(()=>new Ao);var Ri=So(()=>new Io);var Co=BigInt(0),Do=BigInt(1);function Kt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function fr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Li(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Co:BigInt("0x"+r)}function Te(r){return Li(Ct(r))}function se(r){return rt(r),Li(Ct(Uint8Array.from(r).reverse()))}function qr(r,t){return Ce(r.toString(16).padStart(t*2,"0"))}function Pe(r,t){return qr(r,t).reverse()}function F(r,t,e){let n;if(typeof t=="string")try{n=Ce(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Be(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}var Bo=r=>typeof r=="bigint"&&Co<=r;function Oi(r,t,e){return Bo(r)&&Bo(t)&&Bo(e)&&t<=r&&r<e}function jt(r,t,e,n){if(!Oi(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ki(r){let t;for(t=0;r>Co;r>>=Do,t+=1);return t}var ie=r=>(Do<<BigInt(r))-Do;function Ni(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=m=>new Uint8Array(m),o=m=>Uint8Array.of(m),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},u=(...m)=>e(i,s,...m),f=(m=n(0))=>{i=u(o(0),m),s=u(),m.length!==0&&(i=u(o(1),m),s=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let m=0,x=[];for(;m<t;){s=u();let w=s.slice();x.push(w),m+=s.length}return pt(...x)};return(m,x)=>{c(),f(m);let w;for(;!(w=x(l()));)f();return c(),w}}function Wt(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function Re(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 ct=BigInt(0),Y=BigInt(1),ae=BigInt(2),ef=BigInt(3),Ki=BigInt(4),zi=BigInt(5),Fi=BigInt(8);function V(r,t){let e=r%t;return e>=ct?e:t+e}function q(r,t,e){let n=r;for(;t-- >ct;)n*=n,n%=e;return n}function Ui(r,t){if(r===ct)throw new Error("invert: expected non-zero number");if(t<=ct)throw new Error("invert: expected positive modulus, got "+t);let e=V(r,t),n=t,o=ct,s=Y,i=Y,a=ct;for(;e!==ct;){let u=n/e,f=n%e,l=o-i*u,h=s-a*u;n=e,e=f,o=i,s=a,i=l,a=h}if(n!==Y)throw new Error("invert: does not exist");return V(o,t)}function qi(r,t){let e=(r.ORDER+Y)/Ki,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function rf(r,t){let e=(r.ORDER-zi)/Fi,n=r.mul(t,ae),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ae),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function nf(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-Y,e=0;for(;t%ae===ct;)t/=ae,e++;let n=ae,o=vt(r);for(;Mi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return qi;let s=o.pow(n,t),i=(t+Y)/ae;return function(c,u){if(c.is0(u))return u;if(Mi(c,u)!==1)throw new Error("Cannot find square root");let f=e,l=c.mul(c.ONE,s),h=c.pow(u,t),m=c.pow(u,i);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let x=1,w=c.sqr(h);for(;!c.eql(w,c.ONE);)if(x++,w=c.sqr(w),x===f)throw new Error("Cannot find square root");let p=Y<<BigInt(f-x-1),_=c.pow(l,p);f=x,l=c.sqr(_),h=c.mul(h,l),m=c.mul(m,_)}return m}}function of(r){return r%Ki===ef?qi:r%Fi===zi?rf:nf(r)}var Hi=(r,t)=>(V(r,t)&Y)===Y,sf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function To(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=sf.reduce((n,o)=>(n[o]="function",n),t);return Wt(r,e),r}function af(r,t,e){if(e<ct)throw new Error("invalid exponent, negatives unsupported");if(e===ct)return r.ONE;if(e===Y)return t;let n=r.ONE,o=t;for(;e>ct;)e&Y&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Y;return n}function lr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Mi(r,t){let e=(r.ORDER-Y)/ae,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Vi(r,t){t!==void 0&&or(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function vt(r,t,e=!1,n={}){if(r<=ct)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(e=f.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Vi(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,u=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ie(i),ZERO:ct,ONE:Y,create:f=>V(f,r),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return ct<=f&&f<r},is0:f=>f===ct,isValidNot0:f=>!u.is0(f)&&u.isValid(f),isOdd:f=>(f&Y)===Y,neg:f=>V(-f,r),eql:(f,l)=>f===l,sqr:f=>V(f*f,r),add:(f,l)=>V(f+l,r),sub:(f,l)=>V(f-l,r),mul:(f,l)=>V(f*l,r),pow:(f,l)=>af(u,f,l),div:(f,l)=>V(f*Ui(l,r),r),sqrN:f=>f*f,addN:(f,l)=>f+l,subN:(f,l)=>f-l,mulN:(f,l)=>f*l,inv:f=>Ui(f,r),sqrt:s||(f=>(c||(c=of(r)),c(u,f))),toBytes:f=>e?Pe(f,a):qr(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return e?se(f):Te(f)},invertBatch:f=>lr(u,f),cmov:(f,l,h)=>h?l:f});return Object.freeze(u)}function Gi(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 Po(r){let t=Gi(r);return t+Math.ceil(t/2)}function $i(r,t,e=!1){let n=r.length,o=Gi(t),s=Po(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?se(r):Te(r),a=V(i,t-Y)+Y;return e?Pe(a,o):qr(a,o)}var Oe=BigInt(0),ce=BigInt(1);function Le(r,t){let e=t.negate();return r?e:t}function Hr(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=lr(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}function Xi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Ro(r,t){Xi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ie(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Zi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ce);let u=t*n,f=u+Math.abs(a)-1,l=a===0,h=a<0,m=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:m,offsetF:u}}function cf(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 uf(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 Lo=new WeakMap,Yi=new WeakMap;function Oo(r){return Yi.get(r)||1}function ji(r){if(r!==Oe)throw new Error("invalid wNAF")}function Vr(r,t){return{constTimeNegate:Le,hasPrecomputes(e){return Oo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Oe;)n&ce&&(o=o.add(s)),s=s.double(),n>>=ce;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Ro(n,t),i=[],a=e,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=Ro(e,t);for(let c=0;c<a.windows;c++){let{nextN:u,offset:f,isZero:l,isNeg:h,isNegF:m,offsetF:x}=Zi(o,c,a);o=u,l?i=i.add(Le(m,n[x])):s=s.add(Le(h,n[f]))}return ji(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Ro(e,t);for(let a=0;a<i.windows&&o!==Oe;a++){let{nextN:c,offset:u,isZero:f,isNeg:l}=Zi(o,a,i);if(o=c,!f){let h=n[u];s=s.add(l?h.negate():h)}}return ji(o),s},getPrecomputes(e,n,o){let s=Lo.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),Lo.set(n,s))),s},wNAFCached(e,n,o){let s=Oo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Oo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Xi(n,t),Yi.set(e,n),Lo.delete(e)}}}function Qi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Oe||n>Oe;)e&ce&&(s=s.add(o)),n&ce&&(i=i.add(o)),o=o.double(),e>>=ce,n>>=ce;return{p1:s,p2:i}}function Gr(r,t,e,n){cf(e,r),uf(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=ki(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ie(c),f=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,h=i;for(let m=l;m>=0;m-=c){f.fill(i);for(let w=0;w<s;w++){let p=n[w],_=Number(p>>BigInt(m)&u);f[_]=f[_].add(e[w])}let x=i;for(let w=f.length-1,p=i;w>0;w--)p=p.add(f[w]),x=x.add(p);if(h=h.add(x),m!==0)for(let w=0;w<c;w++)h=h.double()}return h}function Wi(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return To(t),t}else return vt(r)}function $r(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Oe))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Wi(t.p,e.Fp),o=Wi(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Pt=BigInt(0),ut=BigInt(1),ko=BigInt(2),ff=BigInt(8),lf={zip215:!0};function df(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function hf(r,t={}){let{Fp:e,Fn:n}=$r("edwards",r,t),{h:o,n:s}=r;Wt(t,{},{uvRatio:"function"});let i=ko<<BigInt(n.BYTES*8)-ut,a=w=>e.create(w),c=t.uvRatio||((w,p)=>{try{return{isValid:!0,value:e.sqrt(e.div(w,p))}}catch{return{isValid:!1,value:Pt}}});if(!df(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function u(w,p,_=!1){let D=_?ut:Pt;return jt("coordinate "+w,p,D,i),p}function f(w){if(!(w instanceof m))throw new Error("ExtendedPoint expected")}let l=Re((w,p)=>{let{ex:_,ey:D,ez:v}=w,R=w.is0();p==null&&(p=R?ff:e.inv(v));let y=a(_*p),P=a(D*p),T=a(v*p);if(R)return{x:Pt,y:ut};if(T!==ut)throw new Error("invZ was invalid");return{x:y,y:P}}),h=Re(w=>{let{a:p,d:_}=r;if(w.is0())throw new Error("bad point: ZERO");let{ex:D,ey:v,ez:R,et:y}=w,P=a(D*D),T=a(v*v),I=a(R*R),d=a(I*I),E=a(P*p),g=a(I*a(E+T)),b=a(d+a(_*a(P*T)));if(g!==b)throw new Error("bad point: equation left != right (1)");let S=a(D*v),B=a(R*y);if(S!==B)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,_,D,v){this.ex=u("x",p),this.ey=u("y",_),this.ez=u("z",D,!0),this.et=u("t",v),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");let{x:_,y:D}=p||{};return u("x",_),u("y",D),new m(_,D,ut,a(_*D))}static normalizeZ(p){return Hr(m,"ez",p)}static msm(p,_){return Gr(m,n,p,_)}_setWindowSize(p){this.precompute(p)}precompute(p=8,_=!0){return x.setWindowSize(this,p),_||this.multiply(ko),this}assertValidity(){h(this)}equals(p){f(p);let{ex:_,ey:D,ez:v}=this,{ex:R,ey:y,ez:P}=p,T=a(_*P),I=a(R*v),d=a(D*P),E=a(y*v);return T===I&&d===E}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:p}=r,{ex:_,ey:D,ez:v}=this,R=a(_*_),y=a(D*D),P=a(ko*a(v*v)),T=a(p*R),I=_+D,d=a(a(I*I)-R-y),E=T+y,g=E-P,b=T-y,S=a(d*g),B=a(E*b),A=a(d*b),C=a(g*E);return new m(S,B,C,A)}add(p){f(p);let{a:_,d:D}=r,{ex:v,ey:R,ez:y,et:P}=this,{ex:T,ey:I,ez:d,et:E}=p,g=a(v*T),b=a(R*I),S=a(P*D*E),B=a(y*d),A=a((v+R)*(T+I)-g-b),C=B-S,O=B+S,L=a(b-_*g),$=a(A*C),U=a(O*L),k=a(A*L),Z=a(C*O);return new m($,U,Z,k)}subtract(p){return this.add(p.negate())}multiply(p){let _=p;jt("scalar",_,ut,s);let{p:D,f:v}=x.wNAFCached(this,_,m.normalizeZ);return m.normalizeZ([D,v])[0]}multiplyUnsafe(p,_=m.ZERO){let D=p;return jt("scalar",D,Pt,s),D===Pt?m.ZERO:this.is0()||D===ut?this:x.wNAFCachedUnsafe(this,D,m.normalizeZ,_)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return x.wNAFCachedUnsafe(this,s).is0()}toAffine(p){return l(this,p)}clearCofactor(){return o===ut?this:this.multiplyUnsafe(o)}static fromBytes(p,_=!1){return rt(p),this.fromHex(p,_)}static fromHex(p,_=!1){let{d:D,a:v}=r,R=e.BYTES;p=F("pointHex",p,R),Kt("zip215",_);let y=p.slice(),P=p[R-1];y[R-1]=P&-129;let T=se(y),I=_?i:e.ORDER;jt("pointHex.y",T,Pt,I);let d=a(T*T),E=a(d-ut),g=a(D*d-v),{isValid:b,value:S}=c(E,g);if(!b)throw new Error("Point.fromHex: invalid y coordinate");let B=(S&ut)===ut,A=(P&128)!==0;if(!_&&S===Pt&&A)throw new Error("Point.fromHex: x=0 and x_0=1");return A!==B&&(S=a(-S)),m.fromAffine({x:S,y:T})}static fromPrivateScalar(p){return m.BASE.multiply(p)}toBytes(){let{x:p,y:_}=this.toAffine(),D=Pe(_,e.BYTES);return D[D.length-1]|=p&ut?128:0,D}toRawBytes(){return this.toBytes()}toHex(){return Ct(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}m.BASE=new m(r.Gx,r.Gy,ut,a(r.Gx*r.Gy)),m.ZERO=new m(Pt,ut,ut,Pt),m.Fp=e,m.Fn=n;let x=Vr(m,n.BYTES*8);return m}function pf(r,t){Wt(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=t.randomBytes||ir,u=t.adjustScalarBytes||(y=>y),f=t.domain||((y,P,T)=>{if(Kt("phflag",T),P.length||T)throw new Error("Contexts/pre-hash are not supported");return y});function l(y){return i.create(y)}function h(y){return l(se(y))}function m(y){let P=s.BYTES;y=F("private key",y,P);let T=F("hashed private key",n(y),2*P),I=u(T.slice(0,P)),d=T.slice(P,2*P),E=h(I);return{head:I,prefix:d,scalar:E}}function x(y){let{head:P,prefix:T,scalar:I}=m(y),d=o.multiply(I),E=d.toBytes();return{head:P,prefix:T,scalar:I,point:d,pointBytes:E}}function w(y){return x(y).pointBytes}function p(y=Uint8Array.of(),...P){let T=pt(...P);return h(n(f(T,F("context",y),!!e)))}function _(y,P,T={}){y=F("message",y),e&&(y=e(y));let{prefix:I,scalar:d,pointBytes:E}=x(P),g=p(T.context,I,y),b=o.multiply(g).toBytes(),S=p(T.context,b,E,y),B=l(g+S*d);jt("signature.s",B,Pt,a);let A=s.BYTES,C=pt(b,Pe(B,A));return F("result",C,A*2)}let D=lf;function v(y,P,T,I=D){let{context:d,zip215:E}=I,g=s.BYTES;y=F("signature",y,2*g),P=F("message",P),T=F("publicKey",T,g),E!==void 0&&Kt("zip215",E),e&&(P=e(P));let b=se(y.slice(g,2*g)),S,B,A;try{S=r.fromHex(T,E),B=r.fromHex(y.slice(0,g),E),A=o.multiplyUnsafe(b)}catch{return!1}if(!E&&S.isSmallOrder())return!1;let C=p(d,B.toBytes(),S.toBytes(),P);return B.add(S.multiplyUnsafe(C)).subtract(A).clearCofactor().is0()}return o.precompute(8),{getPublicKey:w,sign:_,verify:v,utils:{getExtendedPublicKey:x,randomPrivateKey:()=>c(s.BYTES),precompute(y=8,P=r.BASE){return P.precompute(y,!1)}},Point:r}}function mf(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=vt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function gf(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function Ji(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=mf(r),o=hf(t,e),s=pf(o,n);return gf(r,s)}var Mp=BigInt(0),yf=BigInt(1),ta=BigInt(2),Kp=BigInt(3),bf=BigInt(5),xf=BigInt(8),Zr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:xf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function wf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Zr.p,a=r*r%s*r%s,c=q(a,ta,s)*a%s,u=q(c,yf,s)*r%s,f=q(u,bf,s)*u%s,l=q(f,t,s)*f%s,h=q(l,e,s)*l%s,m=q(h,n,s)*h%s,x=q(m,o,s)*m%s,w=q(x,o,s)*m%s,p=q(w,t,s)*f%s;return{pow_p_5_8:q(p,ta,s)*r%s,b2:a}}function Ef(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ea=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Sf(r,t){let e=Zr.p,n=V(t*t*t,e),o=V(n*n*t,e),s=wf(r*o).pow_p_5_8,i=V(r*n*s,e),a=V(t*i*i,e),c=i,u=V(i*ea,e),f=a===r,l=a===V(-r,e),h=a===V(-r*ea,e);return f&&(i=c),(l||h)&&(i=u),Hi(i,e)&&(i=V(-i,e)),{isValid:f||l,value:i}}var _f=vt(Zr.p,void 0,!0),vf={...Zr,Fp:_f,hash:Ri,adjustScalarBytes:Ef,uvRatio:Sf},ra=Ji(vf);var dr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},jr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var na={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new jr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Wr=na;var Xr=32;var No,Af=(async()=>{try{return await Wr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function If(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Wr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Wr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Bf(r,t,e){return ra.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function oa(r,t,e){return No==null&&(No=await Af),No?If(r,t,e):Bf(r,t,e)}function Yr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Qr=class{type="Ed25519";raw;constructor(t){this.raw=Uo(t,Xr)}toMultihash(){return St.digest(Ae(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=oa(this.raw,e,t);return Yr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ia(r){return r=Uo(r,Xr),new Qr(r)}function Uo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Lt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Cf=Math.pow(2,7),Tf=Math.pow(2,14),Pf=Math.pow(2,21),Mo=Math.pow(2,28),Ko=Math.pow(2,35),zo=Math.pow(2,42),Fo=Math.pow(2,49),N=128,nt=127;function lt(r){if(r<Cf)return 1;if(r<Tf)return 2;if(r<Pf)return 3;if(r<Mo)return 4;if(r<Ko)return 5;if(r<zo)return 6;if(r<Fo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ke(r,t,e=0){switch(lt(r)){case 8:t[e++]=r&255|N,r/=128;case 7:t[e++]=r&255|N,r/=128;case 6:t[e++]=r&255|N,r/=128;case 5:t[e++]=r&255|N,r/=128;case 4:t[e++]=r&255|N,r>>>=7;case 3:t[e++]=r&255|N,r>>>=7;case 2:t[e++]=r&255|N,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Rf(r,t,e=0){switch(lt(r)){case 8:t.set(e++,r&255|N),r/=128;case 7:t.set(e++,r&255|N),r/=128;case 6:t.set(e++,r&255|N),r/=128;case 5:t.set(e++,r&255|N),r/=128;case 4:t.set(e++,r&255|N),r>>>=7;case 3:t.set(e++,r&255|N),r>>>=7;case 2:t.set(e++,r&255|N),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function qo(r,t){let e=r[t],n=0;if(n+=e&nt,e<N||(e=r[t+1],n+=(e&nt)<<7,e<N)||(e=r[t+2],n+=(e&nt)<<14,e<N)||(e=r[t+3],n+=(e&nt)<<21,e<N)||(e=r[t+4],n+=(e&nt)*Mo,e<N)||(e=r[t+5],n+=(e&nt)*Ko,e<N)||(e=r[t+6],n+=(e&nt)*zo,e<N)||(e=r[t+7],n+=(e&nt)*Fo,e<N))return n;throw new RangeError("Could not decode varint")}function Lf(r,t){let e=r.get(t),n=0;if(n+=e&nt,e<N||(e=r.get(t+1),n+=(e&nt)<<7,e<N)||(e=r.get(t+2),n+=(e&nt)<<14,e<N)||(e=r.get(t+3),n+=(e&nt)<<21,e<N)||(e=r.get(t+4),n+=(e&nt)*Mo,e<N)||(e=r.get(t+5),n+=(e&nt)*Ko,e<N)||(e=r.get(t+6),n+=(e&nt)*zo,e<N)||(e=r.get(t+7),n+=(e&nt)*Fo,e<N))return n;throw new RangeError("Could not decode varint")}function aa(r,t,e=0){return t==null&&(t=ft(lt(r))),t instanceof Uint8Array?ke(r,t,e):Rf(r,t,e)}function hr(r,t=0){return r instanceof Uint8Array?qo(r,t):Lf(r,t)}var Ho=new Float32Array([-0]),Xt=new Uint8Array(Ho.buffer);function ua(r,t,e){Ho[0]=r,t[e]=Xt[0],t[e+1]=Xt[1],t[e+2]=Xt[2],t[e+3]=Xt[3]}function fa(r,t){return Xt[0]=r[t],Xt[1]=r[t+1],Xt[2]=r[t+2],Xt[3]=r[t+3],Ho[0]}var Vo=new Float64Array([-0]),ot=new Uint8Array(Vo.buffer);function la(r,t,e){Vo[0]=r,t[e]=ot[0],t[e+1]=ot[1],t[e+2]=ot[2],t[e+3]=ot[3],t[e+4]=ot[4],t[e+5]=ot[5],t[e+6]=ot[6],t[e+7]=ot[7]}function da(r,t){return ot[0]=r[t],ot[1]=r[t+1],ot[2]=r[t+2],ot[3]=r[t+3],ot[4]=r[t+4],ot[5]=r[t+5],ot[6]=r[t+6],ot[7]=r[t+7],Vo[0]}var Of=BigInt(Number.MAX_SAFE_INTEGER),kf=BigInt(Number.MIN_SAFE_INTEGER),mt=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 ue;if(t<Of&&t>kf)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>ha&&(o=0n,++n>ha&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ue;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):ue}},ue=new mt(0,0);ue.toBigInt=function(){return 0n};ue.zzEncode=ue.zzDecode=function(){return this};ue.length=function(){return 1};var ha=4294967296n;function pa(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ma(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Go(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 Jr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var $o=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 Jr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return Jr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=fa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=da(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 ma(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)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new mt(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=Jr(this.buf,this.pos+=4),e=Jr(this.buf,this.pos+=4);return new mt(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=qo(this.buf,this.pos);return this.pos+=lt(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 Zo(r){return new $o(r instanceof Uint8Array?r:r.subarray())}function xt(r,t,e){let n=Zo(r);return t.decode(n,void 0,e)}function jo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var fe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Wo(){}var Yo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Nf=jo();function Uf(r){return globalThis.Buffer!=null?ft(r):Nf(r)}var mr=class{len;head;tail;states;constructor(){this.len=0,this.head=new fe(Wo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new fe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Qo((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(tn,10,mt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=mt.fromBigInt(t);return this._push(tn,e.length(),e)}uint64Number(t){return this._push(ke,lt(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=mt.fromBigInt(t).zzEncode();return this._push(tn,e.length(),e)}sint64Number(t){let e=mt.fromNumber(t).zzEncode();return this._push(tn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Xo,1,t?1:0)}fixed32(t){return this._push(pr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=mt.fromBigInt(t);return this._push(pr,4,e.lo)._push(pr,4,e.hi)}fixed64Number(t){let e=mt.fromNumber(t);return this._push(pr,4,e.lo)._push(pr,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(ua,4,t)}double(t){return this._push(la,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Xo,1,0):this.uint32(e)._push(Kf,e,t)}string(t){let e=pa(t);return e!==0?this.uint32(e)._push(Go,e,t):this._push(Xo,1,0)}fork(){return this.states=new Yo(this),this.head=this.tail=new fe(Wo,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 fe(Wo,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=Uf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Xo(r,t,e){t[e]=r&255}function Mf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Qo=class extends fe{next;constructor(t,e){super(Mf,t,e),this.next=void 0}};function tn(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 pr(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 Kf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(mr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(zf,t,r),this},mr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ff,t,r),this});function zf(r,t,e){t.set(r,e)}function Ff(r,t,e){r.length<40?Go(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(M(r),e)}function Jo(){return new mr}function wt(r,t){let e=Jo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ne;(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"})(Ne||(Ne={}));function en(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function le(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 en("enum",Ne.VARINT,e,n)}function Et(r,t){return en("message",Ne.LENGTH_DELIMITED,r,t)}var rn=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var gt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(gt||(gt={}));var ts;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ts||(ts={}));(function(r){r.codec=()=>le(ts)})(gt||(gt={}));var gr;(function(r){let t;r.codec=()=>(t==null&&(t=Et((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.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=gt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(gr||(gr={}));var es;(function(r){let t;r.codec=()=>(t==null&&(t=Et((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.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=gt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(es||(es={}));var nn=class extends Ie{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,gi(t);let n=sr(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),Ut(s)}update(t){return De(this),this.iHash.update(t),this}digestInto(t){De(this),rt(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}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},rs=(r,t,e)=>new nn(r,t).update(e).digest();rs.create=(r,t)=>new nn(r,t);function ya(r){r.lowS!==void 0&&Kt("lowS",r.lowS),r.prehash!==void 0&&Kt("prehash",r.prehash)}var ns=class extends Error{constructor(t=""){super(t)}},zt={Err:ns,_tlv:{encode:(r,t)=>{let{Err:e}=zt;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=fr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?fr(o.length/2|128):"";return fr(r)+s+o+t},decode(r,t){let{Err:e}=zt,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 u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=zt;if(r<yr)throw new t("integer: negative integers are not allowed");let e=fr(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}=zt;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 Te(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=zt,o=F("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=zt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},yr=BigInt(0),br=BigInt(1),Hf=BigInt(2),on=BigInt(3),Vf=BigInt(4);function Gf(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function ba(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=F("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function $f(r,t={}){let{Fp:e,Fn:n}=$r("weierstrass",r,t),{h:o,n:s}=r;Wt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(I,d,E){let{x:g,y:b}=d.toAffine(),S=e.toBytes(g);if(Kt("isCompressed",E),E){a();let B=!e.isOdd(b);return pt(xa(B),S)}else return pt(Uint8Array.of(4),S,e.toBytes(b))}function u(I){rt(I);let d=e.BYTES,E=d+1,g=2*d+1,b=I.length,S=I[0],B=I.subarray(1);if(b===E&&(S===2||S===3)){let A=e.fromBytes(B);if(!e.isValid(A))throw new Error("bad point: is not on curve, wrong x");let C=h(A),O;try{O=e.sqrt(C)}catch(U){let k=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+k)}a();let L=e.isOdd(O);return(S&1)===1!==L&&(O=e.neg(O)),{x:A,y:O}}else if(b===g&&S===4){let A=e.fromBytes(B.subarray(d*0,d*1)),C=e.fromBytes(B.subarray(d*1,d*2));if(!m(A,C))throw new Error("bad point: is not on curve");return{x:A,y:C}}else throw new Error(`bad point: got length ${b}, expected compressed=${E} or uncompressed=${g}`)}let f=t.toBytes||c,l=t.fromBytes||u,h=Gf(e,r.a,r.b);function m(I,d){let E=e.sqr(d),g=h(I);return e.eql(E,g)}if(!m(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let x=e.mul(e.pow(r.a,on),Vf),w=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(x,w)))throw new Error("bad curve params: a or b");function p(I,d,E=!1){if(!e.isValid(d)||E&&e.is0(d))throw new Error(`bad point coordinate ${I}`);return d}function _(I){if(!(I instanceof y))throw new Error("ProjectivePoint expected")}let D=Re((I,d)=>{let{px:E,py:g,pz:b}=I;if(e.eql(b,e.ONE))return{x:E,y:g};let S=I.is0();d==null&&(d=S?e.ONE:e.inv(b));let B=e.mul(E,d),A=e.mul(g,d),C=e.mul(b,d);if(S)return{x:e.ZERO,y:e.ZERO};if(!e.eql(C,e.ONE))throw new Error("invZ was invalid");return{x:B,y:A}}),v=Re(I=>{if(I.is0()){if(t.allowInfinityPoint&&!e.is0(I.py))return;throw new Error("bad point: ZERO")}let{x:d,y:E}=I.toAffine();if(!e.isValid(d)||!e.isValid(E))throw new Error("bad point: x or y not field elements");if(!m(d,E))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(I,d,E,g,b){return E=new y(e.mul(E.px,I),E.py,E.pz),d=Le(g,d),E=Le(b,E),d.add(E)}class y{constructor(d,E,g){this.px=p("x",d),this.py=p("y",E,!0),this.pz=p("z",g),Object.freeze(this)}static fromAffine(d){let{x:E,y:g}=d||{};if(!d||!e.isValid(E)||!e.isValid(g))throw new Error("invalid affine point");if(d instanceof y)throw new Error("projective point not allowed");return e.is0(E)&&e.is0(g)?y.ZERO:new y(E,g,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){return Hr(y,"pz",d)}static fromBytes(d){return rt(d),y.fromHex(d)}static fromHex(d){let E=y.fromAffine(l(F("pointHex",d)));return E.assertValidity(),E}static fromPrivateKey(d){let E=ba(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return y.BASE.multiply(E(d))}static msm(d,E){return Gr(y,n,d,E)}precompute(d=8,E=!0){return T.setWindowSize(this,d),E||this.multiply(on),this}_setWindowSize(d){this.precompute(d)}assertValidity(){v(this)}hasEvenY(){let{y:d}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(d)}equals(d){_(d);let{px:E,py:g,pz:b}=this,{px:S,py:B,pz:A}=d,C=e.eql(e.mul(E,A),e.mul(S,b)),O=e.eql(e.mul(g,A),e.mul(B,b));return C&&O}negate(){return new y(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:E}=r,g=e.mul(E,on),{px:b,py:S,pz:B}=this,A=e.ZERO,C=e.ZERO,O=e.ZERO,L=e.mul(b,b),$=e.mul(S,S),U=e.mul(B,B),k=e.mul(b,S);return k=e.add(k,k),O=e.mul(b,B),O=e.add(O,O),A=e.mul(d,O),C=e.mul(g,U),C=e.add(A,C),A=e.sub($,C),C=e.add($,C),C=e.mul(A,C),A=e.mul(k,A),O=e.mul(g,O),U=e.mul(d,U),k=e.sub(L,U),k=e.mul(d,k),k=e.add(k,O),O=e.add(L,L),L=e.add(O,L),L=e.add(L,U),L=e.mul(L,k),C=e.add(C,L),U=e.mul(S,B),U=e.add(U,U),L=e.mul(U,k),A=e.sub(A,L),O=e.mul(U,$),O=e.add(O,O),O=e.add(O,O),new y(A,C,O)}add(d){_(d);let{px:E,py:g,pz:b}=this,{px:S,py:B,pz:A}=d,C=e.ZERO,O=e.ZERO,L=e.ZERO,$=r.a,U=e.mul(r.b,on),k=e.mul(E,S),Z=e.mul(g,B),W=e.mul(b,A),et=e.add(E,g),K=e.add(S,B);et=e.mul(et,K),K=e.add(k,Z),et=e.sub(et,K),K=e.add(E,b);let it=e.add(S,A);return K=e.mul(K,it),it=e.add(k,W),K=e.sub(K,it),it=e.add(g,b),C=e.add(B,A),it=e.mul(it,C),C=e.add(Z,W),it=e.sub(it,C),L=e.mul($,K),C=e.mul(U,W),L=e.add(C,L),C=e.sub(Z,L),L=e.add(Z,L),O=e.mul(C,L),Z=e.add(k,k),Z=e.add(Z,k),W=e.mul($,W),K=e.mul(U,K),Z=e.add(Z,W),W=e.sub(k,W),W=e.mul($,W),K=e.add(K,W),k=e.mul(Z,K),O=e.add(O,k),k=e.mul(it,K),C=e.mul(et,C),C=e.sub(C,k),k=e.mul(et,Z),L=e.mul(it,L),L=e.add(L,k),new y(C,O,L)}subtract(d){return this.add(d.negate())}is0(){return this.equals(y.ZERO)}multiply(d){let{endo:E}=t;if(!n.isValidNot0(d))throw new Error("invalid scalar: out of range");let g,b,S=B=>T.wNAFCached(this,B,y.normalizeZ);if(E){let{k1neg:B,k1:A,k2neg:C,k2:O}=E.splitScalar(d),{p:L,f:$}=S(A),{p:U,f:k}=S(O);b=$.add(k),g=R(E.beta,L,U,B,C)}else{let{p:B,f:A}=S(d);g=B,b=A}return y.normalizeZ([g,b])[0]}multiplyUnsafe(d){let{endo:E}=t,g=this;if(!n.isValid(d))throw new Error("invalid scalar: out of range");if(d===yr||g.is0())return y.ZERO;if(d===br)return g;if(T.hasPrecomputes(this))return this.multiply(d);if(E){let{k1neg:b,k1:S,k2neg:B,k2:A}=E.splitScalar(d),{p1:C,p2:O}=Qi(y,g,S,A);return R(E.beta,C,O,b,B)}else return T.wNAFCachedUnsafe(g,d)}multiplyAndAddUnsafe(d,E,g){let b=this.multiplyUnsafe(E).add(d.multiplyUnsafe(g));return b.is0()?void 0:b}toAffine(d){return D(this,d)}isTorsionFree(){let{isTorsionFree:d}=t;return o===br?!0:d?d(y,this):T.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:d}=t;return o===br?this:d?d(y,this):this.multiplyUnsafe(o)}toBytes(d=!0){return Kt("isCompressed",d),this.assertValidity(),f(y,this,d)}toRawBytes(d=!0){return this.toBytes(d)}toHex(d=!0){return Ct(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}y.BASE=new y(r.Gx,r.Gy,e.ONE),y.ZERO=new y(e.ZERO,e.ONE,e.ZERO),y.Fp=e,y.Fn=n;let P=n.BITS,T=Vr(y,t.endo?Math.ceil(P/2):P);return y}function xa(r){return Uint8Array.of(r?2:3)}function Zf(r,t,e={}){Wt(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||ir,o=t.hmac||((g,...b)=>rs(t.hash,g,pt(...b))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i;function u(g){let b=a>>br;return g>b}function f(g){return u(g)?i.neg(g):g}function l(g,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${g}: out of range 1..CURVE.n`)}class h{constructor(b,S,B){l("r",b),l("s",S),this.r=b,this.s=S,B!=null&&(this.recovery=B),Object.freeze(this)}static fromCompact(b){let S=i.BYTES,B=F("compactSignature",b,S*2);return new h(i.fromBytes(B.subarray(0,S)),i.fromBytes(B.subarray(S,S*2)))}static fromDER(b){let{r:S,s:B}=zt.toSig(F("DER",b));return new h(S,B)}assertValidity(){}addRecoveryBit(b){return new h(this.r,this.s,b)}recoverPublicKey(b){let S=s.ORDER,{r:B,s:A,recovery:C}=this;if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");if(a*Hf<S&&C>1)throw new Error("recovery id is ambiguous for h>1 curve");let L=C===2||C===3?B+a:B;if(!s.isValid(L))throw new Error("recovery id 2 or 3 invalid");let $=s.toBytes(L),U=r.fromHex(pt(xa((C&1)===0),$)),k=i.inv(L),Z=v(F("msgHash",b)),W=i.create(-Z*k),et=i.create(A*k),K=r.BASE.multiplyUnsafe(W).add(U.multiplyUnsafe(et));if(K.is0())throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return u(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i.neg(this.s),this.recovery):this}toBytes(b){if(b==="compact")return pt(i.toBytes(this.r),i.toBytes(this.s));if(b==="der")return Ce(zt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Ct(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Ct(this.toBytes("compact"))}}let m=ba(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),x={isValidPrivateKey(g){try{return m(g),!0}catch{return!1}},normPrivateKeyToScalar:m,randomPrivateKey:()=>{let g=a;return $i(n(Po(g)),g)},precompute(g=8,b=r.BASE){return b.precompute(g,!1)}};function w(g,b=!0){return r.fromPrivateKey(g).toBytes(b)}function p(g){if(typeof g=="bigint")return!1;if(g instanceof r)return!0;let S=F("key",g).length,B=s.BYTES,A=B+1,C=2*B+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===A))return S===A||S===C}function _(g,b,S=!0){if(p(g)===!0)throw new Error("first arg must be private key");if(p(b)===!1)throw new Error("second arg must be public key");return r.fromHex(b).multiply(m(g)).toBytes(S)}let D=t.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");let b=Te(g),S=g.length*8-c;return S>0?b>>BigInt(S):b},v=t.bits2int_modN||function(g){return i.create(D(g))},R=ie(c);function y(g){return jt("num < 2^"+c,g,yr,R),i.toBytes(g)}function P(g,b,S=T){if(["recovered","canonical"].some(et=>et in S))throw new Error("sign() legacy options not supported");let{hash:B}=t,{lowS:A,prehash:C,extraEntropy:O}=S;A==null&&(A=!0),g=F("msgHash",g),ya(S),C&&(g=F("prehashed msgHash",B(g)));let L=v(g),$=m(b),U=[y($),y(L)];if(O!=null&&O!==!1){let et=O===!0?n(s.BYTES):O;U.push(F("extraEntropy",et))}let k=pt(...U),Z=L;function W(et){let K=D(et);if(!i.isValidNot0(K))return;let it=i.inv(K),Ze=r.BASE.multiply(K).toAffine(),be=i.create(Ze.x);if(be===yr)return;let Jt=i.create(it*i.create(Z+be*$));if(Jt===yr)return;let Gn=(Ze.x===be?0:2)|Number(Ze.y&br),xe=Jt;return A&&u(Jt)&&(xe=f(Jt),Gn^=1),new h(be,xe,Gn)}return{seed:k,k2sig:W}}let T={lowS:t.lowS,prehash:!1},I={lowS:t.lowS,prehash:!1};function d(g,b,S=T){let{seed:B,k2sig:A}=P(g,b,S);return Ni(t.hash.outputLen,i.BYTES,o)(B,A)}r.BASE.precompute(8);function E(g,b,S,B=I){let A=g;b=F("msgHash",b),S=F("publicKey",S),ya(B);let{lowS:C,prehash:O,format:L}=B;if("strict"in B)throw new Error("options.strict was renamed to lowS");if(L!==void 0&&!["compact","der","js"].includes(L))throw new Error('format must be "compact", "der" or "js"');let $=typeof A=="string"||Be(A),U=!$&&!L&&typeof A=="object"&&A!==null&&typeof A.r=="bigint"&&typeof A.s=="bigint";if(!$&&!U)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let k,Z;try{if(U)if(L===void 0||L==="js")k=new h(A.r,A.s);else throw new Error("invalid format");if($){try{L!=="compact"&&(k=h.fromDER(A))}catch(xe){if(!(xe instanceof zt.Err))throw xe}!k&&L!=="der"&&(k=h.fromCompact(A))}Z=r.fromHex(S)}catch{return!1}if(!k||C&&k.hasHighS())return!1;O&&(b=t.hash(b));let{r:W,s:et}=k,K=v(b),it=i.inv(et),Ze=i.create(K*it),be=i.create(W*it),Jt=r.BASE.multiplyUnsafe(Ze).add(Z.multiplyUnsafe(be));return Jt.is0()?!1:i.create(Jt.x)===W}return Object.freeze({getPublicKey:w,getSharedSecret:_,sign:d,verify:E,utils:x,Point:r,Signature:h})}function jf(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=vt(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function Wf(r){let{CURVE:t,curveOpts:e}=jf(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function Xf(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function wa(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=Wf(r),o=$f(t,e),s=Zf(o,n,e);return Xf(r,s)}function Ea(r,t){let e=n=>wa({...r,hash:n});return{...e(t),create:e}}var sn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},om=BigInt(0),Yf=BigInt(1),os=BigInt(2),Sa=(r,t)=>(r+t/os)/t;function Qf(r){let t=sn.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,f=u*u*r%t,l=q(f,e,t)*f%t,h=q(l,e,t)*f%t,m=q(h,os,t)*u%t,x=q(m,o,t)*m%t,w=q(x,s,t)*x%t,p=q(w,a,t)*w%t,_=q(p,c,t)*p%t,D=q(_,a,t)*w%t,v=q(D,e,t)*f%t,R=q(v,i,t)*x%t,y=q(R,n,t)*u%t,P=q(y,os,t);if(!ss.eql(ss.sqr(P),r))throw new Error("Cannot find square root");return P}var ss=vt(sn.p,void 0,void 0,{sqrt:Qf}),Ue=Ea({...sn,Fp:ss,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=sn.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Yf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Sa(s*r,t),c=Sa(-n*r,t),u=V(r-a*e-c*o,t),f=V(-a*n-c*s,t),l=u>i,h=f>i;if(l&&(u=t-u),h&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:u,k2neg:h,k2:f}}}},Pi);function _a(r,t,e,n){let o=tr.digest(e instanceof Uint8Array?e:e.subarray());if(Yr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ue.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new dr(String(s))});try{return n?.signal?.throwIfAborted(),Ue.verify(t,o.digest,r)}catch(s){throw new dr(String(s))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=Aa(t),this.raw=va(this._key)}toMultihash(){return St.digest(Ae(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){return _a(this._key,e,t,n)}};function Ia(r){return new an(r)}function va(r){return Ue.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Aa(r){try{return Ue.ProjectivePoint.fromHex(r),r}catch(t){throw new Pr(String(t))}}function Ba(r){let{Type:t,Data:e}=gr.decode(r.digest),n=e??new Uint8Array;switch(t){case gt.Ed25519:return ia(n);case gt.secp256k1:return Ia(n);case gt.ECDSA:return di(n);default:throw new je}}function Ae(r){return gr.encode({Type:gt[r.type],Data:r.raw})}var Da=Symbol.for("nodejs.util.inspect.custom"),Jf=114,xr=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()})`}[$n]=!0;toString(){return this.string==null&&(this.string=H.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return X.createV1(Jf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return at(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return at(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Da](){return`PeerId(${this.toString()})`}},cn=class extends xr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},un=class extends xr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},fn=class extends xr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},tl=2336,ln=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=St.digest(M(this.url))}[Da](){return`PeerId(${this.url})`}[$n]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return X.createV1(tl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function Ca(r){if(rl(r))return new cn({multihash:r});if(el(r))try{let t=Ba(r);if(t.type==="Ed25519")return new un({multihash:r,publicKey:t});if(t.type==="secp256k1")return new fn({multihash:r,publicKey:t})}catch{let e=z(r.digest);return new ln(new URL(e))}throw new Rr("Supplied PeerID Multihash is invalid")}function el(r){return r.code===St.code}function rl(r){return r.code===tr.code}function is(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 dn(r){let t=Qe(H.decode(`z${r}`));return Ca(t)}var hn=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 is(this.set.entries(),t=>{let e=dn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=dn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return is(this.set.values(),t=>dn(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 as(){return new hn}var cs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ta={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Pa=new globalThis.TextEncoder;function nl(r,t){let e=cs[t],n=Ta[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function ol(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=cs[t],o=Ta[t],s=r;for(;s.length>0;){let i=Pa.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 us(r,{size:t=32,utf8Buffer:e}={}){if(!cs[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 ol(r,t,e);r=Pa.encode(r)}return nl(r,t)}var wr={hash:r=>Number(us(r,{size:32})),hashV:(r,t)=>sl(wr.hash(r,t))};function sl(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),M(t,"base16")}var fs=64,It=class{fp;h;seed;constructor(t,e,n,o=2){if(o>fs)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=ht(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?at(this.fp,t.fp):!1}};function de(r,t){return Math.floor(Math.random()*(t-r))+r}var he=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=de(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 il=500,Er=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??wr,this.seed=t.seed??de(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=M(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 he(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new he(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[de(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new he(this.bucketSize));for(let a=0;a<il;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new he(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=M(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=M(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}},al={1:.5,2:.84,4:.95,8:.98};function cl(r=.001){return r>.002?2:r>1e-5?4:8}function Ra(r,t=.001){let e=cl(t),n=al[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),fs);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var pn=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??wr,this.seed=t.seed??de(0,Math.pow(2,10)),this.filterSeries=[new Er({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=M(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 Er({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=M(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=M(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 ls(r,t=.001,e){return new pn({...Ra(r,t),...e??{}})}var mn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,t);if(!Number.isNaN(h))return h});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var La=45,ul=15,Me=new mn;function gn(r){if(!(r.length>ul))return Me.new(r).parseWith(()=>Me.readIPv4Addr())}function yn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>La))return Me.new(r).parseWith(()=>Me.readIPv6Addr())}function Ke(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>La)return;let e=Me.new(r).parseWith(()=>Me.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 Oa(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 ka(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function ds(r){switch(r.length){case pe:return r.join(".");case me:{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 Na(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function Ua(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var pe=4,me=16,Vg=parseInt("0xFFFF",16),fl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Sr(r,t){t.length===me&&r.length===pe&&Oa(t,0,11)&&(t=t.slice(12)),t.length===pe&&r.length===me&&ka(r,fl,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 Ma(r,t){if(typeof t=="string"&&(t=Ke(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 hs(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=pe,o=gn(t);if(o==null&&(n=me,o=yn(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=ps(s,8*n);return{network:Sr(o,i),mask:i}}function ps(r,t){if(t!==8*pe&&t!==8*me)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 ze=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=hs(t));else{let n=Ke(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=Ke(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ps(o,8*n.length);this.network=Sr(n,this.mask)}}contains(t){return Ma({network:this.network,mask:this.mask},t)}toString(){let t=Na(this.mask),e=t!==-1?String(t):Ua(this.mask);return ds(this.network)+"/"+e}};function Ka(r,t){return new ze(r).contains(t)}var tt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ft=class extends Error{static name="ValidationError";name="ValidationError"},_r=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},bn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Fe(r){return!!gn(r)}function xn(r){return!!yn(r)}function gs(r){return t=>z(t,r)}function ys(r){return t=>M(t,r)}function qe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ge(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function za(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=M(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ge(n);return kt([e,o],e.length+o.length)}function Fa(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=Vt.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=ge(n);return kt([e,o],e.length+o.length)}function bs(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=z(t,"base32"),o=qe(e);return`${n}:${o}`}var xs=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new tt("Invalid byte value in IP address");t[n]=o}),t},qa=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Fe(e[n]),i;s&&(i=xs(e[n]),e[n]=z(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,z(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new tt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ha=function(r){if(r.byteLength!==4)throw new tt("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Va=function(r){if(r.byteLength!==16)throw new tt("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new tt(`Invalid IPv6 address "${e}"`)}};function Ga(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new tt(`Invalid IPv6 address "${r}"`)}}var ms=Object.values(er).map(r=>r.decoder),ll=function(){let r=ms[0].or(ms[1]);return ms.slice(2).forEach(t=>r=r.or(t)),r}();function $a(r){return ll.decode(r)}function Za(r){return t=>r.encoder.encode(t)}function dl(r){if(parseInt(r).toString()!==r)throw new Ft("Value must be an integer")}function hl(r){if(r<0)throw new Ft("Value must be a positive integer, or zero")}function pl(r){return t=>{if(t>r)throw new Ft(`Value must be smaller than or equal to ${r}`)}}function ml(...r){return t=>{for(let e of r)e(t)}}var vr=ml(dl,hl,pl(65535));var Q=-1,ws=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new bn(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},yt=new ws,Gl=[{code:4,name:"ip4",size:32,valueToBytes:xs,bytesToValue:Ha,validate:r=>{if(!Fe(r))throw new Ft(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ge,bytesToValue:qe,validate:vr},{code:273,name:"udp",size:16,valueToBytes:ge,bytesToValue:qe,validate:vr},{code:33,name:"dccp",size:16,valueToBytes:ge,bytesToValue:qe,validate:vr},{code:41,name:"ip6",size:128,valueToBytes:qa,bytesToValue:Va,stringToValue:Ga,validate:r=>{if(!xn(r))throw new Ft(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:Q},{code:43,name:"ipcidr",size:8,bytesToValue:gs("base10"),valueToBytes:ys("base10")},{code:53,name:"dns",size:Q,resolvable:!0},{code:54,name:"dns4",size:Q,resolvable:!0},{code:55,name:"dns6",size:Q,resolvable:!0},{code:56,name:"dnsaddr",size:Q,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:ge,bytesToValue:qe,validate:vr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:Q,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:Q,bytesToValue:gs("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ys("base58btc")(r):X.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:bs,valueToBytes:za},{code:445,name:"onion3",size:296,bytesToValue:bs,valueToBytes:Fa},{code:446,name:"garlic64",size:Q},{code:447,name:"garlic32",size:Q},{code:448,name:"tls"},{code:449,name:"sni",size:Q},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:Q,bytesToValue:Za(ao),valueToBytes:$a},{code:480,name:"http"},{code:481,name:"http-path",size:Q,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:Q}];Gl.forEach(r=>{yt.addProtocol(r)});function ja(r){let t=[],e=0;for(;e<r.length;){let n=hr(r,e),o=yt.getProtocol(n),s=lt(n),i=$l(o,r,e+s),a=0;i>0&&o.size===Q&&(a=lt(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let f=e+s+a,l=r.subarray(f,f+i);u.value=o.bytesToValue?.(l)??z(l)}t.push(u),e+=c}return t}function Wa(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=yt.getProtocol(n.code),s=lt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??M(n.value),a=i.byteLength,o.size===Q&&(c=lt(a)));let u=new Uint8Array(s+c+a),f=0;ke(n.code,u,f),f+=s,i!=null&&(o.size===Q&&(ke(a,u,f),f+=c),u.set(i,f)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return kt(e,t)}function Xa(r){if(r.charAt(0)!=="/")throw new tt('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=yt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new tt(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new tt(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new tt("Incomplete multiaddr");return t}function Ya(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=yt.getProtocol(t.code);if(e==null)throw new tt(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function $l(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:hr(t,e)}var Zl=Symbol.for("nodejs.util.inspect.custom"),Bs=Symbol.for("@multiformats/multiaddr"),jl=[53,54,55,56],Is=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Wl(r){if(r==null&&(r="/"),Ja(r))return r.getComponents();if(r instanceof Uint8Array)return ja(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Xa(r);if(Array.isArray(r))return r;throw new tt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var _n=class r{[Bs]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Wl(t),e.validate!==!1&&Xl(this)}get bytes(){return this.#r==null&&(this.#r=Wa(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Ya(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:c,value:u}of this.#t)a===42&&(s=`%${u??""}`),jl.includes(a)&&(e="tcp",o=443,n=`${u??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=c==="tcp"?"tcp":"udp",o=parseInt(u??"")),(a===4||a===41)&&(e="tcp",n=`${u??""}${s}`,t=a===41?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}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=yt.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=yt.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??M(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new _r(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?z(H.decode(`z${n}`),"base58btc"):z(X.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(yt.getProtocol(t.code).path)return t.value??null;return null}equals(t){return at(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Qa.get(e.name);if(n==null)throw new Is(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Ir(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(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[Zl](){return`Multiaddr(${this.toString()})`}};function Xl(r){r.getComponents().forEach(t=>{let e=yt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}var Qa=new Map;function Ja(r){return!!r?.[Bs]}function Ir(r){return new _n(r)}function tc(r){try{for(let{code:t,value:e}of r.getComponents())if(e!=null&&t===41)return Ka("2000::/3",e)}catch{}return!1}var rc=Ic(ec(),1),Yl=["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"],Ql=Yl.map(r=>new rc.Netmask(r));function Ds(r){for(let t of Ql)if(t.contains(r))return!0;return!1}function Jl(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function td(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 Ds(o)}function ed(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function rd(r){let t=r.split(":"),e=t[t.length-1];return Ds(e)}function nd(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 vn(r){if(Fe(r))return Ds(r);if(Jl(r))return td(r);if(ed(r))return rd(r);if(xn(r))return nd(r)}function nc(r){try{for(let{code:t}of r.getComponents())if(t!==42)return t===4||t===41}catch{}return!1}function oc(r){try{if(!nc(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:vn(t)??!1}catch{}return!0}function Dt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var An=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},He=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new An(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 An(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 Cs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function sc(r={}){return od(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 od(r,t){t=t??{};let e=t.onEnd,n=new He,o,s,i,a=Dt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,_)=>{s=D=>{s=null,n.push(D);try{p(r(n))}catch(v){_(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Dt()})}},u=p=>s!=null?s(p):(n.push(p),o),f=p=>(n=new He,s!=null?s({error:p}):(n.push({error:p}),o)),l=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},h=p=>i?o:(i=!0,p!=null?f(p):u({done:!0})),m=()=>(n=new He,h(),{done:!0}),x=p=>(h(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:x,push:l,end:h,get readableLength(){return n.size},onEmpty:async p=>{let _=p?.signal;if(_?.throwIfAborted(),n.isEmpty())return;let D,v;_!=null&&(D=new Promise((R,y)=>{v=()=>{y(new Cs)},_.addEventListener("abort",v)}));try{await Promise.race([a.promise,D])}finally{v!=null&&_!=null&&_?.removeEventListener("abort",v)}}},e==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(p){return w.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return w.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(p){return w.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return w.readableLength},onEmpty:p=>w.onEmpty(p)},o}var Ts=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 In(r,t,e,n){let o=new Ts(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",f),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let c=l=>{try{if(n?.filter?.(l)===!1)return}catch(h){a(),i(h);return}a(),s(l)},u=l=>{a(),i(l.detail)},f=()=>{a(),i(o)};e?.addEventListener("abort",f),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}function Dr(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Bn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Dn=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 ye(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Dn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Dn(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 Cn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Dt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Rt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function sd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Tn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=sd(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,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 Rt),this.cleanup())}async join(t={}){let e=new Cn(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 ye(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 Pn=class extends Lr{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=[],this.emitEmpty=Dr(this.emitEmpty.bind(this),1),this.emitIdle=Dr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Bn;let n=new Tn(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 Rt)}),this.clear()}async onEmpty(t){this.size!==0&&await In(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await In(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await In(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=sc({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 Rt("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 Rn=class extends Pn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Cr(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 ic(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal};if(e?.timeout!=null){let f=Cr([o.signal,AbortSignal.timeout(e.timeout)]);u.signal=f}s=!0,Promise.resolve().then(async()=>{await r(u)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Dr(i,e?.debounce??100),c=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{e??={},e.timeout=u},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var Ps=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ac(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ps({name:t,metrics:e}):n=new Map,n}var Rs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Dt(),this.haveNext=Dt()}[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=Dt(),t}async throw(t){return this.ended=!0,this.error=t,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 this.ended=!0,this.nextResult=t,this.haveNext.resolve(),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 this.error??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=Dt(),await ye(this.readNext.promise,e?.signal,e)}};function cc(){return new Rs}var Ln=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function uc(r,t){let e=cc();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 j;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:c,value:u}=await ye(n.next(),i?.signal);return c===!0?null:u}for(;o.byteLength<i.bytes;){let{value:c,done:u}=await ye(n.next(),i?.signal);if(u===!0)throw new Ln("unexpected end of input");o.append(c)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},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 On=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},kn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Nn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function fc(r,t={}){let e=uc(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=lt(t.maxDataLength));let n=t?.lengthDecoder??hr,o=t?.lengthEncoder??aa;return{read:async i=>{let a=-1,c=new j;for(;;){c.append(await e.read({...i,bytes:1}));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new On("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Nn("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new kn("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new j(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new j(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function Ve(r,t){let e=fc(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 Ls="libp2p",Os="autonat",ks="2";var lc="dial-request",dc="dial-back",hc=200n*1024n,pc=4096;var Ge;(function(r){let t;r.codec=()=>(t==null&&(t=Et((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e={...e},e.dialDataResponse!=null&&(e.dialDataRequest=void 0,e.dialResponse=void 0,e.dialRequest=void 0),e.dialDataRequest!=null&&(e.dialDataResponse=void 0,e.dialResponse=void 0,e.dialRequest=void 0),e.dialResponse!=null&&(e.dialDataResponse=void 0,e.dialDataRequest=void 0,e.dialRequest=void 0),e.dialRequest!=null&&(e.dialDataResponse=void 0,e.dialDataRequest=void 0,e.dialResponse=void 0),e.dialRequest!=null&&(n.uint32(10),Un.codec().encode(e.dialRequest,n)),e.dialResponse!=null&&(n.uint32(18),qt.codec().encode(e.dialResponse,n)),e.dialDataRequest!=null&&(n.uint32(26),Mn.codec().encode(e.dialDataRequest,n)),e.dialDataResponse!=null&&(n.uint32(34),zn.codec().encode(e.dialDataResponse,n)),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.dialRequest=Un.codec().decode(e,e.uint32(),{limits:o.limits?.dialRequest});break}case 2:{s.dialResponse=qt.codec().decode(e,e.uint32(),{limits:o.limits?.dialResponse});break}case 3:{s.dialDataRequest=Mn.codec().decode(e,e.uint32(),{limits:o.limits?.dialDataRequest});break}case 4:{s.dialDataResponse=zn.codec().decode(e,e.uint32(),{limits:o.limits?.dialDataResponse});break}default:{e.skipType(a&7);break}}}return s.dialDataResponse!=null&&(delete s.dialDataRequest,delete s.dialResponse,delete s.dialRequest),s.dialDataRequest!=null&&(delete s.dialDataResponse,delete s.dialResponse,delete s.dialRequest),s.dialResponse!=null&&(delete s.dialDataResponse,delete s.dialDataRequest,delete s.dialRequest),s.dialRequest!=null&&(delete s.dialDataResponse,delete s.dialDataRequest,delete s.dialResponse),s})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(Ge||(Ge={}));var Un;(function(r){let t;r.codec=()=>(t==null&&(t=Et((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.addrs!=null)for(let s of e.addrs)n.uint32(10),n.bytes(s);e.nonce!=null&&e.nonce!==0n&&(n.uint32(17),n.fixed64(e.nonce)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={addrs:[],nonce:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(o.limits?.addrs!=null&&s.addrs.length===o.limits.addrs)throw new rn('Decode error - map field "addrs" had too many elements');s.addrs.push(e.bytes());break}case 2:{s.nonce=e.fixed64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(Un||(Un={}));var Mn;(function(r){let t;r.codec=()=>(t==null&&(t=Et((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.addrIdx!=null&&e.addrIdx!==0&&(n.uint32(8),n.uint32(e.addrIdx)),e.numBytes!=null&&e.numBytes!==0n&&(n.uint32(16),n.uint64(e.numBytes)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={addrIdx:0,numBytes:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.addrIdx=e.uint32();break}case 2:{s.numBytes=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(Mn||(Mn={}));var st;(function(r){r.UNUSED="UNUSED",r.E_DIAL_ERROR="E_DIAL_ERROR",r.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",r.OK="OK"})(st||(st={}));var Kn;(function(r){r[r.UNUSED=0]="UNUSED",r[r.E_DIAL_ERROR=100]="E_DIAL_ERROR",r[r.E_DIAL_BACK_ERROR=101]="E_DIAL_BACK_ERROR",r[r.OK=200]="OK"})(Kn||(Kn={}));(function(r){r.codec=()=>le(Kn)})(st||(st={}));var qt;(function(r){let t;(function(o){o.E_INTERNAL_ERROR="E_INTERNAL_ERROR",o.E_REQUEST_REJECTED="E_REQUEST_REJECTED",o.E_DIAL_REFUSED="E_DIAL_REFUSED",o.OK="OK"})(t=r.ResponseStatus||(r.ResponseStatus={}));let e;(function(o){o[o.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",o[o.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",o[o.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",o[o.OK=200]="OK"})(e||(e={})),function(o){o.codec=()=>le(e)}(t=r.ResponseStatus||(r.ResponseStatus={}));let n;r.codec=()=>(n==null&&(n=Et((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.status!=null&&e[o.status]!==0&&(s.uint32(8),r.ResponseStatus.codec().encode(o.status,s)),o.addrIdx!=null&&o.addrIdx!==0&&(s.uint32(16),s.uint32(o.addrIdx)),o.dialStatus!=null&&Kn[o.dialStatus]!==0&&(s.uint32(24),st.codec().encode(o.dialStatus,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:st.UNUSED},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.status=r.ResponseStatus.codec().decode(o);break}case 2:{a.addrIdx=o.uint32();break}case 3:{a.dialStatus=st.codec().decode(o);break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>wt(o,r.codec()),r.decode=(o,s)=>xt(o,r.codec(),s)})(qt||(qt={}));var zn;(function(r){let t;r.codec=()=>(t==null&&(t=Et((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.data!=null&&e.data.byteLength>0&&(n.uint32(10),n.bytes(e.data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={data:ht(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(zn||(zn={}));var $e;(function(r){let t;r.codec=()=>(t==null&&(t=Et((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.nonce!=null&&e.nonce!==0n&&(n.uint32(9),n.fixed64(e.nonce)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={nonce:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.nonce=e.fixed64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})($e||($e={}));var Qt;(function(r){let t;(function(o){o.OK="OK"})(t=r.DialBackStatus||(r.DialBackStatus={}));let e;(function(o){o[o.OK=0]="OK"})(e||(e={})),function(o){o.codec=()=>le(e)}(t=r.DialBackStatus||(r.DialBackStatus={}));let n;r.codec=()=>(n==null&&(n=Et((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.status!=null&&e[o.status]!==0&&(s.uint32(8),r.DialBackStatus.codec().encode(o.status,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={status:t.OK},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.status=r.DialBackStatus.codec().decode(o);break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>wt(o,r.codec()),r.decode=(o,s)=>xt(o,r.codec(),s)})(Qt||(Qt={}));function Fn(r,t){return Math.round(Math.random()*(t-r)+r)}var ad=4,cd=8,qn=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:client"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.connectionThreshold=e.connectionThreshold??80,this.maxMessageSize=e.maxMessageSize??8192,this.dialResults=ac({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=ic(this.findRandomPeers.bind(this),6e4),this.addressFilter=ls(1024),this.queue=new Rn({concurrency:3,maxSize:50}),this.maxDialDataBytes=e.maxDialDataBytes??hc,this.dialDataChunkSize=e.dialDataChunkSize??pc,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[Or]=["@libp2p/autonat"];get[kr](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.components.registrar.register(this.dialRequestProtocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),await this.components.registrar.handle(this.dialBackProtocol,t=>{this.handleDialBackStream(t).catch(e=>{this.log.error("error handling incoming autonat stream - %e",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),await this.components.registrar.unhandle(this.dialBackProtocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=Cr([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleDialBackStream(t){let e=AbortSignal.timeout(this.timeout);let n=Ve(t.stream,{maxDataLength:this.maxMessageSize});try{let o=await n.read($e,{signal:e});if(!this.nonces.has(o.nonce))throw new bt("No matching dial found for nonce value");this.nonces.delete(o.nonce),await n.write({status:Qt.DialBackStatus.OK},Qt),await t.stream.close({signal:e})}catch(o){this.log.error("error handling incoming dial back stream - %e",o),t.stream.abort(o)}}getUnverifiedMultiaddrs(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((s,i)=>s.type==="observed"&&i.type!=="observed"?1:i.type==="observed"&&s.type!=="observed"?-1:0).filter(s=>!(!(s.expires<Date.now())||s.multiaddr.toOptions().family===6&&(!e||!tc(s.multiaddr))||oc(s.multiaddr))),o=[];for(let s of n){let i=s.multiaddr.toString(),a=this.dialResults.get(i);if(a!=null&&a.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",a.multiaddr,t);continue}if(a==null){let c=s.expires<Date.now();if(c&&this.addressFilter.remove?.(i),this.addressFilter.has(i))continue;this.addressFilter.add(i),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",i),a={multiaddr:s.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:as(),type:s.type,lastVerified:s.lastVerified},this.dialResults.set(i,a)}o.push(a)}return o}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>i.toOptions().family===6),o=this.getNetworkSegment(t.remoteAddr),s=this.getUnverifiedMultiaddrs(o,n);if(s.length!==0){if(!this.hasConnectionCapacity()){s[0]?.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s[0].multiaddr),this.confirmAddress(s[0])):this.log("skipping verifying %a because we are too close to the connection limit",s[0]?.multiaddr);return}this.queue.add(async i=>{let a=Cr([i.signal,AbortSignal.timeout(this.timeout)]),c=BigInt(Fn(0,Number.MAX_SAFE_INTEGER));this.nonces.add(c);try{await this.askPeerToVerify(t,o,c,i)}finally{a.clear(),this.nonces.delete(c)}},{peerId:t.remotePeer}).catch(i=>{this.log.error("error from %p verifying addresses - %e",t.remotePeer,i)})}}async askPeerToVerify(t,e,n,o){let s=[...this.dialResults.values()].filter(a=>a.result==null).map(a=>a.multiaddr);if(s.length===0){this.queue.clear();return}this.log.trace("asking %p to verify multiaddrs %s",t.remotePeer,s);let i=await t.newStream(this.dialRequestProtocol,o);try{let a=Ve(i).pb(Ge);for(await a.write({dialRequest:{addrs:s.map(c=>c.bytes),nonce:n}},o);;){let c=await a.read(o);if(c.dialDataRequest!=null){if(c.dialDataRequest.numBytes>this.maxDialDataBytes){this.log("too many dial data byte requested by %p - %s/%s",t.remotePeer,c.dialDataRequest.numBytes,this.maxDialDataBytes);continue}this.log("sending %d bytes to %p as anti-amplification attack protection",c.dialDataRequest.numBytes,t.remotePeer);let h=new Uint8Array(this.dialDataChunkSize),m=BigInt(this.dialDataChunkSize);for(let x=0n;x<c.dialDataRequest.numBytes;x+=m)await a.write({dialDataResponse:{data:h}},o);c=await a.read(o)}if(c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}if(c.dialResponse.status!==qt.ResponseStatus.OK)return;let f=s[c.dialResponse.addrIdx];if(f==null){this.log.trace("peer dialed unknown address");continue}let l=this.dialResults.get(f.toString());if(l==null){this.log.trace("peer reported %a as %s but there is no result object",f,c.dialResponse.status);continue}if(l.networkSegments.includes(e)){this.log.trace("%a results already included network segment %s",f,e);continue}if(l.result!=null){this.log.trace("already resolved result for %a, ignoring response from",f,t.remotePeer);continue}if(l.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,f);continue}if(l.verifyingPeers.add(t.remotePeer),l.networkSegments.push(e),c.dialResponse.dialStatus===st.OK){if(this.log.trace("%p dialed %a successfully",t.remotePeer,l.multiaddr),l.success++,l.type!=="observed"){this.confirmAddress(l);continue}}else if(c.dialResponse.dialStatus===st.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,l.multiaddr),l.failure++;else if(c.dialResponse.dialStatus===st.E_DIAL_BACK_ERROR){this.log.trace("%p saw error while dialing %a",t.remotePeer,l.multiaddr);continue}this.log("%a success %d failure %d",l.multiaddr,l.success,l.failure),l.success===ad&&this.confirmAddress(l),l.failure===cd&&this.unconfirmAddress(l)}}finally{try{await i.close(o)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1}getNetworkSegment(t){let e=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};var Hn=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:server"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.maxMessageSize=e.maxMessageSize??8192}async start(){this.started||(await this.components.registrar.handle(this.dialRequestProtocol,t=>{this.handleDialRequestStream(t).catch(e=>{this.log.error("error handling incoming autonat stream - %e",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),this.started=!1}async handleDialRequestStream(t){let e=AbortSignal.timeout(this.timeout);let n=Ve(t.stream,{maxDataLength:this.maxMessageSize}).pb(Ge);try{let o=xc(t.connection.remoteAddr);if(o==null)throw new bt(`Could not find IP address in connection address "${t.connection.remoteAddr}"`);let{dialRequest:s}=await n.read({signal:e});if(s==null)throw new bt("Did not receive DialRequest message on incoming dial request stream");if(s.addrs.length===0)throw new bt("Did not receive any addresses to dial");for(let i=0;i<s.addrs.length;i++)try{let a=Ir(s.addrs[i]);if(!await this.components.connectionManager.isDialable(a,{signal:e})){await n.write({dialResponse:{addrIdx:i,status:qt.ResponseStatus.E_DIAL_REFUSED,dialStatus:st.UNUSED}},{signal:e});continue}let u=xc(a);if(u==null)throw new bt(`Could not find IP address in requested address "${a}"`);if(vn(u))throw new bt(`Requested address had private IP "${a}"`);u!==o&&await this.preventAmplificationAttack(n,i,{signal:e});let f=await this.dialClientBack(a,s.nonce,{signal:e});await n.write({dialResponse:{addrIdx:i,status:qt.ResponseStatus.OK,dialStatus:f}},{signal:e})}catch(a){this.log.error("could not parse multiaddr - %e",a)}await t.stream.close({signal:e})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.stream.abort(o)}}async preventAmplificationAttack(t,e,n){let o=Fn(3e4,1e5);await t.write({dialDataRequest:{addrIdx:e,numBytes:BigInt(o)}},n);let s=0;for(;s<o;){let{dialDataResponse:i}=await t.read(n);if(i==null)throw new bt("Did not receive DialDataResponse message on incoming dial request stream");s+=i.data.byteLength}}async dialClientBack(t,e,n){let o;try{o=await this.components.connectionManager.openConnection(t,{force:!0,...n})}catch(s){return this.log.error("failed to open connection to %a - %e",s,t),st.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=Ve(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:e},$e,n),(await i.read(Qt)).status!==Qt.DialBackStatus.OK)throw new bt("DialBackResponse status was not OK");await o.close(n)}catch(s){return this.log.error("could not perform dial back - %e",s),o.abort(s),st.E_DIAL_BACK_ERROR}return st.OK}};function xc(r){return r.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var Vn=class{client;server;constructor(t,e){let n=`/${e.protocolPrefix??Ls}/${Os}/${ks}/${lc}`,o=`/${e.protocolPrefix??Ls}/${Os}/${ks}/${dc}`;this.client=new qn(t,{...e,dialRequestProtocol:n,dialBackProtocol:o}),this.server=new Hn(t,{...e,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[Or]=["@libp2p/autonat"];get[kr](){return["@libp2p/identify"]}async start(){await Ms(this.client,this.server)}async stop(){await Ks(this.client,this.server)}};function ud(r={}){return t=>new Vn(t,r)}return Bc(fd);})();
|
|
2
|
+
"use strict";var Libp2PAutonatV2=(()=>{var $c=Object.create;var Vr=Object.defineProperty;var Gc=Object.getOwnPropertyDescriptor;var Zc=Object.getOwnPropertyNames;var jc=Object.getPrototypeOf,Xc=Object.prototype.hasOwnProperty;var Wc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),yt=(r,t)=>{for(var e in t)Vr(r,e,{get:t[e],enumerable:!0})},ci=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Zc(t))!Xc.call(r,o)&&o!==e&&Vr(r,o,{get:()=>t[o],enumerable:!(n=Gc(t,o))||n.enumerable});return r};var Yc=(r,t,e)=>(e=r!=null?$c(jc(r)):{},ci(t||!r||!r.__esModule?Vr(e,"default",{value:r,enumerable:!0}):e,r)),Qc=r=>ci(Vr({},"__esModule",{value:!0}),r);var Dc=Wc(Kr=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,d,l,f;return u=(c&255<<24)>>>24,d=(c&255<<16)>>>16,l=(c&65280)>>>8,f=c&255,[u,d,l,f].join(".")},i=function(c){var u,d,l,f,h,p;for(u=[],l=f=0;f<=3&&c.length!==0;l=++f){if(l>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}p=t(c),h=p[0],d=p[1],c=c.substring(d),u.push(h)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[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 u,d,l,f,h;for(f=0,u=10,d="9",l=0,c.length>1&&c[l]==="0"&&(c[l+1]==="x"||c[l+1]==="X"?(l+=2,u=16):"0"<=c[l+1]&&c[l+1]<="9"&&(l++,u=8,d="7")),h=l;l<c.length;){if("0"<=c[l]&&c[l]<=d)f=f*u+(e(c[l])-n)>>>0;else if(u===16)if("a"<=c[l]&&c[l]<="f")f=f*u+(10+e(c[l])-s)>>>0;else if("A"<=c[l]&&c[l]<="F")f=f*u+(10+e(c[l])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");l++}if(l===h)throw new Error("empty octet");return[f,l]},r=(function(){function c(u,d){var l,f,h,p;if(typeof u!="string")throw new Error("Missing `net' parameter");if(d||(p=u.split("/",2),u=p[0],d=p[1]),d||(d=32),typeof d=="string"&&d.indexOf(".")>-1){try{this.maskLong=i(d)}catch(w){throw l=w,new Error("Invalid mask: "+d)}for(f=h=32;h>=0;f=--h)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;break}}else if(d||d===0)this.bitmask=parseInt(d,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(u)&this.maskLong)>>>0}catch(w){throw l=w,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+d);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(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var d,l,f;for(f=i(this.first),l=i(this.last),d=0;f<=l;)u(a(f),f,d),d++,f++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c})(),Kr.ip2long=i,Kr.long2ip=a,Kr.Netmask=r}).call(Kr)});var Wd={};yt(Wd,{autoNATv2:()=>Xd});var Nt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Ct=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Hr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var $r=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var _t=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var ir=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var to=Symbol.for("@libp2p/peer-id");function ui(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function fi(...r){let t=[];for(let e of r)ui(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(t.map(async e=>{await e.start()})),await Promise.all(t.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function li(...r){let t=[];for(let e of r)ui(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(t.map(async e=>{await e.stop()})),await Promise.all(t.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var Gr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){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 Zr=Symbol.for("@libp2p/service-capabilities"),jr=Symbol.for("@libp2p/service-dependencies");var so={};yt(so,{base58btc:()=>G,base58flickr:()=>su});var Dh=new Uint8Array(0);function di(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 Ut(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 hi(r){return new TextEncoder().encode(r)}function pi(r){return new TextDecoder().decode(r)}function Jc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function l(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 w=0,S=0,y=0,_=p.length;y!==_&&p[y]===0;)y++,w++;for(var x=(_-y)*d+1>>>0,D=new Uint8Array(x);y!==_;){for(var R=p[y],M=0,U=x-1;(R!==0||M<S)&&U!==-1;U--,M++)R+=256*D[U]>>>0,D[U]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");S=M,y++}for(var O=x-S;O!==x&&D[O]===0;)O++;for(var E=c.repeat(w);O<x;++O)E+=r.charAt(D[O]);return E}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var w=0;if(p[w]!==" "){for(var S=0,y=0;p[w]===c;)S++,w++;for(var _=(p.length-w)*u+1>>>0,x=new Uint8Array(_);p[w];){var D=e[p.charCodeAt(w)];if(D===255)return;for(var R=0,M=_-1;(D!==0||R<y)&&M!==-1;M--,R++)D+=a*x[M]>>>0,x[M]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");y=R,w++}if(p[w]!==" "){for(var U=_-y;U!==_&&x[U]===0;)U++;for(var O=new Uint8Array(S+(_-U)),E=S;U!==_;)O[E++]=x[U++];return O}}}function h(p){var w=f(p);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:h}}var tu=Jc,eu=tu,gi=eu;var eo=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")}},ro=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 yi(this,t)}},no=class{decoders;constructor(t){this.decoders=t}or(t){return yi(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 yi(r,t){return new no({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var oo=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 eo(t,e,n),this.decoder=new ro(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function De({name:r,prefix:t,encode:e,decode:n}){return new oo(r,t,e,n)}function te({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=gi(e,r);return De({prefix:t,name:r,encode:n,decode:s=>Ut(o(s))})}function ru(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let d=t[r[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function nu(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function ou(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function W({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=ou(n);return De({prefix:t,name:r,encode(s){return nu(s,n,e)},decode(s){return ru(s,o,e,r)}})}var G=te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),su=te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var io={};yt(io,{base32:()=>ee,base32hex:()=>uu,base32hexpad:()=>lu,base32hexpadupper:()=>du,base32hexupper:()=>fu,base32pad:()=>au,base32padupper:()=>cu,base32upper:()=>iu,base32z:()=>hu});var ee=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),iu=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),au=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),cu=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),uu=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),fu=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),lu=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),du=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),hu=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ao={};yt(ao,{base36:()=>ar,base36upper:()=>pu});var ar=te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),pu=te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var mu=wi,bi=128,gu=127,yu=~gu,bu=Math.pow(2,31);function wi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=bu;)t[e++]=r&255|bi,r/=128;for(;r&yu;)t[e++]=r&255|bi,r>>>=7;return t[e]=r|0,wi.bytes=e-n+1,t}var xu=co,wu=128,xi=127;function co(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw co.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&xi)<<o:(i&xi)*Math.pow(2,o),o+=7}while(i>=wu);return co.bytes=s-n,e}var Eu=Math.pow(2,7),Su=Math.pow(2,14),vu=Math.pow(2,21),_u=Math.pow(2,28),Au=Math.pow(2,35),Iu=Math.pow(2,42),Bu=Math.pow(2,49),Du=Math.pow(2,56),Cu=Math.pow(2,63),Tu=function(r){return r<Eu?1:r<Su?2:r<vu?3:r<_u?4:r<Au?5:r<Iu?6:r<Bu?7:r<Du?8:r<Cu?9:10},Lu={encode:mu,decode:xu,encodingLength:Tu},Ru=Lu,cr=Ru;function ur(r,t=0){return[cr.decode(r,t),cr.decode.bytes]}function Ce(r,t,e=0){return cr.encode(r,t,e),t}function Te(r){return cr.encodingLength(r)}function Re(r,t){let e=t.byteLength,n=Te(r),o=n+Te(e),s=new Uint8Array(o+e);return Ce(r,s,0),Ce(e,s,n),s.set(t,o),new Le(r,e,t,s)}function fr(r){let t=Ut(r),[e,n]=ur(t),[o,s]=ur(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(e,o,i,t)}function Ei(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&di(r.bytes,e.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Si(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ou(e,uo(r),t??G.encoder);default:return ku(e,uo(r),t??ee.encoder)}}var vi=new WeakMap;function uo(r){let t=vi.get(r);if(t==null){let e=new Map;return vi.set(r,e),e}return t}var J=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!==lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Nu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Re(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ei(t.multihash,n.multihash)}toString(t){return Si(this,t)}toJSON(){return{"/":Si(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??_i(n,o,s.bytes))}else if(e[Uu]===!0){let{version:n,multihash:o,code:s}=e,i=fr(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==lr)throw new Error(`Version 0 CID must use dag-pb (code: ${lr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=_i(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,lr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Ut(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 Le(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,f]=ur(t.subarray(e));return e+=f,l},o=n(),s=lr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,d=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:u}}static parse(t,e){let[n,o]=Pu(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 uo(s).set(n,t),s}};function Pu(r,t){switch(r[0]){case"Q":{let e=t??G;return[G.prefix,e.decode(`${G.prefix}${r}`)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case ee.prefix:{let e=t??ee;return[ee.prefix,e.decode(r)]}case ar.prefix:{let e=t??ar;return[ar.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 Ou(r,t,e){let{prefix:n}=e;if(n!==G.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 ku(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var lr=112,Nu=18;function _i(r,t,e){let n=Te(r),o=n+Te(t),s=new Uint8Array(o+e.byteLength);return Ce(r,s,0),Ce(t,s,n),s.set(e,o),s}var Uu=Symbol.for("@ipld/js-cid/CID");var fo={};yt(fo,{identity:()=>Tt});var Ai=0,Mu="identity",Ii=Ut;function Ku(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Re(Ai,Ii(r))}var Tt={code:Ai,name:Mu,encode:Ii,digest:Ku};function ft(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function bt(r=0){return new Uint8Array(r)}function pt(r=0){return new Uint8Array(r)}function Mt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=pt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Di=Symbol.for("@achingbrain/uint8arraylist");function Bi(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 Wr(r){return!!r?.[Di]}var tt=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(Wr(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(Wr(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=Bi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Bi(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(Wr(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 Mt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Mt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,d=e>a&&e<=c;if(u&&d){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Wr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let l=e;l<=c;l+=d){d=0;for(let f=u;f>=0;f--){let h=this.get(l+f);if(n[f]!==h){d=Math.max(1,f-a[h]);break}}if(d===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=pt(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=bt(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=bt(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=bt(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=pt(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=bt(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=bt(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=bt(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=bt(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=bt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!ft(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var lo={};yt(lo,{base10:()=>Fu});var Fu=te({prefix:"9",name:"base10",alphabet:"0123456789"});var ho={};yt(ho,{base16:()=>qu,base16upper:()=>zu});var qu=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),zu=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var po={};yt(po,{base2:()=>Vu});var Vu=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mo={};yt(mo,{base256emoji:()=>ju});var Ci=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}"),Hu=Ci.reduce((r,t,e)=>(r[e]=t,r),[]),$u=Ci.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Gu(r){return r.reduce((t,e)=>(t+=Hu[e],t),"")}function Zu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=$u[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var ju=De({prefix:"\u{1F680}",name:"base256emoji",encode:Gu,decode:Zu});var yo={};yt(yo,{base64:()=>Xu,base64pad:()=>Wu,base64url:()=>go,base64urlpad:()=>Yu});var Xu=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Wu=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),go=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yu=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bo={};yt(bo,{base8:()=>Qu});var Qu=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xo={};yt(xo,{identity:()=>Ju});var Ju=De({prefix:"\0",name:"identity",encode:r=>pi(r),decode:r=>hi(r)});var lp=new TextEncoder,dp=new TextDecoder;var So={};yt(So,{sha256:()=>dr,sha512:()=>nf});var rf=20;function Eo({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new wo(r,t,e,n,o)}var wo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??rf,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ti(n,this.code,e?.truncate):n.then(o=>Ti(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ti(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Re(t,r)}function Ri(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var dr=Eo({name:"sha2-256",code:18,encode:Ri("SHA-256")}),nf=Eo({name:"sha2-512",code:19,encode:Ri("SHA-512")});var hr={...xo,...po,...bo,...lo,...ho,...io,...ao,...so,...yo,...mo},_p={...So,...fo};function Oi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Pi=Oi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),vo=Oi("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=pt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),of={utf8:Pi,"utf-8":Pi,hex:hr.base16,latin1:vo,ascii:vo,binary:vo,...hr},Yr=of;function V(r,t="utf8"){let e=Yr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function H(r,t="utf8"){let e=Yr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var sf=parseInt("11111",2),_o=parseInt("10000000",2),af=parseInt("01111111",2),ki={0:pr,1:pr,2:cf,3:lf,4:df,5:ff,6:uf,16:pr,22:pr,48:pr};function Ao(r,t={offset:0}){let e=r[t.offset]&sf;if(t.offset++,ki[e]!=null)return ki[e](r,t);throw new Error("No decoder for tag "+e)}function mr(r,t){let e=0;if((r[t.offset]&_o)===_o){let n=r[t.offset]&af,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function pr(r,t){mr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ao(r,t);if(n===null)break;e.push(n)}return e}function cf(r,t){let e=mr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function uf(r,t){let e=mr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let d=0;for(let l=0;l<c.length;l++)d+=c[l]<<l*7;a+=`.${d}`,c=[]}}return a}function ff(r,t){return t.offset++,null}function lf(r,t){let e=mr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function df(r,t){let e=mr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function hf(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new tt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Io(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=hf(r.byteLength);return new tt(Uint8Array.from([t.byteLength|_o]),t)}function Ni(r){let t=new tt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new tt(Uint8Array.from([2]),Io(t),t)}function Ui(r){let t=Uint8Array.from([0]),e=new tt(t,r);return new tt(Uint8Array.from([3]),Io(e),e)}function Qr(r,t=48){let e=new tt;for(let n of r)e.append(n);return new tt(Uint8Array.from([t]),Io(e),e)}async function Mi(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var pf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),mf=Uint8Array.from([6,5,43,129,4,0,34]),gf=Uint8Array.from([6,5,43,129,4,0,35]),yf={ext:!0,kty:"EC",crv:"P-256"},bf={ext:!0,kty:"EC",crv:"P-384"},xf={ext:!0,kty:"EC",crv:"P-521"},Bo=32,Do=48,Co=66;function Ki(r){let t=Ao(r);return Fi(t)}function Fi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Bo*2+1)return n=H(t.subarray(e,e+Bo),"base64url"),o=H(t.subarray(e+Bo),"base64url"),new Pe({...yf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Do*2+1)return n=H(t.subarray(e,e+Do),"base64url"),o=H(t.subarray(e+Do),"base64url"),new Pe({...bf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Co*2+1)return n=H(t.subarray(e,e+Co),"base64url"),o=H(t.subarray(e+Co),"base64url"),new Pe({...xf,key_ops:["verify"],x:n,y:o});throw new Ct(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function qi(r){return Qr([Ni(Uint8Array.from([1])),Qr([wf(r.crv)],160),Qr([Ui(new tt(Uint8Array.from([4]),V(r.x??"","base64url"),V(r.y??"","base64url")))],161)]).subarray()}function wf(r){if(r==="P-256")return pf;if(r==="P-384")return mf;if(r==="P-521")return gf;throw new Ct(`Invalid curve ${r}`)}var Pe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=qi(this.jwk)),this._raw}toMultihash(){return Tt.digest(Oe(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}async verify(t,e,n){return Mi(this.jwk,e,t,n)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ft(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function gr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function mt(r,...t){if(!Ft(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 Jr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");gr(r.outputLen),gr(r.blockLen)}function Ne(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 Vi(r,t){mt(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function qt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function tn(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Lt(r,t){return r<<32-t|r>>>t}var Hi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ef=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function At(r){if(mt(r),Hi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Ef[r[e]];return t}var Kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function zi(r){if(r>=Kt._0&&r<=Kt._9)return r-Kt._0;if(r>=Kt.A&&r<=Kt.F)return r-(Kt.A-10);if(r>=Kt.a&&r<=Kt.f)return r-(Kt.a-10)}function pe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Hi)return Uint8Array.fromHex(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=zi(r.charCodeAt(s)),a=zi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function To(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function yr(r){return typeof r=="string"&&(r=To(r)),mt(r),r}function lt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];mt(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 ke=class{};function Lo(r){let t=n=>r().update(yr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ue(r=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(r));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Sf(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,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function $i(r,t,e){return r&t^~r&e}function Gi(r,t,e){return r&t^r&e^t&e}var br=class extends ke{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=tn(this.buffer)}update(t){Ne(this),t=yr(t),mt(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=tn(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){Ne(this),Vi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,qt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;Sf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=tn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,d[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var en=BigInt(4294967295),Zi=BigInt(32);function vf(r,t=!1){return t?{h:Number(r&en),l:Number(r>>Zi&en)}:{h:Number(r>>Zi&en)|0,l:Number(r&en)|0}}function ji(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=vf(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Ro=(r,t,e)=>r>>>e,Po=(r,t,e)=>r<<32-e|t>>>e,me=(r,t,e)=>r>>>e|t<<32-e,ge=(r,t,e)=>r<<32-e|t>>>e,xr=(r,t,e)=>r<<64-e|t>>>e-32,wr=(r,t,e)=>r>>>e-32|t<<64-e;function kt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Xi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Wi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Yi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Qi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ji=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ta=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Af=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),re=new Uint32Array(64),Oo=class extends br{constructor(t=32){super(64,t,8,!1),this.A=zt[0]|0,this.B=zt[1]|0,this.C=zt[2]|0,this.D=zt[3]|0,this.E=zt[4]|0,this.F=zt[5]|0,this.G=zt[6]|0,this.H=zt[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 l=0;l<16;l++,e+=4)re[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let f=re[l-15],h=re[l-2],p=Lt(f,7)^Lt(f,18)^f>>>3,w=Lt(h,17)^Lt(h,19)^h>>>10;re[l]=w+re[l-7]+p+re[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){let f=Lt(a,6)^Lt(a,11)^Lt(a,25),h=d+f+$i(a,c,u)+Af[l]+re[l]|0,w=(Lt(n,2)^Lt(n,13)^Lt(n,22))+Gi(n,o,s)|0;d=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,u,d)}roundClean(){qt(re)}destroy(){this.set(0,0,0,0,0,0,0,0),qt(this.buffer)}};var ea=ji(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),If=ea[0],Bf=ea[1],ne=new Uint32Array(80),oe=new Uint32Array(80),ko=class extends br{constructor(t=64){super(128,t,16,!1),this.Ah=ot[0]|0,this.Al=ot[1]|0,this.Bh=ot[2]|0,this.Bl=ot[3]|0,this.Ch=ot[4]|0,this.Cl=ot[5]|0,this.Dh=ot[6]|0,this.Dl=ot[7]|0,this.Eh=ot[8]|0,this.El=ot[9]|0,this.Fh=ot[10]|0,this.Fl=ot[11]|0,this.Gh=ot[12]|0,this.Gl=ot[13]|0,this.Hh=ot[14]|0,this.Hl=ot[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:d,Fh:l,Fl:f,Gh:h,Gl:p,Hh:w,Hl:S}=this;return[t,e,n,o,s,i,a,c,u,d,l,f,h,p,w,S]}set(t,e,n,o,s,i,a,c,u,d,l,f,h,p,w,S){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=w|0,this.Hl=S|0}process(t,e){for(let x=0;x<16;x++,e+=4)ne[x]=t.getUint32(e),oe[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let D=ne[x-15]|0,R=oe[x-15]|0,M=me(D,R,1)^me(D,R,8)^Ro(D,R,7),U=ge(D,R,1)^ge(D,R,8)^Po(D,R,7),O=ne[x-2]|0,E=oe[x-2]|0,C=me(O,E,19)^xr(O,E,61)^Ro(O,E,6),k=ge(O,E,19)^wr(O,E,61)^Po(O,E,6),T=Yi(U,k,oe[x-7],oe[x-16]),b=Qi(T,M,C,ne[x-7],ne[x-16]);ne[x]=b|0,oe[x]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:d,Eh:l,El:f,Fh:h,Fl:p,Gh:w,Gl:S,Hh:y,Hl:_}=this;for(let x=0;x<80;x++){let D=me(l,f,14)^me(l,f,18)^xr(l,f,41),R=ge(l,f,14)^ge(l,f,18)^wr(l,f,41),M=l&h^~l&w,U=f&p^~f&S,O=Ji(_,R,U,Bf[x],oe[x]),E=ta(O,y,D,M,If[x],ne[x]),C=O|0,k=me(n,o,28)^xr(n,o,34)^xr(n,o,39),T=ge(n,o,28)^wr(n,o,34)^wr(n,o,39),b=n&s^n&a^s&a,m=o&i^o&c^i&c;y=w|0,_=S|0,w=h|0,S=p|0,h=l|0,p=f|0,{h:l,l:f}=kt(u|0,d|0,E|0,C|0),u=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let g=Xi(C,T,m);n=Wi(g,E,k,b),o=g|0}({h:n,l:o}=kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:d}=kt(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:f}=kt(this.Eh|0,this.El|0,l|0,f|0),{h,l:p}=kt(this.Fh|0,this.Fl|0,h|0,p|0),{h:w,l:S}=kt(this.Gh|0,this.Gl|0,w|0,S|0),{h:y,l:_}=kt(this.Hh|0,this.Hl|0,y|0,_|0),this.set(n,o,s,i,a,c,u,d,l,f,h,p,w,S,y,_)}roundClean(){qt(ne,oe)}destroy(){qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ra=Lo(()=>new Oo);var na=Lo(()=>new ko);var Mo=BigInt(0),Uo=BigInt(1);function Vt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}"`;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function xt(r,t,e=""){let n=Ft(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Er(r){let t=r.toString(16);return t.length&1?"0"+t:t}function oa(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Mo:BigInt("0x"+r)}function Me(r){return oa(At(r))}function Ht(r){return mt(r),oa(At(Uint8Array.from(r).reverse()))}function rn(r,t){return pe(r.toString(16).padStart(t*2,"0"))}function Ko(r,t){return rn(r,t).reverse()}function q(r,t,e){let n;if(typeof t=="string")try{n=pe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ft(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 sa(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 Fo(r){return Uint8Array.from(r)}var No=r=>typeof r=="bigint"&&Mo<=r;function ia(r,t,e){return No(r)&&No(t)&&No(e)&&t<=r&&r<e}function Sr(r,t,e,n){if(!ia(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function nn(r){let t;for(t=0;r>Mo;r>>=Uo,t+=1);return t}var se=r=>(Uo<<BigInt(r))-Uo;function aa(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=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},u=(...h)=>e(i,s,...h),d=(h=n(0))=>{i=u(o(0),h),s=u(),h.length!==0&&(i=u(o(1),h),s=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<t;){s=u();let w=s.slice();p.push(w),h+=s.length}return lt(...p)};return(h,p)=>{c(),d(h);let w;for(;!(w=p(l()));)d();return c(),w}}function ie(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}var qo=()=>{throw new Error("not implemented")};function Ke(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 dt=BigInt(0),et=BigInt(1),ye=BigInt(2),fa=BigInt(3),la=BigInt(4),da=BigInt(5),Df=BigInt(7),ha=BigInt(8),Cf=BigInt(9),pa=BigInt(16);function Y(r,t){let e=r%t;return e>=dt?e:t+e}function $(r,t,e){let n=r;for(;t-- >dt;)n*=n,n%=e;return n}function ca(r,t){if(r===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let e=Y(r,t),n=t,o=dt,s=et,i=et,a=dt;for(;e!==dt;){let u=n/e,d=n%e,l=o-i*u,f=s-a*u;n=e,e=d,o=i,s=a,i=l,a=f}if(n!==et)throw new Error("invert: does not exist");return Y(o,t)}function zo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function ma(r,t){let e=(r.ORDER+et)/la,n=r.pow(t,e);return zo(r,n,t),n}function Tf(r,t){let e=(r.ORDER-da)/ha,n=r.mul(t,ye),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ye),o),a=r.mul(s,r.sub(i,r.ONE));return zo(r,a,t),a}function Lf(r){let t=wt(r),e=ga(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Df)/pa;return(a,c)=>{let u=a.pow(c,i),d=a.mul(u,n),l=a.mul(u,o),f=a.mul(u,s),h=a.eql(a.sqr(d),c),p=a.eql(a.sqr(l),c);u=a.cmov(u,d,h),d=a.cmov(f,l,p);let w=a.eql(a.sqr(d),c),S=a.cmov(u,d,w);return zo(a,S,c),S}}function ga(r){if(r<fa)throw new Error("sqrt is not defined for small field");let t=r-et,e=0;for(;t%ye===dt;)t/=ye,e++;let n=ye,o=wt(r);for(;ua(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return ma;let s=o.pow(n,t),i=(t+et)/ye;return function(c,u){if(c.is0(u))return u;if(ua(c,u)!==1)throw new Error("Cannot find square root");let d=e,l=c.mul(c.ONE,s),f=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(f,c.ONE);){if(c.is0(f))return c.ZERO;let p=1,w=c.sqr(f);for(;!c.eql(w,c.ONE);)if(p++,w=c.sqr(w),p===d)throw new Error("Cannot find square root");let S=et<<BigInt(d-p-1),y=c.pow(l,S);d=p,l=c.sqr(y),f=c.mul(f,l),h=c.mul(h,y)}return h}}function Rf(r){return r%la===fa?ma:r%ha===da?Tf:r%pa===Cf?Lf(r):ga(r)}var $t=(r,t)=>(Y(r,t)&et)===et,Pf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Vo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=Pf.reduce((n,o)=>(n[o]="function",n),t);return ie(r,e),r}function Of(r,t,e){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(e===dt)return r.ONE;if(e===et)return t;let n=r.ONE,o=t;for(;e>dt;)e&et&&(n=r.mul(n,o)),o=r.sqr(o),e>>=et;return n}function vr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function ua(r,t){let e=(r.ORDER-et)/ye,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function on(r,t){t!==void 0&&gr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function wt(r,t,e=!1,n={}){if(r<=dt)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(e=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),a=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:u}=on(r,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:r,isLE:e,BITS:c,BYTES:u,MASK:se(c),ZERO:dt,ONE:et,allowedLengths:a,create:f=>Y(f,r),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return dt<=f&&f<r},is0:f=>f===dt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&et)===et,neg:f=>Y(-f,r),eql:(f,h)=>f===h,sqr:f=>Y(f*f,r),add:(f,h)=>Y(f+h,r),sub:(f,h)=>Y(f-h,r),mul:(f,h)=>Y(f*h,r),pow:(f,h)=>Of(l,f,h),div:(f,h)=>Y(f*ca(h,r),r),sqrN:f=>f*f,addN:(f,h)=>f+h,subN:(f,h)=>f-h,mulN:(f,h)=>f*h,inv:f=>ca(f,r),sqrt:s||(f=>(d||(d=Rf(r)),d(l,f))),toBytes:f=>e?Ko(f,u):rn(f,u),fromBytes:(f,h=!0)=>{if(a){if(!a.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);let w=new Uint8Array(u);w.set(f,e?0:w.length-f.length),f=w}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let p=e?Ht(f):Me(f);if(i&&(p=Y(p,r)),!h&&!l.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:f=>vr(l,f),cmov:(f,h,p)=>p?h:f});return Object.freeze(l)}function ya(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 Ho(r){let t=ya(r);return t+Math.ceil(t/2)}function $o(r,t,e=!1){let n=r.length,o=ya(t),s=Ho(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Ht(r):Me(r),a=Y(i,t-et)+et;return e?Ko(a,o):rn(a,o)}var Fe=BigInt(0),be=BigInt(1);function _r(r,t){let e=t.negate();return r?e:t}function Gt(r,t){let e=vr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Ea(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Go(r,t){Ea(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=se(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ba(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=be);let u=t*n,d=u+Math.abs(a)-1,l=a===0,f=a<0,h=t%2!==0;return{nextN:c,offset:d,isZero:l,isNeg:f,isNegF:h,offsetF:u}}function kf(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 Nf(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 Zo=new WeakMap,Sa=new WeakMap;function jo(r){return Sa.get(r)||1}function xa(r){if(r!==Fe)throw new Error("invalid wNAF")}var qe=class{constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Fe;)e&be&&(n=n.add(o)),o=o.double(),e>>=be;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Go(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Go(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:d,isNeg:l,isNegF:f,offsetF:h}=ba(n,a,i);n=c,d?s=s.add(_r(f,e[h])):o=o.add(_r(l,e[u]))}return xa(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Go(t,this.bits);for(let i=0;i<s.windows&&n!==Fe;i++){let{nextN:a,offset:c,isZero:u,isNeg:d}=ba(n,i,s);if(n=a,!u){let l=e[c];o=o.add(d?l.negate():l)}}return xa(n),o}getPrecomputes(t,e,n){let o=Zo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Zo.set(e,o))),o}cached(t,e,n){let o=jo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=jo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Ea(e,this.bits),Sa.set(t,e),Zo.delete(t)}hasCache(t){return jo(t)!==1}};function va(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Fe||n>Fe;)e&be&&(s=s.add(o)),n&be&&(i=i.add(o)),o=o.double(),e>>=be,n>>=be;return{p1:s,p2:i}}function ze(r,t,e,n){kf(e,r),Nf(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=nn(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=se(c),d=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,f=i;for(let h=l;h>=0;h-=c){d.fill(i);for(let w=0;w<s;w++){let S=n[w],y=Number(S>>BigInt(h)&u);d[y]=d[y].add(e[w])}let p=i;for(let w=d.length-1,S=i;w>0;w--)S=S.add(d[w]),p=p.add(S);if(f=f.add(p),h!==0)for(let w=0;w<c;w++)f=f.double()}return f}function wa(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Vo(t),t}else return wt(r,{isLE:e})}function sn(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Fe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=wa(t.p,e.Fp,n),s=wa(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var ae=BigInt(0),rt=BigInt(1),Xo=BigInt(2),Uf=BigInt(8);function Mf(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Kf(r,t={}){let e=sn("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;ie(t,{},{uvRatio:"function"});let a=Xo<<BigInt(o.BYTES*8)-rt,c=S=>n.create(S),u=t.uvRatio||((S,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,y))}}catch{return{isValid:!1,value:ae}}});if(!Mf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(S,y,_=!1){let x=_?rt:ae;return Sr("coordinate "+S,y,x,a),y}function l(S){if(!(S instanceof p))throw new Error("ExtendedPoint expected")}let f=Ke((S,y)=>{let{X:_,Y:x,Z:D}=S,R=S.is0();y==null&&(y=R?Uf:n.inv(D));let M=c(_*y),U=c(x*y),O=n.mul(D,y);if(R)return{x:ae,y:rt};if(O!==rt)throw new Error("invZ was invalid");return{x:M,y:U}}),h=Ke(S=>{let{a:y,d:_}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:x,Y:D,Z:R,T:M}=S,U=c(x*x),O=c(D*D),E=c(R*R),C=c(E*E),k=c(U*y),T=c(E*c(k+O)),b=c(C+c(_*c(U*O)));if(T!==b)throw new Error("bad point: equation left != right (1)");let m=c(x*D),g=c(R*M);if(m!==g)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(y,_,x,D){this.X=d("x",y),this.Y=d("y",_),this.Z=d("z",x,!0),this.T=d("t",D),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof p)throw new Error("extended point not allowed");let{x:_,y:x}=y||{};return d("x",_),d("y",x),new p(_,x,rt,c(_*x))}static fromBytes(y,_=!1){let x=n.BYTES,{a:D,d:R}=s;y=Fo(xt(y,x,"point")),Vt(_,"zip215");let M=Fo(y),U=y[x-1];M[x-1]=U&-129;let O=Ht(M),E=_?a:n.ORDER;Sr("point.y",O,ae,E);let C=c(O*O),k=c(C-rt),T=c(R*C-D),{isValid:b,value:m}=u(k,T);if(!b)throw new Error("bad point: invalid y coordinate");let g=(m&rt)===rt,v=(U&128)!==0;if(!_&&m===ae&&v)throw new Error("bad point: x=0 and x_0=1");return v!==g&&(m=c(-m)),p.fromAffine({x:m,y:O})}static fromHex(y,_=!1){return p.fromBytes(q("point",y),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,_=!0){return w.createCache(this,y),_||this.multiply(Xo),this}assertValidity(){h(this)}equals(y){l(y);let{X:_,Y:x,Z:D}=this,{X:R,Y:M,Z:U}=y,O=c(_*U),E=c(R*D),C=c(x*U),k=c(M*D);return O===E&&C===k}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=s,{X:_,Y:x,Z:D}=this,R=c(_*_),M=c(x*x),U=c(Xo*c(D*D)),O=c(y*R),E=_+x,C=c(c(E*E)-R-M),k=O+M,T=k-U,b=O-M,m=c(C*T),g=c(k*b),v=c(C*b),A=c(T*k);return new p(m,g,A,v)}add(y){l(y);let{a:_,d:x}=s,{X:D,Y:R,Z:M,T:U}=this,{X:O,Y:E,Z:C,T:k}=y,T=c(D*O),b=c(R*E),m=c(U*x*k),g=c(M*C),v=c((D+R)*(O+E)-T-b),A=g-m,L=g+m,I=c(b-_*T),B=c(v*A),P=c(L*I),N=c(v*I),Z=c(A*L);return new p(B,P,Z,N)}subtract(y){return this.add(y.negate())}multiply(y){if(!o.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:_,f:x}=w.cached(this,y,D=>Gt(p,D));return Gt(p,[_,x])[0]}multiplyUnsafe(y,_=p.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===ae?p.ZERO:this.is0()||y===rt?this:w.unsafe(this,y,x=>Gt(p,x),_)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return w.unsafe(this,s.n).is0()}toAffine(y){return f(this,y)}clearCofactor(){return i===rt?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:_}=this.toAffine(),x=n.toBytes(_);return x[x.length-1]|=y&rt?128:0,x}toHex(){return At(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(y){return Gt(p,y)}static msm(y,_){return ze(p,o,y,_)}_setWindowSize(y){this.precompute(y)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,rt,c(s.Gx*s.Gy)),p.ZERO=new p(ae,rt,rt,ae),p.Fp=n,p.Fn=o;let w=new qe(p,o.BITS);return p.BASE.precompute(8),p}var an=class{constructor(t){this.ep=t}static fromBytes(t){qo()}static fromHex(t){qo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return At(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.init(this.ep.precompute(t,e))}toRawBytes(){return this.toBytes()}};function Ff(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');ie(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=e.randomBytes||Ue,c=e.adjustScalarBytes||(E=>E),u=e.domain||((E,C,k)=>{if(Vt(k,"phflag"),C.length||k)throw new Error("Contexts/pre-hash are not supported");return E});function d(E){return i.create(Ht(E))}function l(E){let C=x.secretKey;E=q("private key",E,C);let k=q("hashed private key",t(E),2*C),T=c(k.slice(0,C)),b=k.slice(C,2*C),m=d(T);return{head:T,prefix:b,scalar:m}}function f(E){let{head:C,prefix:k,scalar:T}=l(E),b=o.multiply(T),m=b.toBytes();return{head:C,prefix:k,scalar:T,point:b,pointBytes:m}}function h(E){return f(E).pointBytes}function p(E=Uint8Array.of(),...C){let k=lt(...C);return d(t(u(k,q("context",E),!!n)))}function w(E,C,k={}){E=q("message",E),n&&(E=n(E));let{prefix:T,scalar:b,pointBytes:m}=f(C),g=p(k.context,T,E),v=o.multiply(g).toBytes(),A=p(k.context,v,m,E),L=i.create(g+A*b);if(!i.isValid(L))throw new Error("sign failed: invalid s");let I=lt(v,i.toBytes(L));return xt(I,x.signature,"result")}let S={zip215:!0};function y(E,C,k,T=S){let{context:b,zip215:m}=T,g=x.signature;E=q("signature",E,g),C=q("message",C),k=q("publicKey",k,x.publicKey),m!==void 0&&Vt(m,"zip215"),n&&(C=n(C));let v=g/2,A=E.subarray(0,v),L=Ht(E.subarray(v,g)),I,B,P;try{I=r.fromBytes(k,m),B=r.fromBytes(A,m),P=o.multiplyUnsafe(L)}catch{return!1}if(!m&&I.isSmallOrder())return!1;let N=p(b,B.toBytes(),I.toBytes(),C);return B.add(I.multiplyUnsafe(N)).subtract(P).clearCofactor().is0()}let _=s.BYTES,x={secretKey:_,publicKey:_,signature:2*_,seed:_};function D(E=a(x.seed)){return xt(E,x.seed,"seed")}function R(E){let C=O.randomSecretKey(E);return{secretKey:C,publicKey:h(C)}}function M(E){return Ft(E)&&E.length===i.BYTES}function U(E,C){try{return!!r.fromBytes(E,C)}catch{return!1}}let O={getExtendedPublicKey:f,randomSecretKey:D,isValidSecretKey:M,isValidPublicKey:U,toMontgomery(E){let{y:C}=r.fromBytes(E),k=x.publicKey,T=k===32;if(!T&&k!==57)throw new Error("only defined for 25519 and 448");let b=T?s.div(rt+C,rt-C):s.div(C-rt,C+rt);return s.toBytes(b)},toMontgomerySecret(E){let C=x.secretKey;xt(E,C);let k=t(E.subarray(0,C));return c(k).subarray(0,C)},randomPrivateKey:D,precompute(E=8,C=r.BASE){return C.precompute(E,!1)}};return Object.freeze({keygen:R,getPublicKey:h,sign:w,verify:y,utils:O,Point:r,lengths:x})}function qf(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=wt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,hash:r.hash,eddsaOpts:s}}function zf(r,t){let e=t.Point;return Object.assign({},t,{ExtendedPoint:e,CURVE:r,nBitLength:e.Fn.BITS,nByteLength:e.Fn.BYTES})}function _a(r){let{CURVE:t,curveOpts:e,hash:n,eddsaOpts:o}=qf(r),s=Kf(t,e),i=Ff(s,n,o);return zf(r,i)}var Vf=BigInt(0),Zt=BigInt(1),Aa=BigInt(2),R0=BigInt(3),Hf=BigInt(5),$f=BigInt(8),Ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ar={p:Ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:$f,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Gf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ve,a=r*r%s*r%s,c=$(a,Aa,s)*a%s,u=$(c,Zt,s)*r%s,d=$(u,Hf,s)*u%s,l=$(d,t,s)*d%s,f=$(l,e,s)*l%s,h=$(f,n,s)*f%s,p=$(h,o,s)*h%s,w=$(p,o,s)*h%s,S=$(w,t,s)*d%s;return{pow_p_5_8:$(S,Aa,s)*r%s,b2:a}}function Zf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Wo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Jo(r,t){let e=Ve,n=Y(t*t*t,e),o=Y(n*n*t,e),s=Gf(r*o).pow_p_5_8,i=Y(r*n*s,e),a=Y(t*i*i,e),c=i,u=Y(i*Wo,e),d=a===r,l=a===Y(-r,e),f=a===Y(-r*Wo,e);return d&&(i=c),(l||f)&&(i=u),$t(i,e)&&(i=Y(-i,e)),{isValid:d||l,value:i}}var ce=wt(Ar.p,{isLE:!0}),jf=wt(Ar.n,{isLE:!0}),Xf={...Ar,Fp:ce,hash:na,adjustScalarBytes:Zf,uvRatio:Jo},jt=_a(Xf);var Yo=Wo,Wf=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Yf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Qf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Jf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ia=r=>Jo(Zt,r),tl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Qo=r=>jt.Point.Fp.create(Ht(r)&tl);function Ba(r){let{d:t}=Ar,e=Ve,n=y=>ce.create(y),o=n(Yo*r*r),s=n((o+Zt)*Qf),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=Jo(s,a),d=n(u*r);$t(d,e)||(d=n(-d)),c||(u=d),c||(i=o);let l=n(i*(o-Zt)*Jf-a),f=u*u,h=n((u+u)*a),p=n(l*Wf),w=n(Zt-f),S=n(Zt+f);return new jt.Point(n(h*S),n(w*p),n(p*S),n(h*w))}function el(r){mt(r,64);let t=Qo(r.subarray(0,32)),e=Ba(t),n=Qo(r.subarray(32,64)),o=Ba(n);return new Xt(e.add(o))}var Xt=class r extends an{constructor(t){super(t)}static fromAffine(t){return new r(jt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static hashToCurve(t){return el(q("ristrettoHash",t,64))}static fromBytes(t){mt(t,32);let{a:e,d:n}=Ar,o=Ve,s=D=>ce.create(D),i=Qo(t);if(!sa(ce.toBytes(i),t)||$t(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Zt+e*a),u=s(Zt-e*a),d=s(c*c),l=s(u*u),f=s(e*n*d-l),{isValid:h,value:p}=Ia(s(f*l)),w=s(p*u),S=s(p*w*f),y=s((i+i)*w);$t(y,o)&&(y=s(-y));let _=s(c*S),x=s(y*_);if(!h||$t(x,o)||_===Vf)throw new Error("invalid ristretto255 encoding 2");return new r(new jt.Point(y,_,Zt,x))}static fromHex(t){return r.fromBytes(q("ristrettoHex",t,32))}static msm(t,e){return ze(r,jt.Point.Fn,t,e)}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=Ve,i=S=>ce.create(S),a=i(i(n+e)*i(n-e)),c=i(t*e),u=i(c*c),{value:d}=Ia(i(a*u)),l=i(d*a),f=i(d*c),h=i(l*f*o),p;if($t(o*h,s)){let S=i(e*Yo),y=i(t*Yo);t=S,e=y,p=i(l*Yf)}else p=f;$t(t*h,s)&&(e=i(-e));let w=i((n-e)*p);return $t(w,s)&&(w=i(-w)),ce.toBytes(w)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ce.create(u),a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Xt.BASE=new Xt(jt.Point.BASE);Xt.ZERO=new Xt(jt.Point.ZERO);Xt.Fp=ce;Xt.Fn=jf;var Ir=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},cn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Da={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new cn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var un=Da;var fn=32;var ts,rl=(async()=>{try{return await un.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function nl(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await un.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await un.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ol(r,t,e){return jt.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Ca(r,t,e){return ts==null&&(ts=await rl),ts?nl(r,t,e):ol(r,t,e)}function ln(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var dn=class{type="Ed25519";raw;constructor(t){this.raw=es(t,fn)}toMultihash(){return Tt.digest(Oe(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Ca(this.raw,e,t);return ln(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function La(r){return r=es(r,fn),new dn(r)}function es(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Ct(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var il=Math.pow(2,7),al=Math.pow(2,14),cl=Math.pow(2,21),rs=Math.pow(2,28),ns=Math.pow(2,35),os=Math.pow(2,42),ss=Math.pow(2,49),F=128,at=127;function gt(r){if(r<il)return 1;if(r<al)return 2;if(r<cl)return 3;if(r<rs)return 4;if(r<ns)return 5;if(r<os)return 6;if(r<ss)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function He(r,t,e=0){switch(gt(r)){case 8:t[e++]=r&255|F,r/=128;case 7:t[e++]=r&255|F,r/=128;case 6:t[e++]=r&255|F,r/=128;case 5:t[e++]=r&255|F,r/=128;case 4:t[e++]=r&255|F,r>>>=7;case 3:t[e++]=r&255|F,r>>>=7;case 2:t[e++]=r&255|F,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ul(r,t,e=0){switch(gt(r)){case 8:t.set(e++,r&255|F),r/=128;case 7:t.set(e++,r&255|F),r/=128;case 6:t.set(e++,r&255|F),r/=128;case 5:t.set(e++,r&255|F),r/=128;case 4:t.set(e++,r&255|F),r>>>=7;case 3:t.set(e++,r&255|F),r>>>=7;case 2:t.set(e++,r&255|F),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function is(r,t){let e=r[t],n=0;if(n+=e&at,e<F||(e=r[t+1],n+=(e&at)<<7,e<F)||(e=r[t+2],n+=(e&at)<<14,e<F)||(e=r[t+3],n+=(e&at)<<21,e<F)||(e=r[t+4],n+=(e&at)*rs,e<F)||(e=r[t+5],n+=(e&at)*ns,e<F)||(e=r[t+6],n+=(e&at)*os,e<F)||(e=r[t+7],n+=(e&at)*ss,e<F))return n;throw new RangeError("Could not decode varint")}function fl(r,t){let e=r.get(t),n=0;if(n+=e&at,e<F||(e=r.get(t+1),n+=(e&at)<<7,e<F)||(e=r.get(t+2),n+=(e&at)<<14,e<F)||(e=r.get(t+3),n+=(e&at)<<21,e<F)||(e=r.get(t+4),n+=(e&at)*rs,e<F)||(e=r.get(t+5),n+=(e&at)*ns,e<F)||(e=r.get(t+6),n+=(e&at)*os,e<F)||(e=r.get(t+7),n+=(e&at)*ss,e<F))return n;throw new RangeError("Could not decode varint")}function Ra(r,t,e=0){return t==null&&(t=pt(gt(r))),t instanceof Uint8Array?He(r,t,e):ul(r,t,e)}function Br(r,t=0){return r instanceof Uint8Array?is(r,t):fl(r,t)}var as=new Float32Array([-0]),ue=new Uint8Array(as.buffer);function Oa(r,t,e){as[0]=r,t[e]=ue[0],t[e+1]=ue[1],t[e+2]=ue[2],t[e+3]=ue[3]}function ka(r,t){return ue[0]=r[t],ue[1]=r[t+1],ue[2]=r[t+2],ue[3]=r[t+3],as[0]}var cs=new Float64Array([-0]),ct=new Uint8Array(cs.buffer);function Na(r,t,e){cs[0]=r,t[e]=ct[0],t[e+1]=ct[1],t[e+2]=ct[2],t[e+3]=ct[3],t[e+4]=ct[4],t[e+5]=ct[5],t[e+6]=ct[6],t[e+7]=ct[7]}function Ua(r,t){return ct[0]=r[t],ct[1]=r[t+1],ct[2]=r[t+2],ct[3]=r[t+3],ct[4]=r[t+4],ct[5]=r[t+5],ct[6]=r[t+6],ct[7]=r[t+7],cs[0]}var ll=BigInt(Number.MAX_SAFE_INTEGER),dl=BigInt(Number.MIN_SAFE_INTEGER),Et=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return xe;if(t<ll&&t>dl)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>Ma&&(o=0n,++n>Ma&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return xe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):xe}},xe=new Et(0,0);xe.toBigInt=function(){return 0n};xe.zzEncode=xe.zzDecode=function(){return this};xe.length=function(){return 1};var Ma=4294967296n;function Ka(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 Fa(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function us(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Rt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function hn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var fs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Rt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Rt(this,4);return hn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return hn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=ka(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=Ua(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Rt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Fa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Rt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Rt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Rt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Rt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Rt(this,8);let t=hn(this.buf,this.pos+=4),e=hn(this.buf,this.pos+=4);return new Et(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=is(this.buf,this.pos);return this.pos+=gt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ls(r){return new fs(r instanceof Uint8Array?r:r.subarray())}function It(r,t,e){let n=ls(r);return t.decode(n,void 0,e)}function ds(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return pt(i);o+i>t&&(n=pt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var we=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function hs(){}var ms=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},hl=ds();function pl(r){return globalThis.Buffer!=null?pt(r):hl(r)}var Cr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(hs,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new we(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new gs((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(pn,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(pn,e.length(),e)}uint64Number(t){return this._push(He,gt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Et.fromBigInt(t).zzEncode();return this._push(pn,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(pn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ps,1,t?1:0)}fixed32(t){return this._push(Dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(Dr,4,e.lo)._push(Dr,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(Dr,4,e.lo)._push(Dr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Oa,4,t)}double(t){return this._push(Na,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ps,1,0):this.uint32(e)._push(gl,e,t)}string(t){let e=Ka(t);return e!==0?this.uint32(e)._push(us,e,t):this._push(ps,1,0)}fork(){return this.states=new ms(this),this.head=this.tail=new we(hs,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new we(hs,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=pl(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ps(r,t,e){t[e]=r&255}function ml(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var gs=class extends we{next;constructor(t,e){super(ml,t,e),this.next=void 0}};function pn(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 Dr(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 gl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Cr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(yl,t,r),this},Cr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(bl,t,r),this});function yl(r,t,e){t.set(r,e)}function bl(r,t,e){r.length<40?us(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(V(r),e)}function ys(){return new Cr}function Bt(r,t){let e=ys();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var $e;(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"})($e||($e={}));function mn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ee(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 mn("enum",$e.VARINT,e,n)}function Dt(r,t){return mn("message",$e.LENGTH_DELIMITED,r,t)}var gn=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var St;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(St||(St={}));var bs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(bs||(bs={}));(function(r){r.codec=()=>Ee(bs)})(St||(St={}));var Tr;(function(r){let t;r.codec=()=>(t==null&&(t=Dt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),St.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=St.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>It(e,r.codec(),n)})(Tr||(Tr={}));var xs;(function(r){let t;r.codec=()=>(t==null&&(t=Dt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),St.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=St.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>It(e,r.codec(),n)})(xs||(xs={}));var yn=class extends ke{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Jr(t);let n=yr(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),qt(s)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(this),mt(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}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ws=(r,t,e)=>new yn(r,t).update(e).digest();ws.create=(r,t)=>new yn(r,t);var za=(r,t)=>(r+(r>=0?t:-t)/Va)/t;function wl(r,t,e){let[[n,o],[s,i]]=t,a=za(i*r,e),c=za(-o*r,e),u=r-a*n-c*s,d=-a*o-c*i,l=u<Yt,f=d<Yt;l&&(u=-u),f&&(d=-d);let h=se(Math.ceil(nn(e)/2))+Ze;if(u<Yt||u>=h||d<Yt||d>=h)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:l,k1:u,k2neg:f,k2:d}}function Ss(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Es(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Vt(e.lowS,"lowS"),Vt(e.prehash,"prehash"),e.format!==void 0&&Ss(e.format),e}var vs=class extends Error{constructor(t=""){super(t)}},Wt={Err:vs,_tlv:{encode:(r,t)=>{let{Err:e}=Wt;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=Er(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Er(o.length/2|128):"";return Er(r)+s+o+t},decode(r,t){let{Err:e}=Wt,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 u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of u)i=i<<8|d;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Wt;if(r<Yt)throw new t("integer: negative integers are not allowed");let e=Er(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}=Wt;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 Me(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Wt,o=q("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=Wt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Yt=BigInt(0),Ze=BigInt(1),Va=BigInt(2),bn=BigInt(3),El=BigInt(4);function Ge(r,t){let{BYTES:e}=r,n;if(typeof t=="bigint")n=t;else{let o=q("private key",t);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${e}, got ${typeof t}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Sl(r,t={}){let e=sn("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;ie(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=$a(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(T,b,m){let{x:g,y:v}=b.toAffine(),A=n.toBytes(g);if(Vt(m,"isCompressed"),m){d();let L=!n.isOdd(v);return lt(Ha(L),A)}else return lt(Uint8Array.of(4),A,n.toBytes(v))}function f(T){xt(T,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=u,g=T.length,v=T[0],A=T.subarray(1);if(g===b&&(v===2||v===3)){let L=n.fromBytes(A);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let I=w(L),B;try{B=n.sqrt(I)}catch(Z){let z=Z instanceof Error?": "+Z.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}d();let P=n.isOdd(B);return(v&1)===1!==P&&(B=n.neg(B)),{x:L,y:B}}else if(g===m&&v===4){let L=n.BYTES,I=n.fromBytes(A.subarray(0,L)),B=n.fromBytes(A.subarray(L,L*2));if(!S(I,B))throw new Error("bad point: is not on curve");return{x:I,y:B}}else throw new Error(`bad point: got length ${g}, expected compressed=${b} or uncompressed=${m}`)}let h=t.toBytes||l,p=t.fromBytes||f;function w(T){let b=n.sqr(T),m=n.mul(b,T);return n.add(n.add(m,n.mul(T,s.a)),s.b)}function S(T,b){let m=n.sqr(b),g=w(T);return n.eql(m,g)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,bn),El),_=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,_)))throw new Error("bad curve params: a or b");function x(T,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${T}`);return b}function D(T){if(!(T instanceof E))throw new Error("ProjectivePoint expected")}function R(T){if(!c||!c.basises)throw new Error("no endo");return wl(T,c.basises,o.ORDER)}let M=Ke((T,b)=>{let{X:m,Y:g,Z:v}=T;if(n.eql(v,n.ONE))return{x:m,y:g};let A=T.is0();b==null&&(b=A?n.ONE:n.inv(v));let L=n.mul(m,b),I=n.mul(g,b),B=n.mul(v,b);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:L,y:I}}),U=Ke(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=T.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(b,m))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function O(T,b,m,g,v){return m=new E(n.mul(m.X,T),m.Y,m.Z),b=_r(g,b),m=_r(v,m),b.add(m)}class E{constructor(b,m,g){this.X=x("x",b),this.Y=x("y",m,!0),this.Z=x("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:m,y:g}=b||{};if(!b||!n.isValid(m)||!n.isValid(g))throw new Error("invalid affine point");if(b instanceof E)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(g)?E.ZERO:new E(m,g,n.ONE)}static fromBytes(b){let m=E.fromAffine(p(xt(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return E.fromBytes(q("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return k.createCache(this,b),m||this.multiply(bn),this}assertValidity(){U(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){D(b);let{X:m,Y:g,Z:v}=this,{X:A,Y:L,Z:I}=b,B=n.eql(n.mul(m,I),n.mul(A,v)),P=n.eql(n.mul(g,I),n.mul(L,v));return B&&P}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,g=n.mul(m,bn),{X:v,Y:A,Z:L}=this,I=n.ZERO,B=n.ZERO,P=n.ZERO,N=n.mul(v,v),Z=n.mul(A,A),z=n.mul(L,L),K=n.mul(v,A);return K=n.add(K,K),P=n.mul(v,L),P=n.add(P,P),I=n.mul(b,P),B=n.mul(g,z),B=n.add(I,B),I=n.sub(Z,B),B=n.add(Z,B),B=n.mul(I,B),I=n.mul(K,I),P=n.mul(g,P),z=n.mul(b,z),K=n.sub(N,z),K=n.mul(b,K),K=n.add(K,P),P=n.add(N,N),N=n.add(P,N),N=n.add(N,z),N=n.mul(N,K),B=n.add(B,N),z=n.mul(A,L),z=n.add(z,z),N=n.mul(z,K),I=n.sub(I,N),P=n.mul(z,Z),P=n.add(P,P),P=n.add(P,P),new E(I,B,P)}add(b){D(b);let{X:m,Y:g,Z:v}=this,{X:A,Y:L,Z:I}=b,B=n.ZERO,P=n.ZERO,N=n.ZERO,Z=s.a,z=n.mul(s.b,bn),K=n.mul(m,A),j=n.mul(g,L),Q=n.mul(v,I),ht=n.add(m,g),X=n.add(A,L);ht=n.mul(ht,X),X=n.add(K,j),ht=n.sub(ht,X),X=n.add(m,v);let it=n.add(A,I);return X=n.mul(X,it),it=n.add(K,Q),X=n.sub(X,it),it=n.add(g,v),B=n.add(L,I),it=n.mul(it,B),B=n.add(j,Q),it=n.sub(it,B),N=n.mul(Z,X),B=n.mul(z,Q),N=n.add(B,N),B=n.sub(j,N),N=n.add(j,N),P=n.mul(B,N),j=n.add(K,K),j=n.add(j,K),Q=n.mul(Z,Q),X=n.mul(z,X),j=n.add(j,Q),Q=n.sub(K,Q),Q=n.mul(Z,Q),X=n.add(X,Q),K=n.mul(j,X),P=n.add(P,K),K=n.mul(it,X),B=n.mul(ht,B),B=n.sub(B,K),K=n.mul(ht,j),N=n.mul(it,N),N=n.add(N,K),new E(B,P,N)}subtract(b){return this.add(b.negate())}is0(){return this.equals(E.ZERO)}multiply(b){let{endo:m}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let g,v,A=L=>k.cached(this,L,I=>Gt(E,I));if(m){let{k1neg:L,k1:I,k2neg:B,k2:P}=R(b),{p:N,f:Z}=A(I),{p:z,f:K}=A(P);v=Z.add(K),g=O(m.beta,N,z,L,B)}else{let{p:L,f:I}=A(b);g=L,v=I}return Gt(E,[g,v])[0]}multiplyUnsafe(b){let{endo:m}=t,g=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Yt||g.is0())return E.ZERO;if(b===Ze)return g;if(k.hasCache(this))return this.multiply(b);if(m){let{k1neg:v,k1:A,k2neg:L,k2:I}=R(b),{p1:B,p2:P}=va(E,g,A,I);return O(m.beta,B,P,v,L)}else return k.unsafe(g,b)}multiplyAndAddUnsafe(b,m,g){let v=this.multiplyUnsafe(m).add(b.multiplyUnsafe(g));return v.is0()?void 0:v}toAffine(b){return M(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===Ze?!0:b?b(E,this):k.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===Ze?this:b?b(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return Vt(b,"isCompressed"),this.assertValidity(),h(E,this,b)}toHex(b=!0){return At(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return Gt(E,b)}static msm(b,m){return ze(E,o,b,m)}static fromPrivateKey(b){return E.BASE.multiply(Ge(o,b))}}E.BASE=new E(s.Gx,s.Gy,n.ONE),E.ZERO=new E(n.ZERO,n.ONE,n.ZERO),E.Fp=n,E.Fn=o;let C=o.BITS,k=new qe(E,t.endo?Math.ceil(C/2):C);return E.BASE.precompute(8),E}function Ha(r){return Uint8Array.of(r?2:3)}function $a(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function vl(r,t={}){let{Fn:e}=r,n=t.randomBytes||Ue,o=Object.assign($a(r.Fp,e),{seed:Ho(e.ORDER)});function s(h){try{return!!Ge(e,h)}catch{return!1}}function i(h,p){let{publicKey:w,publicKeyUncompressed:S}=o;try{let y=h.length;return p===!0&&y!==w||p===!1&&y!==S?!1:!!r.fromBytes(h)}catch{return!1}}function a(h=n(o.seed)){return $o(xt(h,o.seed,"seed"),e.ORDER)}function c(h,p=!0){return r.BASE.multiply(Ge(e,h)).toBytes(p)}function u(h){let p=a(h);return{secretKey:p,publicKey:c(p)}}function d(h){if(typeof h=="bigint")return!1;if(h instanceof r)return!0;let{secretKey:p,publicKey:w,publicKeyUncompressed:S}=o;if(e.allowedLengths||p===w)return;let y=q("key",h).length;return y===w||y===S}function l(h,p,w=!0){if(d(h)===!0)throw new Error("first arg must be private key");if(d(p)===!1)throw new Error("second arg must be public key");let S=Ge(e,h);return r.fromHex(p).multiply(S).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:u,Point:r,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:h=>Ge(e,h),precompute(h=8,p=r.BASE){return p.precompute(h,!1)}},lengths:o})}function _l(r,t,e={}){Jr(t),ie(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||Ue,o=e.hmac||((m,...g)=>ws(t,m,lt(...g))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:h}=vl(r,e),p={prehash:!1,lowS:typeof e.lowS=="boolean"?e.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function S(m){let g=a>>Ze;return m>g}function y(m,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return g}function _(m,g){Ss(g);let v=h.signature,A=g==="compact"?v:g==="recovered"?v+1:void 0;return xt(m,A,`${g} signature`)}class x{constructor(g,v,A){this.r=y("r",g),this.s=y("s",v),A!=null&&(this.recovery=A),Object.freeze(this)}static fromBytes(g,v=w){_(g,v);let A;if(v==="der"){let{r:P,s:N}=Wt.toSig(xt(g));return new x(P,N)}v==="recovered"&&(A=g[0],v="compact",g=g.subarray(1));let L=i.BYTES,I=g.subarray(0,L),B=g.subarray(L,L*2);return new x(i.fromBytes(I),i.fromBytes(B),A)}static fromHex(g,v){return this.fromBytes(pe(g),v)}addRecoveryBit(g){return new x(this.r,this.s,g)}recoverPublicKey(g){let v=s.ORDER,{r:A,s:L,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*Va<v&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let P=I===2||I===3?A+a:A;if(!s.isValid(P))throw new Error("recovery id 2 or 3 invalid");let N=s.toBytes(P),Z=r.fromBytes(lt(Ha((I&1)===0),N)),z=i.inv(P),K=R(q("msgHash",g)),j=i.create(-K*z),Q=i.create(L*z),ht=r.BASE.multiplyUnsafe(j).add(Z.multiplyUnsafe(Q));if(ht.is0())throw new Error("point at infinify");return ht.assertValidity(),ht}hasHighS(){return S(this.s)}toBytes(g=w){if(Ss(g),g==="der")return pe(Wt.hexFromSig(this));let v=i.toBytes(this.r),A=i.toBytes(this.s);if(g==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return lt(Uint8Array.of(this.recovery),v,A)}return lt(v,A)}toHex(g){return At(this.toBytes(g))}assertValidity(){}static fromCompact(g){return x.fromBytes(q("sig",g),"compact")}static fromDER(g){return x.fromBytes(q("sig",g),"der")}normalizeS(){return this.hasHighS()?new x(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return At(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return At(this.toBytes("compact"))}}let D=e.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");let v=Me(g),A=g.length*8-c;return A>0?v>>BigInt(A):v},R=e.bits2int_modN||function(g){return i.create(D(g))},M=se(c);function U(m){return Sr("num < 2^"+c,m,Yt,M),i.toBytes(m)}function O(m,g){return xt(m,void 0,"message"),g?xt(t(m),void 0,"prehashed message"):m}function E(m,g,v){if(["recovered","canonical"].some(j=>j in v))throw new Error("sign() legacy options not supported");let{lowS:A,prehash:L,extraEntropy:I}=Es(v,p);m=O(m,L);let B=R(m),P=Ge(i,g),N=[U(P),U(B)];if(I!=null&&I!==!1){let j=I===!0?n(h.secretKey):I;N.push(q("extraEntropy",j))}let Z=lt(...N),z=B;function K(j){let Q=D(j);if(!i.isValidNot0(Q))return;let ht=i.inv(Q),X=r.BASE.multiply(Q).toAffine(),it=i.create(X.x);if(it===Yt)return;let zr=i.create(ht*i.create(z+it*P));if(zr===Yt)return;let ii=(X.x===it?0:2)|Number(X.y&Ze),ai=zr;return A&&S(zr)&&(ai=i.neg(zr),ii^=1),new x(it,ai,ii)}return{seed:Z,k2sig:K}}function C(m,g,v={}){m=q("message",m);let{seed:A,k2sig:L}=E(m,g,v);return aa(t.outputLen,i.BYTES,o)(A,L)}function k(m){let g,v=typeof m=="string"||Ft(m),A=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!A)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(A)g=new x(m.r,m.s);else if(v){try{g=x.fromBytes(q("sig",m),"der")}catch(L){if(!(L instanceof Wt.Err))throw L}if(!g)try{g=x.fromBytes(q("sig",m),"compact")}catch{return!1}}return g||!1}function T(m,g,v,A={}){let{lowS:L,prehash:I,format:B}=Es(A,p);if(v=q("publicKey",v),g=O(q("message",g),I),"strict"in A)throw new Error("options.strict was renamed to lowS");let P=B===void 0?k(m):x.fromBytes(q("sig",m),B);if(P===!1)return!1;try{let N=r.fromBytes(v);if(L&&P.hasHighS())return!1;let{r:Z,s:z}=P,K=R(g),j=i.inv(z),Q=i.create(K*j),ht=i.create(Z*j),X=r.BASE.multiplyUnsafe(Q).add(N.multiplyUnsafe(ht));return X.is0()?!1:i.create(X.x)===Z}catch{return!1}}function b(m,g,v={}){let{prehash:A}=Es(v,p);return g=O(g,A),x.fromBytes(m,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:h,Point:r,sign:C,verify:T,recoverPublicKey:b,Signature:x,hash:t})}function Al(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=wt(t.n,{BITS:r.nBitLength,allowedLengths:n,modFromBytes:r.wrapPrivateKey}),s={Fp:e,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:s}}function Il(r){let{CURVE:t,curveOpts:e}=Al(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,hash:r.hash,ecdsaOpts:n}}function Bl(r,t){let e=t.Point;return Object.assign({},t,{ProjectivePoint:e,CURVE:Object.assign({},r,on(e.Fn.ORDER,e.Fn.BITS))})}function Ga(r){let{CURVE:t,curveOpts:e,hash:n,ecdsaOpts:o}=Il(r),s=Sl(t,e),i=_l(s,n,o);return Bl(r,i)}function Za(r,t){let e=n=>Ga({...r,hash:n});return{...e(t),create:e}}var As={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Dl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ja=BigInt(2);function Cl(r){let t=As.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,d=u*u*r%t,l=$(d,e,t)*d%t,f=$(l,e,t)*d%t,h=$(f,ja,t)*u%t,p=$(h,o,t)*h%t,w=$(p,s,t)*p%t,S=$(w,a,t)*w%t,y=$(S,c,t)*S%t,_=$(y,a,t)*w%t,x=$(_,e,t)*d%t,D=$(x,i,t)*p%t,R=$(D,n,t)*u%t,M=$(R,ja,t);if(!_s.eql(_s.sqr(M),r))throw new Error("Cannot find square root");return M}var _s=wt(As.p,{sqrt:Cl}),je=Za({...As,Fp:_s,lowS:!0,endo:Dl},ra);function Xa(r,t,e,n){let o=dr.digest(e instanceof Uint8Array?e:e.subarray());if(ln(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),je.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new Ir(String(s))});try{return n?.signal?.throwIfAborted(),je.verify(t,o.digest,r)}catch(s){throw new Ir(String(s))}}var xn=class{type="secp256k1";raw;_key;constructor(t){this._key=Ya(t),this.raw=Wa(this._key)}toMultihash(){return Tt.digest(Oe(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,e,n){return Xa(this._key,e,t,n)}};function Qa(r){return new xn(r)}function Wa(r){return je.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Ya(r){try{return je.ProjectivePoint.fromHex(r),r}catch(t){throw new Hr(String(t))}}function Ja(r){let{Type:t,Data:e}=Tr.decode(r.digest),n=e??new Uint8Array;switch(t){case St.Ed25519:return La(n);case St.secp256k1:return Qa(n);case St.ECDSA:return Ki(n);default:throw new ir}}function Oe(r){return Tr.encode({Type:St[r.type],Data:r.raw})}var tc=Symbol.for("nodejs.util.inspect.custom"),Tl=114,Lr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[to]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return J.createV1(Tl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ft(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ft(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[tc](){return`PeerId(${this.toString()})`}},wn=class extends Lr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},En=class extends Lr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Sn=class extends Lr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ll=2336,vn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Tt.digest(V(this.url))}[tc](){return`PeerId(${this.url})`}[to]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return J.createV1(Ll,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function ec(r){if(Pl(r))return new wn({multihash:r});if(Rl(r))try{let t=Ja(r);if(t.type==="Ed25519")return new En({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Sn({multihash:r,publicKey:t})}catch{let e=H(r.digest);return new vn(new URL(e))}throw new $r("Supplied PeerID Multihash is invalid")}function Rl(r){return r.code===Tt.code}function Pl(r){return r.code===dr.code}function Is(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 _n(r){let t=fr(G.decode(`z${r}`));return ec(t)}var An=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 Is(this.set.entries(),t=>{let e=_n(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=_n(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Is(this.set.values(),t=>_n(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 Bs(){return new An}var Ds={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},rc={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},nc=new globalThis.TextEncoder;function Ol(r,t){let e=Ds[t],n=rc[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function kl(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Ds[t],o=rc[t],s=r;for(;s.length>0;){let i=nc.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function Cs(r,{size:t=32,utf8Buffer:e}={}){if(!Ds[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 kl(r,t,e);r=nc.encode(r)}return Ol(r,t)}var Rr={hash:r=>Number(Cs(r,{size:32})),hashV:(r,t)=>Nl(Rr.hash(r,t))};function Nl(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),V(t,"base16")}var Ts=64,Pt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Ts)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=bt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ft(this.fp,t.fp):!1}};function Se(r,t){return Math.floor(Math.random()*(t-r))+r}var ve=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Pt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Pt))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof Pt))throw new TypeError("Invalid Fingerprint");let e=Se(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Pt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Ul=500,Pr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Rr,this.seed=t.seed??Se(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=V(t));let e=new Pt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ve(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ve(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[Se(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ve(this.bucketSize));for(let a=0;a<Ul;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ve(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=V(t));let e=new Pt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=V(t));let e=new Pt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Ml={1:.5,2:.84,4:.95,8:.98};function Kl(r=.001){return r>.002?2:r>1e-5?4:8}function oc(r,t=.001){let e=Kl(t),n=Ml[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Ts);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var In=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??Rr,this.seed=t.seed??Se(0,Math.pow(2,10)),this.filterSeries=[new Pr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=V(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new Pr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=V(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=V(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function Ls(r,t=.001,e){return new In({...oc(r,t),...e??{}})}var Bn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let f=Number.parseInt(l,t);if(!Number.isNaN(f))return f});if(d===void 0)break;if(s*=t,s+=d,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var sc=45,Fl=15,Xe=new Bn;function Dn(r){if(!(r.length>Fl))return Xe.new(r).parseWith(()=>Xe.readIPv4Addr())}function Cn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>sc))return Xe.new(r).parseWith(()=>Xe.readIPv6Addr())}function We(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>sc)return;let e=Xe.new(r).parseWith(()=>Xe.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function ic(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function ac(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Rs(r){switch(r.length){case _e:return r.join(".");case Ae:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function cc(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function uc(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var _e=4,Ae=16,ky=parseInt("0xFFFF",16),ql=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Or(r,t){t.length===Ae&&r.length===_e&&ic(t,0,11)&&(t=t.slice(12)),t.length===_e&&r.length===Ae&&ac(r,ql,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function fc(r,t){if(typeof t=="string"&&(t=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 Ps(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=_e,o=Dn(t);if(o==null&&(n=Ae,o=Cn(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=Os(s,8*n);return{network:Or(o,i),mask:i}}function Os(r,t){if(t!==8*_e&&t!==8*Ae)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var Ye=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Ps(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=Os(o,8*n.length);this.network=Or(n,this.mask)}}contains(t){return fc({network:this.network,mask:this.mask},t)}toString(){let t=cc(this.mask),e=t!==-1?String(t):uc(this.mask);return Rs(this.network)+"/"+e}};function lc(r,t){return new Ye(r).contains(t)}var st=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Qt=class extends Error{static name="ValidationError";name="ValidationError"},kr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Tn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Qe(r){return!!Dn(r)}function Ln(r){return!!Cn(r)}function Ns(r){return t=>H(t,r)}function Us(r){return t=>V(t,r)}function Je(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Ie(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function dc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ie(n);return Mt([e,o],e.length+o.length)}function hc(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=ee.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=Ie(n);return Mt([e,o],e.length+o.length)}function Ms(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=H(t,"base32"),o=Je(e);return`${n}:${o}`}var Ks=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new st("Invalid byte value in IP address");t[n]=o}),t},pc=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Qe(e[n]),i;s&&(i=Ks(e[n]),e[n]=H(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,H(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new st("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},mc=function(r){if(r.byteLength!==4)throw new st("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},gc=function(r){if(r.byteLength!==16)throw new st("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${e}"`)}};function yc(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${r}"`)}}var ks=Object.values(hr).map(r=>r.decoder),zl=(function(){let r=ks[0].or(ks[1]);return ks.slice(2).forEach(t=>r=r.or(t)),r})();function bc(r){return zl.decode(r)}function xc(r){return t=>r.encoder.encode(t)}function Vl(r){if(parseInt(r).toString()!==r)throw new Qt("Value must be an integer")}function Hl(r){if(r<0)throw new Qt("Value must be a positive integer, or zero")}function $l(r){return t=>{if(t>r)throw new Qt(`Value must be smaller than or equal to ${r}`)}}function Gl(...r){return t=>{for(let e of r)e(t)}}var Nr=Gl(Vl,Hl,$l(65535));var nt=-1,Fs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new Tn(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},vt=new Fs,Sd=[{code:4,name:"ip4",size:32,valueToBytes:Ks,bytesToValue:mc,validate:r=>{if(!Qe(r))throw new Qt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ie,bytesToValue:Je,validate:Nr},{code:273,name:"udp",size:16,valueToBytes:Ie,bytesToValue:Je,validate:Nr},{code:33,name:"dccp",size:16,valueToBytes:Ie,bytesToValue:Je,validate:Nr},{code:41,name:"ip6",size:128,valueToBytes:pc,bytesToValue:gc,stringToValue:yc,validate:r=>{if(!Ln(r))throw new Qt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:nt},{code:43,name:"ipcidr",size:8,bytesToValue:Ns("base10"),valueToBytes:Us("base10")},{code:53,name:"dns",size:nt,resolvable:!0},{code:54,name:"dns4",size:nt,resolvable:!0},{code:55,name:"dns6",size:nt,resolvable:!0},{code:56,name:"dnsaddr",size:nt,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:Ie,bytesToValue:Je,validate:Nr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:nt,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:nt,bytesToValue:Ns("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Us("base58btc")(r):J.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ms,valueToBytes:dc},{code:445,name:"onion3",size:296,bytesToValue:Ms,valueToBytes:hc},{code:446,name:"garlic64",size:nt},{code:447,name:"garlic32",size:nt},{code:448,name:"tls"},{code:449,name:"sni",size:nt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:nt,bytesToValue:xc(go),valueToBytes:bc},{code:480,name:"http"},{code:481,name:"http-path",size:nt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:nt}];Sd.forEach(r=>{vt.addProtocol(r)});function wc(r){let t=[],e=0;for(;e<r.length;){let n=Br(r,e),o=vt.getProtocol(n),s=gt(n),i=vd(o,r,e+s),a=0;i>0&&o.size===nt&&(a=gt(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let d=e+s+a,l=r.subarray(d,d+i);u.value=o.bytesToValue?.(l)??H(l)}t.push(u),e+=c}return t}function Ec(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=vt.getProtocol(n.code),s=gt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===nt&&(c=gt(a)));let u=new Uint8Array(s+c+a),d=0;He(n.code,u,d),d+=s,i!=null&&(o.size===nt&&(He(a,u,d),d+=c),u.set(i,d)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return Mt(e,t)}function Sc(r){if(r.charAt(0)!=="/")throw new st('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=vt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new st(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new st(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new st("Incomplete multiaddr");return t}function vc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=vt.getProtocol(t.code);if(e==null)throw new st(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function vd(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Br(t,e)}var _d=Symbol.for("nodejs.util.inspect.custom"),Zs=Symbol.for("@multiformats/multiaddr"),Ad=[53,54,55,56],Gs=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Id(r){if(r==null&&(r="/"),Ac(r))return r.getComponents();if(r instanceof Uint8Array)return wc(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Sc(r);if(Array.isArray(r))return r;throw new st("Must be a string, Uint8Array, Component[], or another Multiaddr")}var kn=class r{[Zs]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Id(t),e.validate!==!1&&Bd(this)}get bytes(){return this.#r==null&&(this.#r=Ec(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=vc(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:c,value:u}of this.#t)a===42&&(s=`%${u??""}`),Ad.includes(a)&&(e="tcp",o=443,n=`${u??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=c==="tcp"?"tcp":"udp",o=parseInt(u??"")),(a===4||a===41)&&(e="tcp",n=`${u??""}${s}`,t=a===41?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}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=vt.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=vt.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??V(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new kr(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?H(G.decode(`z${n}`),"base58btc"):H(J.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(vt.getProtocol(t.code).path)return t.value??null;return null}equals(t){return ft(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=_c.get(e.name);if(n==null)throw new Gs(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Mr(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(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[_d](){return`Multiaddr(${this.toString()})`}};function Bd(r){r.getComponents().forEach(t=>{let e=vt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}var _c=new Map;function Ac(r){return!!r?.[Zs]}function Mr(r){return new kn(r)}function Ic(r){try{for(let{code:t,value:e}of r.getComponents())if(e!=null&&t===41)return lc("2000::/3",e)}catch{}return!1}function Bc(r){try{for(let{code:t}of r.getComponents())if(t!==42)return t===4||t===41}catch{}return!1}var Cc=Yc(Dc(),1),Dd=["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"],Cd=Dd.map(r=>new Cc.Netmask(r));function js(r){for(let t of Cd)if(t.contains(r))return!0;return!1}function Td(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Ld(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 js(o)}function Rd(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Pd(r){let t=r.split(":"),e=t[t.length-1];return js(e)}function Od(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 Nn(r){if(Qe(r))return js(r);if(Td(r))return Ld(r);if(Rd(r))return Pd(r);if(Ln(r))return Od(r)}function Tc(r){try{if(!Bc(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:Nn(t)??!1}catch{}return!0}function tr(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Un=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},er=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Un(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 Un(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 Xs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Mn(r={}){return kd(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 kd(r,t){t=t??{};let e=t.onEnd,n=new er,o,s,i,a=tr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((S,y)=>{s=_=>{s=null,n.push(_);try{S(r(n))}catch(x){y(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=tr()})}},u=S=>s!=null?s(S):(n.push(S),o),d=S=>(n=new er,s!=null?s({error:S}):(n.push({error:S}),o)),l=S=>{if(i)return o;if(t?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:S})},f=S=>i?o:(i=!0,S!=null?d(S):u({done:!0})),h=()=>(n=new er,f(),{done:!0}),p=S=>(f(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:l,end:f,get readableLength(){return n.size},onEmpty:async S=>{let y=S?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let _,x;y!=null&&(_=new Promise((D,R)=>{x=()=>{R(new Xs)},y.addEventListener("abort",x)}));try{await Promise.race([a.promise,_])}finally{x!=null&&y!=null&&y?.removeEventListener("abort",x)}}},e==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(S){return w.throw(S),e!=null&&(e(S),e=void 0),{done:!0}},return(){return w.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(S){return w.end(S),e!=null&&(e(S),e=void 0),o},get readableLength(){return w.readableLength},onEmpty:S=>w.onEmpty(S)},o}var Ws=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ys=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Lc=r=>globalThis.DOMException===void 0?new Ys(r):new DOMException(r),Rc=r=>{let t=r.reason===void 0?Lc("This operation was aborted."):r.reason;return t instanceof Error?t:Lc(t)};function Qs(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,u=new Promise((d,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:h}=t;h.aborted&&l(Rc(h)),a=()=>{l(Rc(h))},h.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(d,l);return}let f=new Ws;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(h){l(h)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?d():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${e} milliseconds`,l(f))},e),(async()=>{try{d(await r)}catch(h){l(h)}})()}).finally(()=>{u.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var Nd=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function Ud(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:d}=Nd(r),l=(...h)=>{let p=e.multiArgs?h:h[0];e.filter&&!e.filter(p)||(c.push(p),e.count===c.length&&(n(),s(c)))},f=h=>{n(),i(h)};n=()=>{for(let h of a)d(h,l);for(let h of e.rejectionEvents)d(h,f)};for(let h of a)u(h,l);for(let h of e.rejectionEvents)u(h,f);e.signal&&e.signal.addEventListener("abort",()=>{f(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=Qs(o,{milliseconds:e.timeout});return s.cancel=n,s}return o}function rr(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=Ud(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Fr(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Kn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Be=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Md(r){return r.reason}async function Fn(r,t,e){if(t==null)return r;let n=e?.translateError??Md;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var qn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=tr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Nt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Kd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var zn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=Kd(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,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 qn(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 Fn(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 Vn=class extends Gr{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=Fr(this.emitEmpty.bind(this),1),this.emitIdle=Fr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Kn;let n=new zn(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("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 rr(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await rr(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await rr(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=Mn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Nt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function qr(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}var Fd=4194304,Hn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ti=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ei=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ri=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function qd(r){return typeof r?.closeRead=="function"}function zd(r){return typeof r?.close=="function"}function Js(r){return qd(r)?r.readStatus==="closing"||r.readStatus==="closed":zd(r)?r.status!=="open":!1}function Vd(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Hd(r,t){let e=t?.maxBufferSize??Fd,n=new tt,o=Promise.withResolvers(),s=!1;if(!Vd(r))throw new Ct("Argument should be a Stream or a Multiaddr");let i=d=>{if(t?.stopPropagation,n.append(d.data),n.byteLength>e){let l=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${l} > ${e}`))}o.resolve()};r.addEventListener("message",i);let a=d=>{d.error!=null?o.reject(d.error):o.resolve()};r.addEventListener("close",a);let c=()=>{o.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(d){if(s===!0)throw new Hn("Stream was unwrapped");if(Js(r)){if(d?.bytes==null)return null;if(n.byteLength<d.bytes)throw new Be(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let l=d?.bytes??1;for(;;){if(n.byteLength>=l){o.resolve();break}if(await Fn(o.promise,d?.signal),Js(r)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let f=d?.bytes??n.byteLength;if(n.byteLength<f){if(Js(r))throw new Be(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return u.read(d)}let h=n.sublist(0,f);return n.consume(f),h},async write(d,l){if(s===!0)throw new Hn("Stream was unwrapped");r.send(d)||await rr(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function $d(r,t={}){let e=Hd(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=gt(t.maxDataLength));let n=t?.lengthDecoder??Br,o=t?.lengthEncoder??Ra;return{async read(i){let a=-1,c=new tt;for(;;){let d=await e.read({...i,bytes:1});if(d==null)break;c.append(d);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new ti("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ri(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ei(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await e.read({...i,bytes:a});if(u==null)throw new Be(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw new Be(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new tt(o(i.byteLength),i),a)},async writeV(i,a){let c=new tt(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function nr(r,t){let e=$d(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 $n=class extends Vn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Pc(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal};if(e?.timeout!=null){let d=qr([o.signal,AbortSignal.timeout(e.timeout)]);u.signal=d}s=!0,Promise.resolve().then(async()=>{await r(u)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Fr(i,e?.debounce??100),c=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{e??={},e.timeout=u},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var ni=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Oc(r){let{name:t,metrics:e}=r,n;return e!=null?n=new ni({name:t,metrics:e}):n=new Map,n}var oi="libp2p",si="autonat";var kc="dial-request",Nc="dial-back",Uc=200n*1024n,Mc=4096;var or;(function(r){let t;r.codec=()=>(t==null&&(t=Dt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e={...e},e.dialDataResponse!=null&&(e.dialDataRequest=void 0,e.dialResponse=void 0,e.dialRequest=void 0),e.dialDataRequest!=null&&(e.dialDataResponse=void 0,e.dialResponse=void 0,e.dialRequest=void 0),e.dialResponse!=null&&(e.dialDataResponse=void 0,e.dialDataRequest=void 0,e.dialRequest=void 0),e.dialRequest!=null&&(e.dialDataResponse=void 0,e.dialDataRequest=void 0,e.dialResponse=void 0),e.dialRequest!=null&&(n.uint32(10),Gn.codec().encode(e.dialRequest,n)),e.dialResponse!=null&&(n.uint32(18),Jt.codec().encode(e.dialResponse,n)),e.dialDataRequest!=null&&(n.uint32(26),Zn.codec().encode(e.dialDataRequest,n)),e.dialDataResponse!=null&&(n.uint32(34),Xn.codec().encode(e.dialDataResponse,n)),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.dialRequest=Gn.codec().decode(e,e.uint32(),{limits:o.limits?.dialRequest});break}case 2:{s.dialResponse=Jt.codec().decode(e,e.uint32(),{limits:o.limits?.dialResponse});break}case 3:{s.dialDataRequest=Zn.codec().decode(e,e.uint32(),{limits:o.limits?.dialDataRequest});break}case 4:{s.dialDataResponse=Xn.codec().decode(e,e.uint32(),{limits:o.limits?.dialDataResponse});break}default:{e.skipType(a&7);break}}}return s.dialDataResponse!=null&&(delete s.dialDataRequest,delete s.dialResponse,delete s.dialRequest),s.dialDataRequest!=null&&(delete s.dialDataResponse,delete s.dialResponse,delete s.dialRequest),s.dialResponse!=null&&(delete s.dialDataResponse,delete s.dialDataRequest,delete s.dialRequest),s.dialRequest!=null&&(delete s.dialDataResponse,delete s.dialDataRequest,delete s.dialResponse),s})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>It(e,r.codec(),n)})(or||(or={}));var Gn;(function(r){let t;r.codec=()=>(t==null&&(t=Dt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.addrs!=null)for(let s of e.addrs)n.uint32(10),n.bytes(s);e.nonce!=null&&e.nonce!==0n&&(n.uint32(17),n.fixed64(e.nonce)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={addrs:[],nonce:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(o.limits?.addrs!=null&&s.addrs.length===o.limits.addrs)throw new gn('Decode error - map field "addrs" had too many elements');s.addrs.push(e.bytes());break}case 2:{s.nonce=e.fixed64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>It(e,r.codec(),n)})(Gn||(Gn={}));var Zn;(function(r){let t;r.codec=()=>(t==null&&(t=Dt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.addrIdx!=null&&e.addrIdx!==0&&(n.uint32(8),n.uint32(e.addrIdx)),e.numBytes!=null&&e.numBytes!==0n&&(n.uint32(16),n.uint64(e.numBytes)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={addrIdx:0,numBytes:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.addrIdx=e.uint32();break}case 2:{s.numBytes=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>It(e,r.codec(),n)})(Zn||(Zn={}));var ut;(function(r){r.UNUSED="UNUSED",r.E_DIAL_ERROR="E_DIAL_ERROR",r.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",r.OK="OK"})(ut||(ut={}));var jn;(function(r){r[r.UNUSED=0]="UNUSED",r[r.E_DIAL_ERROR=100]="E_DIAL_ERROR",r[r.E_DIAL_BACK_ERROR=101]="E_DIAL_BACK_ERROR",r[r.OK=200]="OK"})(jn||(jn={}));(function(r){r.codec=()=>Ee(jn)})(ut||(ut={}));var Jt;(function(r){let t;(function(o){o.E_INTERNAL_ERROR="E_INTERNAL_ERROR",o.E_REQUEST_REJECTED="E_REQUEST_REJECTED",o.E_DIAL_REFUSED="E_DIAL_REFUSED",o.OK="OK"})(t=r.ResponseStatus||(r.ResponseStatus={}));let e;(function(o){o[o.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",o[o.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",o[o.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",o[o.OK=200]="OK"})(e||(e={})),(function(o){o.codec=()=>Ee(e)})(t=r.ResponseStatus||(r.ResponseStatus={}));let n;r.codec=()=>(n==null&&(n=Dt((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.status!=null&&e[o.status]!==0&&(s.uint32(8),r.ResponseStatus.codec().encode(o.status,s)),o.addrIdx!=null&&o.addrIdx!==0&&(s.uint32(16),s.uint32(o.addrIdx)),o.dialStatus!=null&&jn[o.dialStatus]!==0&&(s.uint32(24),ut.codec().encode(o.dialStatus,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:ut.UNUSED},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.status=r.ResponseStatus.codec().decode(o);break}case 2:{a.addrIdx=o.uint32();break}case 3:{a.dialStatus=ut.codec().decode(o);break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>Bt(o,r.codec()),r.decode=(o,s)=>It(o,r.codec(),s)})(Jt||(Jt={}));var Xn;(function(r){let t;r.codec=()=>(t==null&&(t=Dt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.data!=null&&e.data.byteLength>0&&(n.uint32(10),n.bytes(e.data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={data:bt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>It(e,r.codec(),n)})(Xn||(Xn={}));var sr;(function(r){let t;r.codec=()=>(t==null&&(t=Dt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.nonce!=null&&e.nonce!==0n&&(n.uint32(9),n.fixed64(e.nonce)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={nonce:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.nonce=e.fixed64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>It(e,r.codec(),n)})(sr||(sr={}));var le;(function(r){let t;(function(o){o.OK="OK"})(t=r.DialBackStatus||(r.DialBackStatus={}));let e;(function(o){o[o.OK=0]="OK"})(e||(e={})),(function(o){o.codec=()=>Ee(e)})(t=r.DialBackStatus||(r.DialBackStatus={}));let n;r.codec=()=>(n==null&&(n=Dt((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.status!=null&&e[o.status]!==0&&(s.uint32(8),r.DialBackStatus.codec().encode(o.status,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={status:t.OK},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.status=r.DialBackStatus.codec().decode(o);break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>Bt(o,r.codec()),r.decode=(o,s)=>It(o,r.codec(),s)})(le||(le={}));function Wn(r,t){return Math.round(Math.random()*(t-r)+r)}var Zd=4,jd=8,Yn=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:client"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.connectionThreshold=e.connectionThreshold??80,this.maxMessageSize=e.maxMessageSize??8192,this.dialResults=Oc({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=Pc(this.findRandomPeers.bind(this),6e4),this.addressFilter=Ls(1024),this.queue=new $n({concurrency:3,maxSize:50}),this.maxDialDataBytes=e.maxDialDataBytes??Uc,this.dialDataChunkSize=e.dialDataChunkSize??Mc,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[Zr]=["@libp2p/autonat"];get[jr](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.components.registrar.register(this.dialRequestProtocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),await this.components.registrar.handle(this.dialBackProtocol,(t,e)=>{this.handleDialBackStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),await this.components.registrar.unhandle(this.dialBackProtocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=qr([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleDialBackStream(t,e){let n=AbortSignal.timeout(this.timeout);let o=nr(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read(sr,{signal:n});if(!this.nonces.has(s.nonce))throw new _t("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:le.DialBackStatus.OK},le),await t.close({signal:n})}catch(s){this.log.error("error handling incoming dial back stream - %e",s),t.abort(s)}}getUnverifiedMultiaddrs(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((s,i)=>s.type==="observed"&&i.type!=="observed"?1:i.type==="observed"&&s.type!=="observed"?-1:0).filter(s=>!(!(s.expires<Date.now())||s.multiaddr.toOptions().family===6&&(!e||!Ic(s.multiaddr))||Tc(s.multiaddr))),o=[];for(let s of n){let i=s.multiaddr.toString(),a=this.dialResults.get(i);if(a!=null&&a.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",a.multiaddr,t);continue}if(a==null){let c=s.expires<Date.now();if(c&&this.addressFilter.remove?.(i),this.addressFilter.has(i))continue;this.addressFilter.add(i),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",i),a={multiaddr:s.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:Bs(),type:s.type,lastVerified:s.lastVerified},this.dialResults.set(i,a)}o.push(a)}return o}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>i.toOptions().family===6),o=this.getNetworkSegment(t.remoteAddr),s=this.getUnverifiedMultiaddrs(o,n);if(s.length!==0){if(!this.hasConnectionCapacity()){s[0]?.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s[0].multiaddr),this.confirmAddress(s[0])):this.log("skipping verifying %a because we are too close to the connection limit",s[0]?.multiaddr);return}this.queue.add(async i=>{let a=qr([i.signal,AbortSignal.timeout(this.timeout)]),c=BigInt(Wn(0,Number.MAX_SAFE_INTEGER));this.nonces.add(c);try{await this.askPeerToVerify(t,o,c,i)}finally{a.clear(),this.nonces.delete(c)}},{peerId:t.remotePeer}).catch(i=>{this.log.error("error from %p verifying addresses - %e",t.remotePeer,i)})}}async askPeerToVerify(t,e,n,o){let s=[...this.dialResults.values()].filter(a=>a.result==null).map(a=>a.multiaddr);if(s.length===0){this.queue.clear();return}this.log.trace("asking %a to verify multiaddrs %s",t.remoteAddr,s);let i=await t.newStream(this.dialRequestProtocol,o);try{let a=nr(i).pb(or);await a.write({dialRequest:{addrs:s.map(c=>c.bytes),nonce:n}},o);for(let c=0;c<s.length;c++){let u=await a.read(o);if(u.dialDataRequest!=null){if(u.dialDataRequest.numBytes>this.maxDialDataBytes){this.log("too many dial data byte requested by %p - %s/%s",t.remotePeer,u.dialDataRequest.numBytes,this.maxDialDataBytes);continue}this.log("sending %d bytes to %p as anti-amplification attack protection",u.dialDataRequest.numBytes,t.remotePeer);let h=new Uint8Array(this.dialDataChunkSize),p=BigInt(this.dialDataChunkSize);for(let w=0n;w<u.dialDataRequest.numBytes;w+=p)await a.write({dialDataResponse:{data:h}},o);u=await a.read(o)}if(u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}if(u.dialResponse.status!==Jt.ResponseStatus.OK)return;let l=s[u.dialResponse.addrIdx];if(l==null){this.log.trace("peer dialed unknown address");continue}let f=this.dialResults.get(l.toString());if(f==null){this.log.trace("peer reported %a as %s but there is no result object",l,u.dialResponse.status);continue}if(f.networkSegments.includes(e)){this.log.trace("%a results already included network segment %s",l,e);continue}if(f.result!=null){this.log.trace("already resolved result for %a, ignoring response from",l,t.remotePeer);continue}if(f.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,l);continue}if(f.verifyingPeers.add(t.remotePeer),f.networkSegments.push(e),u.dialResponse.dialStatus===ut.OK){if(this.log.trace("%p dialed %a successfully",t.remotePeer,f.multiaddr),f.success++,f.type!=="observed"){this.confirmAddress(f);continue}}else if(u.dialResponse.dialStatus===ut.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,f.multiaddr),f.failure++;else if(u.dialResponse.dialStatus===ut.E_DIAL_BACK_ERROR){this.log.trace("%p saw error while dialing %a",t.remotePeer,f.multiaddr);continue}this.log("%a success %d failure %d",f.multiaddr,f.success,f.failure),f.success===Zd&&this.confirmAddress(f),f.failure===jd&&this.unconfirmAddress(f)}}finally{try{await i.close(o)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1}getNetworkSegment(t){let e=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};var Qn=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:server"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.maxMessageSize=e.maxMessageSize??8192,this.handleDialRequestStream=this.handleDialRequestStream.bind(this)}async start(){this.started||(await this.components.registrar.handle(this.dialRequestProtocol,this.handleDialRequestStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),this.started=!1}async handleDialRequestStream(t,e){let n=AbortSignal.timeout(this.timeout);let o=nr(t,{maxDataLength:this.maxMessageSize}).pb(or),s=Vc(e.remoteAddr);if(s==null)throw new _t(`Could not find IP address in connection address "${e.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new _t("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new _t("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=Mr(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:Jt.ResponseStatus.E_DIAL_REFUSED,dialStatus:ut.UNUSED}},{signal:n});continue}let d=Vc(c);if(d==null)throw new _t(`Could not find IP address in requested address "${c}"`);if(Nn(d))throw new _t(`Requested address had private IP "${c}"`);d!==s&&await this.preventAmplificationAttack(o,a,{signal:n});let l=await this.dialClientBack(c,i.nonce,{signal:n});await o.write({dialResponse:{addrIdx:a,status:Jt.ResponseStatus.OK,dialStatus:l}},{signal:n})}catch(c){this.log.error("error handling incoming dialback request - %e",c)}await t.close({signal:n})}async preventAmplificationAttack(t,e,n){let o=Wn(3e4,1e5);await t.write({dialDataRequest:{addrIdx:e,numBytes:BigInt(o)}},n);let s=0;for(;s<o;){let{dialDataResponse:i}=await t.read(n);if(i==null)throw new _t("Did not receive DialDataResponse message on incoming dial request stream");s+=i.data.byteLength}}async dialClientBack(t,e,n){let o;try{o=await this.components.connectionManager.openConnection(t,{force:!0,...n})}catch(s){return this.log.error("failed to open connection to %a - %e",s,t),ut.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=nr(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:e},sr,n),(await i.read(le,n)).status!==le.DialBackStatus.OK)throw new _t("DialBackResponse status was not OK");await o.close(n)}catch(s){return this.log.error("could not perform dial back - %e",s),o.abort(s),ut.E_DIAL_BACK_ERROR}return ut.OK}};function Vc(r){return r.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var Jn=class{client;server;constructor(t,e){let n=`/${e.protocolPrefix??oi}/${si}/${"2"}/${kc}`,o=`/${e.protocolPrefix??oi}/${si}/${"2"}/${Nc}`;this.client=new Yn(t,{...e,dialRequestProtocol:n,dialBackProtocol:o}),this.server=new Qn(t,{...e,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[Zr]=["@libp2p/autonat"];get[jr](){return["@libp2p/identify"]}async start(){await fi(this.client,this.server)}async stop(){await li(this.client,this.server)}};function Xd(r={}){return t=>new Jn(t,r)}return Qc(Wd);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|