@libp2p/autonat 2.0.38 → 3.0.0-049bfa0fa

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PAutonat=(()=>{var vc=Object.create;var Nr=Object.defineProperty;var Ac=Object.getOwnPropertyDescriptor;var Ic=Object.getOwnPropertyNames;var Bc=Object.getPrototypeOf,Tc=Object.prototype.hasOwnProperty;var Cc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var r in t)Nr(e,r,{get:t[r],enumerable:!0})},$s=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ic(t))!Tc.call(e,o)&&o!==r&&Nr(e,o,{get:()=>t[o],enumerable:!(n=Ac(t,o))||n.enumerable});return e};var Dc=(e,t,r)=>(r=e!=null?vc(Bc(e)):{},$s(t||!e||!e.__esModule?Nr(r,"default",{value:e,enumerable:!0}):r,e)),Lc=e=>$s(Nr({},"__esModule",{value:!0}),e);var fc=Cc(Pr=>{(function(){var e,t,r,n,o,s,i,c;c=function(a){var u,h,f,l;return u=(a&255<<24)>>>24,h=(a&255<<16)>>>16,f=(a&65280)>>>8,l=a&255,[u,h,f,l].join(".")},i=function(a){var u,h,f,l,p,d;for(u=[],f=l=0;l<=3&&a.length!==0;f=++l){if(f>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}d=t(a),p=d[0],h=d[1],a=a.substring(h),u.push(p)}if(a.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")}},r=function(a){return a.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),t=function(a){var u,h,f,l,p;for(l=0,u=10,h="9",f=0,a.length>1&&a[f]==="0"&&(a[f+1]==="x"||a[f+1]==="X"?(f+=2,u=16):"0"<=a[f+1]&&a[f+1]<="9"&&(f++,u=8,h="7")),p=f;f<a.length;){if("0"<=a[f]&&a[f]<=h)l=l*u+(r(a[f])-n)>>>0;else if(u===16)if("a"<=a[f]&&a[f]<="f")l=l*u+(10+r(a[f])-s)>>>0;else if("A"<=a[f]&&a[f]<="F")l=l*u+(10+r(a[f])-o)>>>0;else break;else break;if(l>4294967295)throw new Error("too large");f++}if(f===p)throw new Error("empty octet");return[l,f]},e=(function(){function a(u,h){var f,l,p,d;if(typeof u!="string")throw new Error("Missing `net' parameter");if(h||(d=u.split("/",2),u=d[0],h=d[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(x){throw f=x,new Error("Invalid mask: "+h)}for(l=p=32;p>=0;l=--p)if(this.maskLong===4294967295<<32-l>>>0){this.bitmask=l;break}}else if(h||h===0)this.bitmask=parseInt(h,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(x){throw f=x,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+h);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var h,f,l;for(l=i(this.first),f=i(this.last),h=0;l<=f;)u(c(l),l,h),h++,l++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a})(),Pr.ip2long=i,Pr.long2ip=c,Pr.Netmask=e}).call(Pr)});var vh={};bt(vh,{autoNAT:()=>Sh});var qn=Symbol.for("@libp2p/peer-id");var Lt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Pt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ur=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var kr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var tr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Mr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Gs=Symbol.for("@libp2p/service-capabilities"),Zs=Symbol.for("@libp2p/service-dependencies");var Gn={};bt(Gn,{base58btc:()=>G,base58flickr:()=>Mc});var Wh=new Uint8Array(0);function Xs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Rt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ws(e){return new TextEncoder().encode(e)}function Ys(e){return new TextDecoder().decode(e)}function Pc(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),h=Math.log(256)/Math.log(c);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var x=0,E=0,y=0,v=d.length;y!==v&&d[y]===0;)y++,x++;for(var w=(v-y)*h+1>>>0,T=new Uint8Array(w);y!==v;){for(var P=d[y],M=0,k=w-1;(P!==0||M<E)&&k!==-1;k--,M++)P+=256*T[k]>>>0,T[k]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");E=M,y++}for(var O=w-E;O!==w&&T[O]===0;)O++;for(var _=a.repeat(x);O<w;++O)_+=e.charAt(T[O]);return _}function l(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var x=0;if(d[x]!==" "){for(var E=0,y=0;d[x]===a;)E++,x++;for(var v=(d.length-x)*u+1>>>0,w=new Uint8Array(v);d[x];){var T=r[d.charCodeAt(x)];if(T===255)return;for(var P=0,M=v-1;(T!==0||P<y)&&M!==-1;M--,P++)T+=c*w[M]>>>0,w[M]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");y=P,x++}if(d[x]!==" "){for(var k=v-y;k!==v&&w[k]===0;)k++;for(var O=new Uint8Array(E+(v-k)),_=E;k!==v;)O[_++]=w[k++];return O}}}function p(d){var x=l(d);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:l,decode:p}}var Rc=Pc,Oc=Rc,Js=Oc;var Vn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Hn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ti(this,t)}},jn=class{decoders;constructor(t){this.decoders=t}or(t){return ti(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ti(e,t){return new jn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var $n=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Vn(t,r,n),this.decoder=new Hn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:e,prefix:t,encode:r,decode:n}){return new $n(e,t,r,n)}function Jt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Js(r,e);return Ae({prefix:t,name:e,encode:n,decode:s=>Rt(o(s))})}function Nc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let h=t[e[u]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|h,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Uc(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function kc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=kc(n);return Ae({prefix:t,name:e,encode(s){return Uc(s,n,r)},decode(s){return Nc(s,o,r,e)}})}var G=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Mc=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zn={};bt(Zn,{base32:()=>te,base32hex:()=>qc,base32hexpad:()=>Hc,base32hexpadupper:()=>jc,base32hexupper:()=>Vc,base32pad:()=>Fc,base32padupper:()=>zc,base32upper:()=>Kc,base32z:()=>$c});var te=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Fc=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),zc=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),qc=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vc=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Hc=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),jc=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$c=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xn={};bt(Xn,{base36:()=>er,base36upper:()=>Gc});var er=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Gc=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Zc=ni,ei=128,Xc=127,Wc=~Xc,Yc=Math.pow(2,31);function ni(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Yc;)t[r++]=e&255|ei,e/=128;for(;e&Wc;)t[r++]=e&255|ei,e>>>=7;return t[r]=e|0,ni.bytes=r-n+1,t}var Qc=Wn,Jc=128,ri=127;function Wn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Wn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ri)<<o:(i&ri)*Math.pow(2,o),o+=7}while(i>=Jc);return Wn.bytes=s-n,r}var tu=Math.pow(2,7),eu=Math.pow(2,14),ru=Math.pow(2,21),nu=Math.pow(2,28),ou=Math.pow(2,35),su=Math.pow(2,42),iu=Math.pow(2,49),au=Math.pow(2,56),cu=Math.pow(2,63),uu=function(e){return e<tu?1:e<eu?2:e<ru?3:e<nu?4:e<ou?5:e<su?6:e<iu?7:e<au?8:e<cu?9:10},fu={encode:Zc,decode:Qc,encodingLength:uu},lu=fu,rr=lu;function nr(e,t=0){return[rr.decode(e,t),rr.decode.bytes]}function Ie(e,t,r=0){return rr.encode(e,t,r),t}function Be(e){return rr.encodingLength(e)}function Ce(e,t){let r=t.byteLength,n=Be(e),o=n+Be(r),s=new Uint8Array(o+r);return Ie(e,s,0),Ie(r,s,n),s.set(t,o),new Te(e,r,t,s)}function fe(e){let t=Rt(e),[r,n]=nr(t),[o,s]=nr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Te(r,o,i,t)}function oi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Xs(e.bytes,r.bytes)}}var Te=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function si(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return du(r,Yn(e),t??G.encoder);default:return pu(r,Yn(e),t??te.encoder)}}var ii=new WeakMap;function Yn(e){let t=ii.get(e);if(t==null){let r=new Map;return ii.set(e,r),r}return t}var et=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,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:r}=this;if(t!==or)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==mu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ce(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&oi(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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??ai(n,o,s.bytes))}else if(r[gu]===!0){let{version:n,multihash:o,code:s}=r,i=fe(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==or)throw new Error(`Version 0 CID must use dag-pb (code: ${or}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ai(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,or,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Rt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Te(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[f,l]=nr(t.subarray(r));return r+=l,f},o=n(),s=or;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,h=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:h,size:u}}static parse(t,r){let[n,o]=hu(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Yn(s).set(n,t),s}};function hu(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case te.prefix:{let r=t??te;return[te.prefix,r.decode(e)]}case er.prefix:{let r=t??er;return[er.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function du(e,t,r){let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function pu(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var or=112,mu=18;function ai(e,t,r){let n=Be(e),o=n+Be(t),s=new Uint8Array(o+r.byteLength);return Ie(e,s,0),Ie(t,s,n),s.set(r,o),s}var gu=Symbol.for("@ipld/js-cid/CID");var Qn={};bt(Qn,{identity:()=>vt});var ci=0,yu="identity",ui=Rt;function bu(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Ce(ci,ui(e))}var vt={code:ci,name:yu,encode:ui,digest:bu};function ft(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function At(e=0){return new Uint8Array(e)}function pt(e=0){return new Uint8Array(e)}function Ot(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=pt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var li=Symbol.for("@achingbrain/uint8arraylist");function fi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Fr(e){return!!e?.[li]}var tt=class e{bufs;length;[li]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Fr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Fr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=fi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=fi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Fr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Ot(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ot(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,h=r>c&&r<=a;if(u&&h){if(t===c&&r===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(h){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Fr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,h;for(let f=r;f<=a;f+=h){h=0;for(let l=u;l>=0;l--){let p=this.get(f+l);if(n[l]!==p){h=Math.max(1,l-c[p]);break}}if(h===0)return f}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=At(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=At(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=At(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=At(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=At(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=At(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=At(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=At(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ft(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Jn={};bt(Jn,{base10:()=>xu});var xu=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var to={};bt(to,{base16:()=>wu,base16upper:()=>Eu});var wu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Eu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var eo={};bt(eo,{base2:()=>_u});var _u=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ro={};bt(ro,{base256emoji:()=>Bu});var hi=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}"),Su=hi.reduce((e,t,r)=>(e[r]=t,e),[]),vu=hi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Au(e){return e.reduce((t,r)=>(t+=Su[r],t),"")}function Iu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=vu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Bu=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:Au,decode:Iu});var oo={};bt(oo,{base64:()=>Tu,base64pad:()=>Cu,base64url:()=>no,base64urlpad:()=>Du});var Tu=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Cu=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),no=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Du=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var so={};bt(so,{base8:()=>Lu});var Lu=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var io={};bt(io,{identity:()=>Pu});var Pu=Ae({prefix:"\0",name:"identity",encode:e=>Ys(e),decode:e=>Ws(e)});var Rd=new TextEncoder,Od=new TextDecoder;var uo={};bt(uo,{sha256:()=>sr,sha512:()=>Uu});var Nu=20;function co({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new ao(e,t,r,n,o)}var ao=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Nu,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?di(n,this.code,r?.truncate):n.then(o=>di(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function di(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Ce(t,e)}function mi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var sr=co({name:"sha2-256",code:18,encode:mi("SHA-256")}),Uu=co({name:"sha2-512",code:19,encode:mi("SHA-512")});var ir={...io,...eo,...so,...Jn,...to,...Zn,...Xn,...Gn,...oo,...ro},$d={...uo,...Qn};function yi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var gi=yi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),fo=yi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=pt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),ku={utf8:gi,"utf-8":gi,hex:ir.base16,latin1:fo,ascii:fo,binary:fo,...ir},zr=ku;function V(e,t="utf8"){let r=zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function j(e,t="utf8"){let r=zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Mu=parseInt("11111",2),lo=parseInt("10000000",2),Ku=parseInt("01111111",2),bi={0:ar,1:ar,2:Fu,3:Vu,4:Hu,5:qu,6:zu,16:ar,22:ar,48:ar};function ho(e,t={offset:0}){let r=e[t.offset]&Mu;if(t.offset++,bi[r]!=null)return bi[r](e,t);throw new Error("No decoder for tag "+r)}function cr(e,t){let r=0;if((e[t.offset]&lo)===lo){let n=e[t.offset]&Ku,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function ar(e,t){cr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=ho(e,t);if(n===null)break;r.push(n)}return r}function Fu(e,t){let r=cr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function zu(e,t){let r=cr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let h=0;for(let f=0;f<a.length;f++)h+=a[f]<<f*7;c+=`.${h}`,a=[]}}return c}function qu(e,t){return t.offset++,null}function Vu(e,t){let r=cr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Hu(e,t){let r=cr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ju(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new tt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function po(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ju(e.byteLength);return new tt(Uint8Array.from([t.byteLength|lo]),t)}function xi(e){let t=new tt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new tt(Uint8Array.from([2]),po(t),t)}function wi(e){let t=Uint8Array.from([0]),r=new tt(t,e);return new tt(Uint8Array.from([3]),po(r),r)}function qr(e,t=48){let r=new tt;for(let n of e)r.append(n);return new tt(Uint8Array.from([t]),po(r),r)}async function Ei(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var $u=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Gu=Uint8Array.from([6,5,43,129,4,0,34]),Zu=Uint8Array.from([6,5,43,129,4,0,35]),Xu={ext:!0,kty:"EC",crv:"P-256"},Wu={ext:!0,kty:"EC",crv:"P-384"},Yu={ext:!0,kty:"EC",crv:"P-521"},mo=32,go=48,yo=66;function _i(e){let t=ho(e);return Si(t)}function Si(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===mo*2+1)return n=j(t.subarray(r,r+mo),"base64url"),o=j(t.subarray(r+mo),"base64url"),new De({...Xu,key_ops:["verify"],x:n,y:o});if(t.byteLength===go*2+1)return n=j(t.subarray(r,r+go),"base64url"),o=j(t.subarray(r+go),"base64url"),new De({...Wu,key_ops:["verify"],x:n,y:o});if(t.byteLength===yo*2+1)return n=j(t.subarray(r,r+yo),"base64url"),o=j(t.subarray(r+yo),"base64url"),new De({...Yu,key_ops:["verify"],x:n,y:o});throw new Pt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function vi(e){return qr([xi(Uint8Array.from([1])),qr([Qu(e.crv)],160),qr([wi(new tt(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Qu(e){if(e==="P-256")return $u;if(e==="P-384")return Gu;if(e==="P-521")return Zu;throw new Pt(`Invalid curve ${e}`)}var De=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=vi(this.jwk)),this._raw}toMultihash(){return vt.digest(Le(this))}toCID(){return et.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,r,n){return Ei(this.jwk,r,t,n)}};var le=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ut(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ur(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function mt(e,...t){if(!Ut(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Vr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ur(e.outputLen),ur(e.blockLen)}function Re(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ii(e,t){mt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function kt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Hr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var Bi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ju=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function St(e){if(mt(e),Bi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Ju[e[r]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ai(e){if(e>=Nt._0&&e<=Nt._9)return e-Nt._0;if(e>=Nt.A&&e<=Nt.F)return e-(Nt.A-10);if(e>=Nt.a&&e<=Nt.f)return e-(Nt.a-10)}function he(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Bi)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ai(e.charCodeAt(s)),c=Ai(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function bo(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function fr(e){return typeof e=="string"&&(e=bo(e)),mt(e),e}function lt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];mt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Pe=class{};function xo(e){let t=n=>e().update(fr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Oe(e=32){if(le&&typeof le.getRandomValues=="function")return le.getRandomValues(new Uint8Array(e));if(le&&typeof le.randomBytes=="function")return Uint8Array.from(le.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function tf(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function Ti(e,t,r){return e&t^~e&r}function Ci(e,t,r){return e&t^e&r^t&r}var lr=class extends Pe{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Hr(this.buffer)}update(t){Re(this),t=fr(t),mt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Hr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),Ii(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,kt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;tf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Hr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,h[f],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var jr=BigInt(4294967295),Di=BigInt(32);function ef(e,t=!1){return t?{h:Number(e&jr),l:Number(e>>Di&jr)}:{h:Number(e>>Di&jr)|0,l:Number(e&jr)|0}}function Li(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=ef(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var wo=(e,t,r)=>e>>>r,Eo=(e,t,r)=>e<<32-r|t>>>r,de=(e,t,r)=>e>>>r|t<<32-r,pe=(e,t,r)=>e<<32-r|t>>>r,hr=(e,t,r)=>e<<64-r|t>>>r-32,dr=(e,t,r)=>e>>>r-32|t<<64-r;function Dt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Pi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ri=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Oi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ni=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ui=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ki=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var nf=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),_o=class extends lr{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:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let f=0;f<16;f++,r+=4)re[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){let l=re[f-15],p=re[f-2],d=It(l,7)^It(l,18)^l>>>3,x=It(p,17)^It(p,19)^p>>>10;re[f]=x+re[f-7]+d+re[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:h}=this;for(let f=0;f<64;f++){let l=It(c,6)^It(c,11)^It(c,25),p=h+l+Ti(c,a,u)+nf[f]+re[f]|0,x=(It(n,2)^It(n,13)^It(n,22))+Ci(n,o,s)|0;h=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,h=h+this.H|0,this.set(n,o,s,i,c,a,u,h)}roundClean(){kt(re)}destroy(){this.set(0,0,0,0,0,0,0,0),kt(this.buffer)}};var Mi=Li(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),of=Mi[0],sf=Mi[1],ne=new Uint32Array(80),oe=new Uint32Array(80),So=class extends lr{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:h,Fh:f,Fl:l,Gh:p,Gl:d,Hh:x,Hl:E}=this;return[t,r,n,o,s,i,c,a,u,h,f,l,p,d,x,E]}set(t,r,n,o,s,i,c,a,u,h,f,l,p,d,x,E){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=h|0,this.Fh=f|0,this.Fl=l|0,this.Gh=p|0,this.Gl=d|0,this.Hh=x|0,this.Hl=E|0}process(t,r){for(let w=0;w<16;w++,r+=4)ne[w]=t.getUint32(r),oe[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let T=ne[w-15]|0,P=oe[w-15]|0,M=de(T,P,1)^de(T,P,8)^wo(T,P,7),k=pe(T,P,1)^pe(T,P,8)^Eo(T,P,7),O=ne[w-2]|0,_=oe[w-2]|0,C=de(O,_,19)^hr(O,_,61)^wo(O,_,6),N=pe(O,_,19)^dr(O,_,61)^Eo(O,_,6),D=Oi(k,N,oe[w-7],oe[w-16]),b=Ni(D,M,C,ne[w-7],ne[w-16]);ne[w]=b|0,oe[w]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:h,Eh:f,El:l,Fh:p,Fl:d,Gh:x,Gl:E,Hh:y,Hl:v}=this;for(let w=0;w<80;w++){let T=de(f,l,14)^de(f,l,18)^hr(f,l,41),P=pe(f,l,14)^pe(f,l,18)^dr(f,l,41),M=f&p^~f&x,k=l&d^~l&E,O=Ui(v,P,k,sf[w],oe[w]),_=ki(O,y,T,M,of[w],ne[w]),C=O|0,N=de(n,o,28)^hr(n,o,34)^hr(n,o,39),D=pe(n,o,28)^dr(n,o,34)^dr(n,o,39),b=n&s^n&c^s&c,m=o&i^o&a^i&a;y=x|0,v=E|0,x=p|0,E=d|0,p=f|0,d=l|0,{h:f,l}=Dt(u|0,h|0,_|0,C|0),u=c|0,h=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let g=Pi(C,D,m);n=Ri(g,_,N,b),o=g|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Dt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:h}=Dt(this.Dh|0,this.Dl|0,u|0,h|0),{h:f,l}=Dt(this.Eh|0,this.El|0,f|0,l|0),{h:p,l:d}=Dt(this.Fh|0,this.Fl|0,p|0,d|0),{h:x,l:E}=Dt(this.Gh|0,this.Gl|0,x|0,E|0),{h:y,l:v}=Dt(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,o,s,i,c,a,u,h,f,l,p,d,x,E,y,v)}roundClean(){kt(ne,oe)}destroy(){kt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ki=xo(()=>new _o);var Fi=xo(()=>new So);var Io=BigInt(0),Ao=BigInt(1);function Kt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xt(e,t,r=""){let n=Ut(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function pr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function zi(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Io:BigInt("0x"+e)}function Ne(e){return zi(St(e))}function Ft(e){return mt(e),zi(St(Uint8Array.from(e).reverse()))}function $r(e,t){return he(e.toString(16).padStart(t*2,"0"))}function Bo(e,t){return $r(e,t).reverse()}function z(e,t,r){let n;if(typeof t=="string")try{n=he(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ut(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function qi(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function To(e){return Uint8Array.from(e)}var vo=e=>typeof e=="bigint"&&Io<=e;function Vi(e,t,r){return vo(e)&&vo(t)&&vo(r)&&t<=e&&e<r}function mr(e,t,r,n){if(!Vi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Gr(e){let t;for(t=0;e>Io;e>>=Ao,t+=1);return t}var se=e=>(Ao<<BigInt(e))-Ao;function Hi(e,t,r){if(typeof e!="number"||e<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 r!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),o=p=>Uint8Array.of(p),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...p)=>r(i,s,...p),h=(p=n(0))=>{i=u(o(0),p),s=u(),p.length!==0&&(i=u(o(1),p),s=u())},f=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,d=[];for(;p<t;){s=u();let x=s.slice();d.push(x),p+=s.length}return lt(...d)};return(p,d)=>{a(),h(p);let x;for(;!(x=d(f()));)h();return a(),x}}function ie(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Co=()=>{throw new Error("not implemented")};function Ue(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var ht=BigInt(0),rt=BigInt(1),me=BigInt(2),Gi=BigInt(3),Zi=BigInt(4),Xi=BigInt(5),af=BigInt(7),Wi=BigInt(8),cf=BigInt(9),Yi=BigInt(16);function Q(e,t){let r=e%t;return r>=ht?r:t+r}function $(e,t,r){let n=e;for(;t-- >ht;)n*=n,n%=r;return n}function ji(e,t){if(e===ht)throw new Error("invert: expected non-zero number");if(t<=ht)throw new Error("invert: expected positive modulus, got "+t);let r=Q(e,t),n=t,o=ht,s=rt,i=rt,c=ht;for(;r!==ht;){let u=n/r,h=n%r,f=o-i*u,l=s-c*u;n=r,r=h,o=i,s=c,i=f,c=l}if(n!==rt)throw new Error("invert: does not exist");return Q(o,t)}function Do(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Qi(e,t){let r=(e.ORDER+rt)/Zi,n=e.pow(t,r);return Do(e,n,t),n}function uf(e,t){let r=(e.ORDER-Xi)/Wi,n=e.mul(t,me),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,me),o),c=e.mul(s,e.sub(i,e.ONE));return Do(e,c,t),c}function ff(e){let t=wt(e),r=Ji(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+af)/Yi;return(c,a)=>{let u=c.pow(a,i),h=c.mul(u,n),f=c.mul(u,o),l=c.mul(u,s),p=c.eql(c.sqr(h),a),d=c.eql(c.sqr(f),a);u=c.cmov(u,h,p),h=c.cmov(l,f,d);let x=c.eql(c.sqr(h),a),E=c.cmov(u,h,x);return Do(c,E,a),E}}function Ji(e){if(e<Gi)throw new Error("sqrt is not defined for small field");let t=e-rt,r=0;for(;t%me===ht;)t/=me,r++;let n=me,o=wt(e);for(;$i(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Qi;let s=o.pow(n,t),i=(t+rt)/me;return function(a,u){if(a.is0(u))return u;if($i(a,u)!==1)throw new Error("Cannot find square root");let h=r,f=a.mul(a.ONE,s),l=a.pow(u,t),p=a.pow(u,i);for(;!a.eql(l,a.ONE);){if(a.is0(l))return a.ZERO;let d=1,x=a.sqr(l);for(;!a.eql(x,a.ONE);)if(d++,x=a.sqr(x),d===h)throw new Error("Cannot find square root");let E=rt<<BigInt(h-d-1),y=a.pow(f,E);h=d,f=a.sqr(y),l=a.mul(l,f),p=a.mul(p,y)}return p}}function lf(e){return e%Zi===Gi?Qi:e%Wi===Xi?uf:e%Yi===cf?ff(e):Ji(e)}var zt=(e,t)=>(Q(e,t)&rt)===rt,hf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Lo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=hf.reduce((n,o)=>(n[o]="function",n),t);return ie(e,r),e}function df(e,t,r){if(r<ht)throw new Error("invalid exponent, negatives unsupported");if(r===ht)return e.ONE;if(r===rt)return t;let n=e.ONE,o=t;for(;r>ht;)r&rt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=rt;return n}function gr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function $i(e,t){let r=(e.ORDER-rt)/me,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Zr(e,t){t!==void 0&&ur(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function wt(e,t,r=!1,n={}){if(e<=ht)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(o=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(r=l.isLE),typeof l.modFromBytes=="boolean"&&(i=l.modFromBytes),c=l.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=Zr(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let h,f=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:se(a),ZERO:ht,ONE:rt,allowedLengths:c,create:l=>Q(l,e),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return ht<=l&&l<e},is0:l=>l===ht,isValidNot0:l=>!f.is0(l)&&f.isValid(l),isOdd:l=>(l&rt)===rt,neg:l=>Q(-l,e),eql:(l,p)=>l===p,sqr:l=>Q(l*l,e),add:(l,p)=>Q(l+p,e),sub:(l,p)=>Q(l-p,e),mul:(l,p)=>Q(l*p,e),pow:(l,p)=>df(f,l,p),div:(l,p)=>Q(l*ji(p,e),e),sqrN:l=>l*l,addN:(l,p)=>l+p,subN:(l,p)=>l-p,mulN:(l,p)=>l*p,inv:l=>ji(l,e),sqrt:s||(l=>(h||(h=lf(e)),h(f,l))),toBytes:l=>r?Bo(l,u):$r(l,u),fromBytes:(l,p=!0)=>{if(c){if(!c.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+l.length);let x=new Uint8Array(u);x.set(l,r?0:x.length-l.length),l=x}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let d=r?Ft(l):Ne(l);if(i&&(d=Q(d,e)),!p&&!f.isValid(d))throw new Error("invalid field element: outside of range 0..ORDER");return d},invertBatch:l=>gr(f,l),cmov:(l,p,d)=>d?p:l});return Object.freeze(f)}function ta(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Po(e){let t=ta(e);return t+Math.ceil(t/2)}function Ro(e,t,r=!1){let n=e.length,o=ta(t),s=Po(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ft(e):Ne(e),c=Q(i,t-rt)+rt;return r?Bo(c,o):$r(c,o)}var ke=BigInt(0),ge=BigInt(1);function yr(e,t){let r=t.negate();return e?r:t}function qt(e,t){let r=gr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function oa(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Oo(e,t){oa(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=se(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ea(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=ge);let u=t*n,h=u+Math.abs(c)-1,f=c===0,l=c<0,p=t%2!==0;return{nextN:a,offset:h,isZero:f,isNeg:l,isNegF:p,offsetF:u}}function pf(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function mf(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var No=new WeakMap,sa=new WeakMap;function Uo(e){return sa.get(e)||1}function ra(e){if(e!==ke)throw new Error("invalid wNAF")}var Me=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>ke;)r&ge&&(n=n.add(o)),o=o.double(),r>>=ge;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Oo(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Oo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:h,isNeg:f,isNegF:l,offsetF:p}=ea(n,c,i);n=a,h?s=s.add(yr(l,r[p])):o=o.add(yr(f,r[u]))}return ra(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Oo(t,this.bits);for(let i=0;i<s.windows&&n!==ke;i++){let{nextN:c,offset:a,isZero:u,isNeg:h}=ea(n,i,s);if(n=c,!u){let f=r[a];o=o.add(h?f.negate():f)}}return ra(n),o}getPrecomputes(t,r,n){let o=No.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),No.set(r,o))),o}cached(t,r,n){let o=Uo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Uo(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){oa(r,this.bits),sa.set(t,r),No.delete(t)}hasCache(t){return Uo(t)!==1}};function ia(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ke||n>ke;)r&ge&&(s=s.add(o)),n&ge&&(i=i.add(o)),o=o.double(),r>>=ge,n>>=ge;return{p1:s,p2:i}}function Ke(e,t,r,n){pf(r,e),mf(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Gr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=se(a),h=new Array(Number(u)+1).fill(i),f=Math.floor((t.BITS-1)/a)*a,l=i;for(let p=f;p>=0;p-=a){h.fill(i);for(let x=0;x<s;x++){let E=n[x],y=Number(E>>BigInt(p)&u);h[y]=h[y].add(r[x])}let d=i;for(let x=h.length-1,E=i;x>0;x--)E=E.add(h[x]),d=d.add(E);if(l=l.add(d),p!==0)for(let x=0;x<a;x++)l=l.double()}return l}function na(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Lo(t),t}else return wt(e,{isLE:r})}function Xr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>ke))throw new Error(`CURVE.${a} must be positive bigint`)}let o=na(t.p,r.Fp,n),s=na(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} 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),nt=BigInt(1),ko=BigInt(2),gf=BigInt(8);function yf(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function bf(e,t={}){let r=Xr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ie(t,{},{uvRatio:"function"});let c=ko<<BigInt(o.BYTES*8)-nt,a=E=>n.create(E),u=t.uvRatio||((E,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(E,y))}}catch{return{isValid:!1,value:ae}}});if(!yf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function h(E,y,v=!1){let w=v?nt:ae;return mr("coordinate "+E,y,w,c),y}function f(E){if(!(E instanceof d))throw new Error("ExtendedPoint expected")}let l=Ue((E,y)=>{let{X:v,Y:w,Z:T}=E,P=E.is0();y==null&&(y=P?gf:n.inv(T));let M=a(v*y),k=a(w*y),O=n.mul(T,y);if(P)return{x:ae,y:nt};if(O!==nt)throw new Error("invZ was invalid");return{x:M,y:k}}),p=Ue(E=>{let{a:y,d:v}=s;if(E.is0())throw new Error("bad point: ZERO");let{X:w,Y:T,Z:P,T:M}=E,k=a(w*w),O=a(T*T),_=a(P*P),C=a(_*_),N=a(k*y),D=a(_*a(N+O)),b=a(C+a(v*a(k*O)));if(D!==b)throw new Error("bad point: equation left != right (1)");let m=a(w*T),g=a(P*M);if(m!==g)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(y,v,w,T){this.X=h("x",y),this.Y=h("y",v),this.Z=h("z",w,!0),this.T=h("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof d)throw new Error("extended point not allowed");let{x:v,y:w}=y||{};return h("x",v),h("y",w),new d(v,w,nt,a(v*w))}static fromBytes(y,v=!1){let w=n.BYTES,{a:T,d:P}=s;y=To(xt(y,w,"point")),Kt(v,"zip215");let M=To(y),k=y[w-1];M[w-1]=k&-129;let O=Ft(M),_=v?c:n.ORDER;mr("point.y",O,ae,_);let C=a(O*O),N=a(C-nt),D=a(P*C-T),{isValid:b,value:m}=u(N,D);if(!b)throw new Error("bad point: invalid y coordinate");let g=(m&nt)===nt,S=(k&128)!==0;if(!v&&m===ae&&S)throw new Error("bad point: x=0 and x_0=1");return S!==g&&(m=a(-m)),d.fromAffine({x:m,y:O})}static fromHex(y,v=!1){return d.fromBytes(z("point",y),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,v=!0){return x.createCache(this,y),v||this.multiply(ko),this}assertValidity(){p(this)}equals(y){f(y);let{X:v,Y:w,Z:T}=this,{X:P,Y:M,Z:k}=y,O=a(v*k),_=a(P*T),C=a(w*k),N=a(M*T);return O===_&&C===N}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:y}=s,{X:v,Y:w,Z:T}=this,P=a(v*v),M=a(w*w),k=a(ko*a(T*T)),O=a(y*P),_=v+w,C=a(a(_*_)-P-M),N=O+M,D=N-k,b=O-M,m=a(C*D),g=a(N*b),S=a(C*b),A=a(D*N);return new d(m,g,A,S)}add(y){f(y);let{a:v,d:w}=s,{X:T,Y:P,Z:M,T:k}=this,{X:O,Y:_,Z:C,T:N}=y,D=a(T*O),b=a(P*_),m=a(k*w*N),g=a(M*C),S=a((T+P)*(O+_)-D-b),A=g-m,L=g+m,I=a(b-v*D),B=a(S*A),R=a(L*I),U=a(S*I),Z=a(A*L);return new d(B,R,Z,U)}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:v,f:w}=x.cached(this,y,T=>qt(d,T));return qt(d,[v,w])[0]}multiplyUnsafe(y,v=d.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===ae?d.ZERO:this.is0()||y===nt?this:x.unsafe(this,y,w=>qt(d,w),v)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return x.unsafe(this,s.n).is0()}toAffine(y){return l(this,y)}clearCofactor(){return i===nt?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:v}=this.toAffine(),w=n.toBytes(v);return w[w.length-1]|=y&nt?128:0,w}toHex(){return St(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 qt(d,y)}static msm(y,v){return Ke(d,o,y,v)}_setWindowSize(y){this.precompute(y)}toRawBytes(){return this.toBytes()}}d.BASE=new d(s.Gx,s.Gy,nt,a(s.Gx*s.Gy)),d.ZERO=new d(ae,nt,nt,ae),d.Fp=n,d.Fn=o;let x=new Me(d,o.BITS);return d.BASE.precompute(8),d}var Wr=class{constructor(t){this.ep=t}static fromBytes(t){Co()}static fromHex(t){Co()}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 St(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,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function xf(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ie(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||Oe,a=r.adjustScalarBytes||(_=>_),u=r.domain||((_,C,N)=>{if(Kt(N,"phflag"),C.length||N)throw new Error("Contexts/pre-hash are not supported");return _});function h(_){return i.create(Ft(_))}function f(_){let C=w.secretKey;_=z("private key",_,C);let N=z("hashed private key",t(_),2*C),D=a(N.slice(0,C)),b=N.slice(C,2*C),m=h(D);return{head:D,prefix:b,scalar:m}}function l(_){let{head:C,prefix:N,scalar:D}=f(_),b=o.multiply(D),m=b.toBytes();return{head:C,prefix:N,scalar:D,point:b,pointBytes:m}}function p(_){return l(_).pointBytes}function d(_=Uint8Array.of(),...C){let N=lt(...C);return h(t(u(N,z("context",_),!!n)))}function x(_,C,N={}){_=z("message",_),n&&(_=n(_));let{prefix:D,scalar:b,pointBytes:m}=l(C),g=d(N.context,D,_),S=o.multiply(g).toBytes(),A=d(N.context,S,m,_),L=i.create(g+A*b);if(!i.isValid(L))throw new Error("sign failed: invalid s");let I=lt(S,i.toBytes(L));return xt(I,w.signature,"result")}let E={zip215:!0};function y(_,C,N,D=E){let{context:b,zip215:m}=D,g=w.signature;_=z("signature",_,g),C=z("message",C),N=z("publicKey",N,w.publicKey),m!==void 0&&Kt(m,"zip215"),n&&(C=n(C));let S=g/2,A=_.subarray(0,S),L=Ft(_.subarray(S,g)),I,B,R;try{I=e.fromBytes(N,m),B=e.fromBytes(A,m),R=o.multiplyUnsafe(L)}catch{return!1}if(!m&&I.isSmallOrder())return!1;let U=d(b,B.toBytes(),I.toBytes(),C);return B.add(I.multiplyUnsafe(U)).subtract(R).clearCofactor().is0()}let v=s.BYTES,w={secretKey:v,publicKey:v,signature:2*v,seed:v};function T(_=c(w.seed)){return xt(_,w.seed,"seed")}function P(_){let C=O.randomSecretKey(_);return{secretKey:C,publicKey:p(C)}}function M(_){return Ut(_)&&_.length===i.BYTES}function k(_,C){try{return!!e.fromBytes(_,C)}catch{return!1}}let O={getExtendedPublicKey:l,randomSecretKey:T,isValidSecretKey:M,isValidPublicKey:k,toMontgomery(_){let{y:C}=e.fromBytes(_),N=w.publicKey,D=N===32;if(!D&&N!==57)throw new Error("only defined for 25519 and 448");let b=D?s.div(nt+C,nt-C):s.div(C-nt,C+nt);return s.toBytes(b)},toMontgomerySecret(_){let C=w.secretKey;xt(_,C);let N=t(_.subarray(0,C));return a(N).subarray(0,C)},randomPrivateKey:T,precompute(_=8,C=e.BASE){return C.precompute(_,!1)}};return Object.freeze({keygen:P,getPublicKey:p,sign:x,verify:y,utils:O,Point:e,lengths:w})}function wf(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=wt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function Ef(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function aa(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=wf(e),s=bf(t,r),i=xf(s,n,o);return Ef(e,i)}var _f=BigInt(0),Vt=BigInt(1),ca=BigInt(2),t0=BigInt(3),Sf=BigInt(5),vf=BigInt(8),Fe=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),br={p:Fe,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:vf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Af(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Fe,c=e*e%s*e%s,a=$(c,ca,s)*c%s,u=$(a,Vt,s)*e%s,h=$(u,Sf,s)*u%s,f=$(h,t,s)*h%s,l=$(f,r,s)*f%s,p=$(l,n,s)*l%s,d=$(p,o,s)*p%s,x=$(d,o,s)*p%s,E=$(x,t,s)*h%s;return{pow_p_5_8:$(E,ca,s)*e%s,b2:c}}function If(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Mo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function zo(e,t){let r=Fe,n=Q(t*t*t,r),o=Q(n*n*t,r),s=Af(e*o).pow_p_5_8,i=Q(e*n*s,r),c=Q(t*i*i,r),a=i,u=Q(i*Mo,r),h=c===e,f=c===Q(-e,r),l=c===Q(-e*Mo,r);return h&&(i=a),(f||l)&&(i=u),zt(i,r)&&(i=Q(-i,r)),{isValid:h||f,value:i}}var ce=wt(br.p,{isLE:!0}),Bf=wt(br.n,{isLE:!0}),Tf={...br,Fp:ce,hash:Fi,adjustScalarBytes:If,uvRatio:zo},Ht=aa(Tf);var Ko=Mo,Cf=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Df=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Lf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Pf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ua=e=>zo(Vt,e),Rf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Fo=e=>Ht.Point.Fp.create(Ft(e)&Rf);function fa(e){let{d:t}=br,r=Fe,n=y=>ce.create(y),o=n(Ko*e*e),s=n((o+Vt)*Lf),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=zo(s,c),h=n(u*e);zt(h,r)||(h=n(-h)),a||(u=h),a||(i=o);let f=n(i*(o-Vt)*Pf-c),l=u*u,p=n((u+u)*c),d=n(f*Cf),x=n(Vt-l),E=n(Vt+l);return new Ht.Point(n(p*E),n(x*d),n(d*E),n(p*x))}function Of(e){mt(e,64);let t=Fo(e.subarray(0,32)),r=fa(t),n=Fo(e.subarray(32,64)),o=fa(n);return new jt(r.add(o))}var jt=class e extends Wr{constructor(t){super(t)}static fromAffine(t){return new e(Ht.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Of(z("ristrettoHash",t,64))}static fromBytes(t){mt(t,32);let{a:r,d:n}=br,o=Fe,s=T=>ce.create(T),i=Fo(t);if(!qi(ce.toBytes(i),t)||zt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(Vt+r*c),u=s(Vt-r*c),h=s(a*a),f=s(u*u),l=s(r*n*h-f),{isValid:p,value:d}=ua(s(l*f)),x=s(d*u),E=s(d*x*l),y=s((i+i)*x);zt(y,o)&&(y=s(-y));let v=s(a*E),w=s(y*v);if(!p||zt(w,o)||v===_f)throw new Error("invalid ristretto255 encoding 2");return new e(new Ht.Point(y,v,Vt,w))}static fromHex(t){return e.fromBytes(z("ristrettoHex",t,32))}static msm(t,r){return Ke(e,Ht.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Fe,i=E=>ce.create(E),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:h}=ua(i(c*u)),f=i(h*c),l=i(h*a),p=i(f*l*o),d;if(zt(o*p,s)){let E=i(r*Ko),y=i(t*Ko);t=E,r=y,d=i(f*Df)}else d=l;zt(t*p,s)&&(r=i(-r));let x=i((n-r)*d);return zt(x,s)&&(x=i(-x)),ce.toBytes(x)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ce.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};jt.BASE=new jt(Ht.Point.BASE);jt.ZERO=new jt(Ht.Point.ZERO);jt.Fp=ce;jt.Fn=Bf;var xr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Yr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var la={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Yr("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 Qr=la;var Jr=32;var qo,Nf=(async()=>{try{return await Qr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Uf(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Qr.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Qr.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function kf(e,t,r){return Ht.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ha(e,t,r){return qo==null&&(qo=await Nf),qo?Uf(e,t,r):kf(e,t,r)}function tn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var en=class{type="Ed25519";raw;constructor(t){this.raw=Vo(t,Jr)}toMultihash(){return vt.digest(Le(this))}toCID(){return et.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,r,n){n?.signal?.throwIfAborted();let o=ha(this.raw,r,t);return tn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function pa(e){return e=Vo(e,Jr),new en(e)}function Vo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Pt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Kf=Math.pow(2,7),Ff=Math.pow(2,14),zf=Math.pow(2,21),Ho=Math.pow(2,28),jo=Math.pow(2,35),$o=Math.pow(2,42),Go=Math.pow(2,49),F=128,ct=127;function gt(e){if(e<Kf)return 1;if(e<Ff)return 2;if(e<zf)return 3;if(e<Ho)return 4;if(e<jo)return 5;if(e<$o)return 6;if(e<Go)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ze(e,t,r=0){switch(gt(e)){case 8:t[r++]=e&255|F,e/=128;case 7:t[r++]=e&255|F,e/=128;case 6:t[r++]=e&255|F,e/=128;case 5:t[r++]=e&255|F,e/=128;case 4:t[r++]=e&255|F,e>>>=7;case 3:t[r++]=e&255|F,e>>>=7;case 2:t[r++]=e&255|F,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function qf(e,t,r=0){switch(gt(e)){case 8:t.set(r++,e&255|F),e/=128;case 7:t.set(r++,e&255|F),e/=128;case 6:t.set(r++,e&255|F),e/=128;case 5:t.set(r++,e&255|F),e/=128;case 4:t.set(r++,e&255|F),e>>>=7;case 3:t.set(r++,e&255|F),e>>>=7;case 2:t.set(r++,e&255|F),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Zo(e,t){let r=e[t],n=0;if(n+=r&ct,r<F||(r=e[t+1],n+=(r&ct)<<7,r<F)||(r=e[t+2],n+=(r&ct)<<14,r<F)||(r=e[t+3],n+=(r&ct)<<21,r<F)||(r=e[t+4],n+=(r&ct)*Ho,r<F)||(r=e[t+5],n+=(r&ct)*jo,r<F)||(r=e[t+6],n+=(r&ct)*$o,r<F)||(r=e[t+7],n+=(r&ct)*Go,r<F))return n;throw new RangeError("Could not decode varint")}function Vf(e,t){let r=e.get(t),n=0;if(n+=r&ct,r<F||(r=e.get(t+1),n+=(r&ct)<<7,r<F)||(r=e.get(t+2),n+=(r&ct)<<14,r<F)||(r=e.get(t+3),n+=(r&ct)<<21,r<F)||(r=e.get(t+4),n+=(r&ct)*Ho,r<F)||(r=e.get(t+5),n+=(r&ct)*jo,r<F)||(r=e.get(t+6),n+=(r&ct)*$o,r<F)||(r=e.get(t+7),n+=(r&ct)*Go,r<F))return n;throw new RangeError("Could not decode varint")}function ma(e,t,r=0){return t==null&&(t=pt(gt(e))),t instanceof Uint8Array?ze(e,t,r):qf(e,t,r)}function wr(e,t=0){return e instanceof Uint8Array?Zo(e,t):Vf(e,t)}var Xo=new Float32Array([-0]),ue=new Uint8Array(Xo.buffer);function ya(e,t,r){Xo[0]=e,t[r]=ue[0],t[r+1]=ue[1],t[r+2]=ue[2],t[r+3]=ue[3]}function ba(e,t){return ue[0]=e[t],ue[1]=e[t+1],ue[2]=e[t+2],ue[3]=e[t+3],Xo[0]}var Wo=new Float64Array([-0]),ut=new Uint8Array(Wo.buffer);function xa(e,t,r){Wo[0]=e,t[r]=ut[0],t[r+1]=ut[1],t[r+2]=ut[2],t[r+3]=ut[3],t[r+4]=ut[4],t[r+5]=ut[5],t[r+6]=ut[6],t[r+7]=ut[7]}function wa(e,t){return ut[0]=e[t],ut[1]=e[t+1],ut[2]=e[t+2],ut[3]=e[t+3],ut[4]=e[t+4],ut[5]=e[t+5],ut[6]=e[t+6],ut[7]=e[t+7],Wo[0]}var Hf=BigInt(Number.MAX_SAFE_INTEGER),jf=BigInt(Number.MIN_SAFE_INTEGER),Et=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ye;if(t<Hf&&t>jf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Ea&&(o=0n,++n>Ea&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ye;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ye}},ye=new Et(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var Ea=4294967296n;function _a(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Sa(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Yo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Bt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function rn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Qo=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,Bt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Bt(this,4);return rn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return rn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=ba(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=wa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Sa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=rn(this.buf,this.pos+=4),r=rn(this.buf,this.pos+=4);return new Et(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Zo(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 Jo(e){return new Qo(e instanceof Uint8Array?e:e.subarray())}function $t(e,t,r){let n=Jo(e);return t.decode(n,void 0,r)}function ts(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return pt(i);o+i>t&&(n=pt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var be=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function es(){}var ns=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},$f=ts();function Gf(e){return globalThis.Buffer!=null?pt(e):$f(e)}var _r=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(es,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new be(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new os((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(nn,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Et.fromBigInt(t);return this._push(nn,r.length(),r)}uint64Number(t){return this._push(ze,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 r=Et.fromBigInt(t).zzEncode();return this._push(nn,r.length(),r)}sint64Number(t){let r=Et.fromNumber(t).zzEncode();return this._push(nn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(rs,1,t?1:0)}fixed32(t){return this._push(Er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Et.fromBigInt(t);return this._push(Er,4,r.lo)._push(Er,4,r.hi)}fixed64Number(t){let r=Et.fromNumber(t);return this._push(Er,4,r.lo)._push(Er,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ya,4,t)}double(t){return this._push(xa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(rs,1,0):this.uint32(r)._push(Xf,r,t)}string(t){let r=_a(t);return r!==0?this.uint32(r)._push(Yo,r,t):this._push(rs,1,0)}fork(){return this.states=new ns(this),this.head=this.tail=new be(es,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 be(es,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Gf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function rs(e,t,r){t[r]=e&255}function Zf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var os=class extends be{next;constructor(t,r){super(Zf,t,r),this.next=void 0}};function nn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Er(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Xf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(_r.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Wf,t,e),this},_r.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Yf,t,e),this});function Wf(e,t,r){t.set(e,r)}function Yf(e,t,r){e.length<40?Yo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function ss(){return new _r}function Gt(e,t){let r=ss();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var qe;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(qe||(qe={}));function on(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Ve(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return on("enum",qe.VARINT,r,n)}function Zt(e,t){return on("message",qe.LENGTH_DELIMITED,e,t)}var sn=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var _t;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(_t||(_t={}));var is;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(is||(is={}));(function(e){e.codec=()=>Ve(is)})(_t||(_t={}));var Sr;(function(e){let t;e.codec=()=>(t==null&&(t=Zt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),_t.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=_t.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Gt(r,e.codec()),e.decode=(r,n)=>$t(r,e.codec(),n)})(Sr||(Sr={}));var as;(function(e){let t;e.codec=()=>(t==null&&(t=Zt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),_t.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=_t.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Gt(r,e.codec()),e.decode=(r,n)=>$t(r,e.codec(),n)})(as||(as={}));var an=class extends Pe{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Vr(t);let n=fr(r);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),kt(s)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(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:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},cs=(e,t,r)=>new an(e,t).update(r).digest();cs.create=(e,t)=>new an(e,t);var Aa=(e,t)=>(e+(e>=0?t:-t)/Ia)/t;function Jf(e,t,r){let[[n,o],[s,i]]=t,c=Aa(i*e,r),a=Aa(-o*e,r),u=e-c*n-a*s,h=-c*o-a*i,f=u<Wt,l=h<Wt;f&&(u=-u),l&&(h=-h);let p=se(Math.ceil(Gr(r)/2))+je;if(u<Wt||u>=p||h<Wt||h>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:u,k2neg:l,k2:h}}function fs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function us(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Kt(r.lowS,"lowS"),Kt(r.prehash,"prehash"),r.format!==void 0&&fs(r.format),r}var ls=class extends Error{constructor(t=""){super(t)}},Xt={Err:ls,_tlv:{encode:(e,t)=>{let{Err:r}=Xt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=pr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?pr(o.length/2|128):"";return pr(e)+s+o+t},decode(e,t){let{Err:r}=Xt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let h of u)i=i<<8|h;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Xt;if(e<Wt)throw new t("integer: negative integers are not allowed");let r=pr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Xt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ne(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Xt,o=z("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:h}=n.decode(2,a);if(h.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Xt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Wt=BigInt(0),je=BigInt(1),Ia=BigInt(2),cn=BigInt(3),tl=BigInt(4);function He(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=z("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function el(e,t={}){let r=Xr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;ie(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Ta(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(D,b,m){let{x:g,y:S}=b.toAffine(),A=n.toBytes(g);if(Kt(m,"isCompressed"),m){h();let L=!n.isOdd(S);return lt(Ba(L),A)}else return lt(Uint8Array.of(4),A,n.toBytes(S))}function l(D){xt(D,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=u,g=D.length,S=D[0],A=D.subarray(1);if(g===b&&(S===2||S===3)){let L=n.fromBytes(A);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let I=x(L),B;try{B=n.sqrt(I)}catch(Z){let q=Z instanceof Error?": "+Z.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}h();let R=n.isOdd(B);return(S&1)===1!==R&&(B=n.neg(B)),{x:L,y:B}}else if(g===m&&S===4){let L=n.BYTES,I=n.fromBytes(A.subarray(0,L)),B=n.fromBytes(A.subarray(L,L*2));if(!E(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 p=t.toBytes||f,d=t.fromBytes||l;function x(D){let b=n.sqr(D),m=n.mul(b,D);return n.add(n.add(m,n.mul(D,s.a)),s.b)}function E(D,b){let m=n.sqr(b),g=x(D);return n.eql(m,g)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,cn),tl),v=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,v)))throw new Error("bad curve params: a or b");function w(D,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${D}`);return b}function T(D){if(!(D instanceof _))throw new Error("ProjectivePoint expected")}function P(D){if(!a||!a.basises)throw new Error("no endo");return Jf(D,a.basises,o.ORDER)}let M=Ue((D,b)=>{let{X:m,Y:g,Z:S}=D;if(n.eql(S,n.ONE))return{x:m,y:g};let A=D.is0();b==null&&(b=A?n.ONE:n.inv(S));let L=n.mul(m,b),I=n.mul(g,b),B=n.mul(S,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}}),k=Ue(D=>{if(D.is0()){if(t.allowInfinityPoint&&!n.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=D.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!E(b,m))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function O(D,b,m,g,S){return m=new _(n.mul(m.X,D),m.Y,m.Z),b=yr(g,b),m=yr(S,m),b.add(m)}class _{constructor(b,m,g){this.X=w("x",b),this.Y=w("y",m,!0),this.Z=w("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 _)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(g)?_.ZERO:new _(m,g,n.ONE)}static fromBytes(b){let m=_.fromAffine(d(xt(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return _.fromBytes(z("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return N.createCache(this,b),m||this.multiply(cn),this}assertValidity(){k(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){T(b);let{X:m,Y:g,Z:S}=this,{X:A,Y:L,Z:I}=b,B=n.eql(n.mul(m,I),n.mul(A,S)),R=n.eql(n.mul(g,I),n.mul(L,S));return B&&R}negate(){return new _(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,g=n.mul(m,cn),{X:S,Y:A,Z:L}=this,I=n.ZERO,B=n.ZERO,R=n.ZERO,U=n.mul(S,S),Z=n.mul(A,A),q=n.mul(L,L),K=n.mul(S,A);return K=n.add(K,K),R=n.mul(S,L),R=n.add(R,R),I=n.mul(b,R),B=n.mul(g,q),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),R=n.mul(g,R),q=n.mul(b,q),K=n.sub(U,q),K=n.mul(b,K),K=n.add(K,R),R=n.add(U,U),U=n.add(R,U),U=n.add(U,q),U=n.mul(U,K),B=n.add(B,U),q=n.mul(A,L),q=n.add(q,q),U=n.mul(q,K),I=n.sub(I,U),R=n.mul(q,Z),R=n.add(R,R),R=n.add(R,R),new _(I,B,R)}add(b){T(b);let{X:m,Y:g,Z:S}=this,{X:A,Y:L,Z:I}=b,B=n.ZERO,R=n.ZERO,U=n.ZERO,Z=s.a,q=n.mul(s.b,cn),K=n.mul(m,A),X=n.mul(g,L),J=n.mul(S,I),dt=n.add(m,g),W=n.add(A,L);dt=n.mul(dt,W),W=n.add(K,X),dt=n.sub(dt,W),W=n.add(m,S);let at=n.add(A,I);return W=n.mul(W,at),at=n.add(K,J),W=n.sub(W,at),at=n.add(g,S),B=n.add(L,I),at=n.mul(at,B),B=n.add(X,J),at=n.sub(at,B),U=n.mul(Z,W),B=n.mul(q,J),U=n.add(B,U),B=n.sub(X,U),U=n.add(X,U),R=n.mul(B,U),X=n.add(K,K),X=n.add(X,K),J=n.mul(Z,J),W=n.mul(q,W),X=n.add(X,J),J=n.sub(K,J),J=n.mul(Z,J),W=n.add(W,J),K=n.mul(X,W),R=n.add(R,K),K=n.mul(at,W),B=n.mul(dt,B),B=n.sub(B,K),K=n.mul(dt,X),U=n.mul(at,U),U=n.add(U,K),new _(B,R,U)}subtract(b){return this.add(b.negate())}is0(){return this.equals(_.ZERO)}multiply(b){let{endo:m}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let g,S,A=L=>N.cached(this,L,I=>qt(_,I));if(m){let{k1neg:L,k1:I,k2neg:B,k2:R}=P(b),{p:U,f:Z}=A(I),{p:q,f:K}=A(R);S=Z.add(K),g=O(m.beta,U,q,L,B)}else{let{p:L,f:I}=A(b);g=L,S=I}return qt(_,[g,S])[0]}multiplyUnsafe(b){let{endo:m}=t,g=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Wt||g.is0())return _.ZERO;if(b===je)return g;if(N.hasCache(this))return this.multiply(b);if(m){let{k1neg:S,k1:A,k2neg:L,k2:I}=P(b),{p1:B,p2:R}=ia(_,g,A,I);return O(m.beta,B,R,S,L)}else return N.unsafe(g,b)}multiplyAndAddUnsafe(b,m,g){let S=this.multiplyUnsafe(m).add(b.multiplyUnsafe(g));return S.is0()?void 0:S}toAffine(b){return M(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===je?!0:b?b(_,this):N.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===je?this:b?b(_,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return Kt(b,"isCompressed"),this.assertValidity(),p(_,this,b)}toHex(b=!0){return St(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 qt(_,b)}static msm(b,m){return Ke(_,o,b,m)}static fromPrivateKey(b){return _.BASE.multiply(He(o,b))}}_.BASE=new _(s.Gx,s.Gy,n.ONE),_.ZERO=new _(n.ZERO,n.ONE,n.ZERO),_.Fp=n,_.Fn=o;let C=o.BITS,N=new Me(_,t.endo?Math.ceil(C/2):C);return _.BASE.precompute(8),_}function Ba(e){return Uint8Array.of(e?2:3)}function Ta(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function rl(e,t={}){let{Fn:r}=e,n=t.randomBytes||Oe,o=Object.assign(Ta(e.Fp,r),{seed:Po(r.ORDER)});function s(p){try{return!!He(r,p)}catch{return!1}}function i(p,d){let{publicKey:x,publicKeyUncompressed:E}=o;try{let y=p.length;return d===!0&&y!==x||d===!1&&y!==E?!1:!!e.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return Ro(xt(p,o.seed,"seed"),r.ORDER)}function a(p,d=!0){return e.BASE.multiply(He(r,p)).toBytes(d)}function u(p){let d=c(p);return{secretKey:d,publicKey:a(d)}}function h(p){if(typeof p=="bigint")return!1;if(p instanceof e)return!0;let{secretKey:d,publicKey:x,publicKeyUncompressed:E}=o;if(r.allowedLengths||d===x)return;let y=z("key",p).length;return y===x||y===E}function f(p,d,x=!0){if(h(p)===!0)throw new Error("first arg must be private key");if(h(d)===!1)throw new Error("second arg must be public key");let E=He(r,p);return e.fromHex(d).multiply(E).toBytes(x)}return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:p=>He(r,p),precompute(p=8,d=e.BASE){return d.precompute(p,!1)}},lengths:o})}function nl(e,t,r={}){Vr(t),ie(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||Oe,o=r.hmac||((m,...g)=>cs(t,m,lt(...g))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:h,getSharedSecret:f,utils:l,lengths:p}=rl(e,r),d={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},x="compact";function E(m){let g=c>>je;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 v(m,g){fs(g);let S=p.signature,A=g==="compact"?S:g==="recovered"?S+1:void 0;return xt(m,A,`${g} signature`)}class w{constructor(g,S,A){this.r=y("r",g),this.s=y("s",S),A!=null&&(this.recovery=A),Object.freeze(this)}static fromBytes(g,S=x){v(g,S);let A;if(S==="der"){let{r:R,s:U}=Xt.toSig(xt(g));return new w(R,U)}S==="recovered"&&(A=g[0],S="compact",g=g.subarray(1));let L=i.BYTES,I=g.subarray(0,L),B=g.subarray(L,L*2);return new w(i.fromBytes(I),i.fromBytes(B),A)}static fromHex(g,S){return this.fromBytes(he(g),S)}addRecoveryBit(g){return new w(this.r,this.s,g)}recoverPublicKey(g){let S=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(c*Ia<S&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=I===2||I===3?A+c:A;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let U=s.toBytes(R),Z=e.fromBytes(lt(Ba((I&1)===0),U)),q=i.inv(R),K=P(z("msgHash",g)),X=i.create(-K*q),J=i.create(L*q),dt=e.BASE.multiplyUnsafe(X).add(Z.multiplyUnsafe(J));if(dt.is0())throw new Error("point at infinify");return dt.assertValidity(),dt}hasHighS(){return E(this.s)}toBytes(g=x){if(fs(g),g==="der")return he(Xt.hexFromSig(this));let S=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),S,A)}return lt(S,A)}toHex(g){return St(this.toBytes(g))}assertValidity(){}static fromCompact(g){return w.fromBytes(z("sig",g),"compact")}static fromDER(g){return w.fromBytes(z("sig",g),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return St(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return St(this.toBytes("compact"))}}let T=r.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");let S=Ne(g),A=g.length*8-a;return A>0?S>>BigInt(A):S},P=r.bits2int_modN||function(g){return i.create(T(g))},M=se(a);function k(m){return mr("num < 2^"+a,m,Wt,M),i.toBytes(m)}function O(m,g){return xt(m,void 0,"message"),g?xt(t(m),void 0,"prehashed message"):m}function _(m,g,S){if(["recovered","canonical"].some(X=>X in S))throw new Error("sign() legacy options not supported");let{lowS:A,prehash:L,extraEntropy:I}=us(S,d);m=O(m,L);let B=P(m),R=He(i,g),U=[k(R),k(B)];if(I!=null&&I!==!1){let X=I===!0?n(p.secretKey):I;U.push(z("extraEntropy",X))}let Z=lt(...U),q=B;function K(X){let J=T(X);if(!i.isValidNot0(J))return;let dt=i.inv(J),W=e.BASE.multiply(J).toAffine(),at=i.create(W.x);if(at===Wt)return;let Or=i.create(dt*i.create(q+at*R));if(Or===Wt)return;let Hs=(W.x===at?0:2)|Number(W.y&je),js=Or;return A&&E(Or)&&(js=i.neg(Or),Hs^=1),new w(at,js,Hs)}return{seed:Z,k2sig:K}}function C(m,g,S={}){m=z("message",m);let{seed:A,k2sig:L}=_(m,g,S);return Hi(t.outputLen,i.BYTES,o)(A,L)}function N(m){let g,S=typeof m=="string"||Ut(m),A=!S&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!S&&!A)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(A)g=new w(m.r,m.s);else if(S){try{g=w.fromBytes(z("sig",m),"der")}catch(L){if(!(L instanceof Xt.Err))throw L}if(!g)try{g=w.fromBytes(z("sig",m),"compact")}catch{return!1}}return g||!1}function D(m,g,S,A={}){let{lowS:L,prehash:I,format:B}=us(A,d);if(S=z("publicKey",S),g=O(z("message",g),I),"strict"in A)throw new Error("options.strict was renamed to lowS");let R=B===void 0?N(m):w.fromBytes(z("sig",m),B);if(R===!1)return!1;try{let U=e.fromBytes(S);if(L&&R.hasHighS())return!1;let{r:Z,s:q}=R,K=P(g),X=i.inv(q),J=i.create(K*X),dt=i.create(Z*X),W=e.BASE.multiplyUnsafe(J).add(U.multiplyUnsafe(dt));return W.is0()?!1:i.create(W.x)===Z}catch{return!1}}function b(m,g,S={}){let{prehash:A}=us(S,d);return g=O(g,A),w.fromBytes(m,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:h,getSharedSecret:f,utils:l,lengths:p,Point:e,sign:C,verify:D,recoverPublicKey:b,Signature:w,hash:t})}function ol(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=wt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function sl(e){let{CURVE:t,curveOpts:r}=ol(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function il(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Zr(r.Fn.ORDER,r.Fn.BITS))})}function Ca(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=sl(e),s=el(t,r),i=nl(s,n,o);return il(e,i)}function Da(e,t){let r=n=>Ca({...e,hash:n});return{...r(t),create:r}}var ds={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},al={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var La=BigInt(2);function cl(e){let t=ds.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,h=u*u*e%t,f=$(h,r,t)*h%t,l=$(f,r,t)*h%t,p=$(l,La,t)*u%t,d=$(p,o,t)*p%t,x=$(d,s,t)*d%t,E=$(x,c,t)*x%t,y=$(E,a,t)*E%t,v=$(y,c,t)*x%t,w=$(v,r,t)*h%t,T=$(w,i,t)*d%t,P=$(T,n,t)*u%t,M=$(P,La,t);if(!hs.eql(hs.sqr(M),e))throw new Error("Cannot find square root");return M}var hs=wt(ds.p,{sqrt:cl}),$e=Da({...ds,Fp:hs,lowS:!0,endo:al},Ki);function Pa(e,t,r,n){let o=sr.digest(r instanceof Uint8Array?r:r.subarray());if(tn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),$e.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new xr(String(s))});try{return n?.signal?.throwIfAborted(),$e.verify(t,o.digest,e)}catch(s){throw new xr(String(s))}}var un=class{type="secp256k1";raw;_key;constructor(t){this._key=Oa(t),this.raw=Ra(this._key)}toMultihash(){return vt.digest(Le(this))}toCID(){return et.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,r,n){return Pa(this._key,r,t,n)}};function Na(e){return new un(e)}function Ra(e){return $e.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Oa(e){try{return $e.ProjectivePoint.fromHex(e),e}catch(t){throw new Ur(String(t))}}function Ua(e){let{Type:t,Data:r}=Sr.decode(e.digest),n=r??new Uint8Array;switch(t){case _t.Ed25519:return pa(n);case _t.secp256k1:return Na(n);case _t.ECDSA:return _i(n);default:throw new tr}}function Le(e){return Sr.encode({Type:_t[e.type],Data:e.raw})}var ka=Symbol.for("nodejs.util.inspect.custom"),ul=114,vr=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()})`}[qn]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(ul,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")}[ka](){return`PeerId(${this.toString()})`}},fn=class extends vr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ln=class extends vr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},hn=class extends vr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},fl=2336,dn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=vt.digest(V(this.url))}[ka](){return`PeerId(${this.url})`}[qn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(fl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function pn(e){if(hl(e))return new fn({multihash:e});if(ll(e))try{let t=Ua(e);if(t.type==="Ed25519")return new ln({multihash:e,publicKey:t});if(t.type==="secp256k1")return new hn({multihash:e,publicKey:t})}catch{let r=j(e.digest);return new dn(new URL(r))}throw new kr("Supplied PeerID Multihash is invalid")}function ll(e){return e.code===vt.code}function hl(e){return e.code===sr.code}function ps(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function mn(e){let t=fe(G.decode(`z${e}`));return pn(t)}var gn=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return ps(this.set.entries(),t=>{let r=mn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=mn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return ps(this.set.values(),t=>mn(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function ms(){return new gn}var gs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ma={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ka=new globalThis.TextEncoder;function dl(e,t){let r=gs[t],n=Ma[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function pl(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=gs[t],o=Ma[t],s=e;for(;s.length>0;){let i=Ka.encodeInto(s,r);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(r[c]),o=BigInt.asUintN(t,o*n)}return o}function ys(e,{size:t=32,utf8Buffer:r}={}){if(!gs[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof e=="string"){if(r)return pl(e,t,r);e=Ka.encode(e)}return dl(e,t)}var Ar={hash:e=>Number(ys(e,{size:32})),hashV:(e,t)=>ml(Ar.hash(e,t))};function ml(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),V(t,"base16")}var bs=64,Tt=class{fp;h;seed;constructor(t,r,n,o=2){if(o>bs)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=At(o);for(let c=0;c<i.length;c++)i[c]=s[c];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ft(this.fp,t.fp):!1}};function xe(e,t){return Math.floor(Math.random()*(t-e))+e}var we=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=t,!0;return!0}swap(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let r=xe(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=t,n}remove(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var gl=500,Ir=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??Ar,this.seed=t.seed??xe(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=V(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new we(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new we(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[xe(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new we(this.bucketSize));for(let c=0;c<gl;c++){let a=this.buckets[i].swap(r);if(a!=null&&(i=(i^a.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new we(this.bucketSize)),this.buckets[i].add(a)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=V(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(t){typeof t=="string"&&(t=V(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},yl={1:.5,2:.84,4:.95,8:.98};function bl(e=.001){return e>.002?2:e>1e-5?4:8}function Fa(e,t=.001){let r=bl(t),n=yl[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),bs);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var yn=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??Ar,this.seed=t.seed??xe(0,Math.pow(2,10)),this.filterSeries=[new Ir({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 r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new Ir({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(t)}has(t){typeof t=="string"&&(t=V(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=V(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,r)=>t+r.count,0)}};function xs(e,t=.001,r){return new yn({...Fa(e,t),...r??{}})}var bn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let l=Number.parseInt(f,t);if(!Number.isNaN(l))return l});if(h===void 0)break;if(s*=t,s+=h,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var za=45,xl=15,Ge=new bn;function xn(e){if(!(e.length>xl))return Ge.new(e).parseWith(()=>Ge.readIPv4Addr())}function wn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>za))return Ge.new(e).parseWith(()=>Ge.readIPv6Addr())}function Ze(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>za)return;let r=Ge.new(e).parseWith(()=>Ge.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function qa(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Va(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function ws(e){switch(e.length){case Ee:return e.join(".");case _e:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Ha(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function ja(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var Ee=4,_e=16,sy=parseInt("0xFFFF",16),wl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Br(e,t){t.length===_e&&e.length===Ee&&qa(t,0,11)&&(t=t.slice(12)),t.length===Ee&&e.length===_e&&Va(e,wl,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function $a(e,t){if(typeof t=="string"&&(t=Ze(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function Es(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=Ee,o=xn(t);if(o==null&&(n=_e,o=wn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+e);let i=_s(s,8*n);return{network:Br(o,i),mask:i}}function _s(e,t){if(t!==8*Ee&&t!==8*_e)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var Xe=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=Es(t));else{let n=Ze(t);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Ze(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=_s(o,8*n.length);this.network=Br(n,this.mask)}}contains(t){return $a({network:this.network,mask:this.mask},t)}toString(){let t=Ha(this.mask),r=t!==-1?String(t):ja(this.mask);return ws(this.network)+"/"+r}};function Ga(e,t){return new Xe(e).contains(t)}var it=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Yt=class extends Error{static name="ValidationError";name="ValidationError"},Tr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},En=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function We(e){return!!xn(e)}function _n(e){return!!wn(e)}function vs(e){return t=>j(t,e)}function As(e){return t=>V(t,e)}function Ye(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Se(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Za(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=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=Se(n);return Ot([r,o],r.length+o.length)}function Xa(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=te.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Se(n);return Ot([r,o],r.length+o.length)}function Is(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=j(t,"base32"),o=Ye(r);return`${n}:${o}`}var Bs=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new it("Invalid byte value in IP address");t[n]=o}),t},Wa=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=We(r[n]),i;s&&(i=Bs(r[n]),r[n]=j(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,j(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new it("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ya=function(e){if(e.byteLength!==4)throw new it("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Qa=function(e){if(e.byteLength!==16)throw new it("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new it(`Invalid IPv6 address "${r}"`)}};function Ja(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new it(`Invalid IPv6 address "${e}"`)}}var Ss=Object.values(ir).map(e=>e.decoder),El=(function(){let e=Ss[0].or(Ss[1]);return Ss.slice(2).forEach(t=>e=e.or(t)),e})();function tc(e){return El.decode(e)}function ec(e){return t=>e.encoder.encode(t)}function _l(e){if(parseInt(e).toString()!==e)throw new Yt("Value must be an integer")}function Sl(e){if(e<0)throw new Yt("Value must be a positive integer, or zero")}function vl(e){return t=>{if(t>e)throw new Yt(`Value must be smaller than or equal to ${e}`)}}function Al(...e){return t=>{for(let r of e)r(t)}}var Cr=Al(_l,Sl,vl(65535));var ot=-1,Ts=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new En(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},yt=new Ts,eh=[{code:4,name:"ip4",size:32,valueToBytes:Bs,bytesToValue:Ya,validate:e=>{if(!We(e))throw new Yt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Se,bytesToValue:Ye,validate:Cr},{code:273,name:"udp",size:16,valueToBytes:Se,bytesToValue:Ye,validate:Cr},{code:33,name:"dccp",size:16,valueToBytes:Se,bytesToValue:Ye,validate:Cr},{code:41,name:"ip6",size:128,valueToBytes:Wa,bytesToValue:Qa,stringToValue:Ja,validate:e=>{if(!_n(e))throw new Yt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ot},{code:43,name:"ipcidr",size:8,bytesToValue:vs("base10"),valueToBytes:As("base10")},{code:53,name:"dns",size:ot,resolvable:!0},{code:54,name:"dns4",size:ot,resolvable:!0},{code:55,name:"dns6",size:ot,resolvable:!0},{code:56,name:"dnsaddr",size:ot,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:Se,bytesToValue:Ye,validate:Cr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ot,path:!0,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ot,bytesToValue:vs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?As("base58btc")(e):et.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Is,valueToBytes:Za},{code:445,name:"onion3",size:296,bytesToValue:Is,valueToBytes:Xa},{code:446,name:"garlic64",size:ot},{code:447,name:"garlic32",size:ot},{code:448,name:"tls"},{code:449,name:"sni",size:ot},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ot,bytesToValue:ec(no),valueToBytes:tc},{code:480,name:"http"},{code:481,name:"http-path",size:ot,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ot}];eh.forEach(e=>{yt.addProtocol(e)});function rc(e){let t=[],r=0;for(;r<e.length;){let n=wr(e,r),o=yt.getProtocol(n),s=gt(n),i=rh(o,e,r+s),c=0;i>0&&o.size===ot&&(c=gt(i));let a=s+c+i,u={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(i>0){let h=r+s+c,f=e.subarray(h,h+i);u.value=o.bytesToValue?.(f)??j(f)}t.push(u),r+=a}return t}function nc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=yt.getProtocol(n.code),s=gt(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),c=i.byteLength,o.size===ot&&(a=gt(c)));let u=new Uint8Array(s+a+c),h=0;ze(n.code,u,h),h+=s,i!=null&&(o.size===ot&&(ze(c,u,h),h+=a),u.set(i,h)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Ot(r,t)}function oc(e){if(e.charAt(0)!=="/")throw new it('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let c=s===e.length-1;if(i==="/"||c){let a=yt.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new it(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new it(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new it("Incomplete multiaddr");return t}function sc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=yt.getProtocol(t.code);if(r==null)throw new it(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function rh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:wr(t,r)}var nh=Symbol.for("nodejs.util.inspect.custom"),Ns=Symbol.for("@multiformats/multiaddr"),oh=[53,54,55,56],Os=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function sh(e){if(e==null&&(e="/"),ac(e))return e.getComponents();if(e instanceof Uint8Array)return rc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),oc(e);if(Array.isArray(e))return e;throw new it("Must be a string, Uint8Array, Component[], or another Multiaddr")}var In=class e{[Ns]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=sh(t),r.validate!==!1&&ih(this)}get bytes(){return this.#r==null&&(this.#r=nc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=sc(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,r,n,o,s="";for(let{code:c,name:a,value:u}of this.#t)c===42&&(s=`%${u??""}`),oh.includes(c)&&(r="tcp",o=443,n=`${u??""}${s}`,t=c===55?6:4),(c===6||c===273)&&(r=a==="tcp"?"tcp":"udp",o=parseInt(u??"")),(c===4||c===41)&&(r="tcp",n=`${u??""}${s}`,t=c===41?6:4);if(t==null||r==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:r,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:r})=>{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:r})=>{if(r==null)return[t];let n=yt.getProtocol(t),o=[t];return r!=null&&o.push(n.valueToBytes?.(r)??V(r)),o})}stringTuples(){return this.#t.map(({code:t,value:r})=>r==null?[t]:[t,r])}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Tr(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let r=t.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?j(G.decode(`z${n}`),"base58btc"):j(et.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 ft(this.bytes,t.bytes)}async resolve(t){let r=this.protos().find(s=>s.resolvable);if(r==null)return[this];let n=ic.get(r.name);if(n==null)throw new Os(`no available resolver for ${r.name}`);return(await n(this,t)).map(s=>Lr(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)}[nh](){return`Multiaddr(${this.toString()})`}};function ih(e){e.getComponents().forEach(t=>{let r=yt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}var ic=new Map;function ac(e){return!!e?.[Ns]}function Lr(e){return new In(e)}function cc(e){let t=yt.getProtocol(e);return{code:t.code,size:t.size??0,name:t.name,resolvable:!!t.resolvable,path:!!t.path}}function uc(e){try{for(let{code:t,value:r}of e.getComponents())if(r!=null&&t===41)return Ga("2000::/3",r)}catch{}return!1}var lc=Dc(fc(),1),ah=["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"],ch=ah.map(e=>new lc.Netmask(e));function Us(e){for(let t of ch)if(t.contains(e))return!0;return!1}function uh(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function fh(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return Us(o)}function lh(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function hh(e){let t=e.split(":"),r=t[t.length-1];return Us(r)}function dh(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function hc(e){if(We(e))return Us(e);if(uh(e))return fh(e);if(lh(e))return hh(e);if(_n(e))return dh(e)}function dc(e){try{for(let{code:t}of e.getComponents())if(t!==42)return t===4||t===41}catch{}return!1}function ks(e){try{if(!dc(e))return!1;let[[,t]]=e.stringTuples();return t==null?!1:hc(t)??!1}catch{}return!0}function Ct(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Bn=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}},Je=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Bn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new Bn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ms=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function pc(e={}){return ph(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function ph(e,t){t=t??{};let r=t.onEnd,n=new Je,o,s,i,c=Ct(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((E,y)=>{s=v=>{s=null,n.push(v);try{E(e(n))}catch(w){y(w)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Ct()})}},u=E=>s!=null?s(E):(n.push(E),o),h=E=>(n=new Je,s!=null?s({error:E}):(n.push({error:E}),o)),f=E=>{if(i)return o;if(t?.objectMode!==!0&&E?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:E})},l=E=>i?o:(i=!0,E!=null?h(E):u({done:!0})),p=()=>(n=new Je,l(),{done:!0}),d=E=>(l(E),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:p,throw:d,push:f,end:l,get readableLength(){return n.size},onEmpty:async E=>{let y=E?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let v,w;y!=null&&(v=new Promise((T,P)=>{w=()=>{P(new Ms)},y.addEventListener("abort",w)}));try{await Promise.race([c.promise,v])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},r==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(E){return x.throw(E),r!=null&&(r(E),r=void 0),{done:!0}},return(){return x.return(),r!=null&&(r(),r=void 0),{done:!0}},push:f,end(E){return x.end(E),r!=null&&(r(E),r=void 0),o},get readableLength(){return x.readableLength},onEmpty:E=>x.onEmpty(E)},o}var Tn=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function Cn(e,t,r,n){let o=new Tn(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,c)=>{function a(){Fs(r,"abort",f),Fs(e,t,u),Fs(e,s,h)}let u=l=>{try{if(n?.filter?.(l)===!1)return}catch(p){a(),c(p);return}a(),i(l)},h=l=>{if(a(),l instanceof Error){c(l);return}c(l.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},f=()=>{a(),c(o)};Ks(r,"abort",f),Ks(e,t,u),Ks(e,s,h)})}function Ks(e,t,r){e!=null&&(mc(e)?e.addEventListener(t,r):e.addListener(t,r))}function Fs(e,t,r){e!=null&&(mc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function mc(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}function Rr(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Dn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Ln=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function ve(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new Ln(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new Ln(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Pn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Ct(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Lt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function mh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Rn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=mh(),this.status="queued",this.fn=t,this.options=r,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((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Lt),this.cleanup())}async join(t={}){let r=new Pn(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await ve(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var On=class extends Mr{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=Rr(this.emitEmpty.bind(this),1),this.emitIdle=Rr(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 r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Dn;let n=new Rn(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).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 Lt)}),this.clear()}async onEmpty(t){this.size!==0&&await Cn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await Cn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Cn(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 r=pc({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),r.end(a)},o=a=>{a.detail!=null&&r.push(a.detail)},s=a=>{n(a.detail.error)},i=()=>{n()},c=()=>{n(new Lt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",c);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",c),n()}}};var Nn=class extends On{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function Un(e){let t=new globalThis.AbortController;function r(){t.abort();for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let s of e){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}function gc(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal};if(r?.timeout!=null){let h=Un([o.signal,AbortSignal.timeout(r.timeout)]);u.signal=h}s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let c=Rr(i,r?.debounce??100),a=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{s||(clearTimeout(n),c())},start:()=>{a||(a=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),a=!1}}}var zs=class extends Map{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function yc(e){let{name:t,metrics:r}=e,n;return r!=null?n=new zs({name:t,metrics:r}):n=new Map,n}var qs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ct(),this.haveNext=Ct()}[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=Ct(),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,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){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=Ct(),await ve(this.readNext.promise,r?.signal,r)}};function bc(){return new qs}var kn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function xc(e,t){let r=bc();e.sink(r).catch(async i=>{await r.end(i)}),e.sink=async i=>{for await(let c of i)await r.push(c);await r.end()};let n=e.source;e.source[Symbol.iterator]!=null?n=e.source[Symbol.iterator]():e.source[Symbol.asyncIterator]!=null&&(n=e.source[Symbol.asyncIterator]());let o=new tt;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:a,value:u}=await ve(n.next(),i?.signal);return a===!0?null:u}for(;o.byteLength<i.bytes;){let{value:a,done:u}=await ve(n.next(),i?.signal);if(u===!0)throw new kn("unexpected end of input");o.append(a)}let c=o.sublist(0,i.bytes);return o.consume(i.bytes),c},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await r.push(i,c):await r.push(i.subarray(),c)},unwrap:()=>{if(o.byteLength>0){let i=e.source;e.source=(async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i})()}return e}}}var Mn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Kn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Fn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function wc(e,t={}){let r=xc(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=gt(t.maxDataLength));let n=t?.lengthDecoder??wr,o=t?.lengthEncoder??ma;return{read:async i=>{let c=-1,a=new tt;for(;;){a.append(await r.read({...i,bytes:1}));try{c=n(a)}catch(u){if(u instanceof RangeError)continue;throw u}if(c<0)throw new Mn("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Fn("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new Kn("message length too long");return r.read({...i,bytes:c})},write:async(i,c)=>{await r.write(new tt(o(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new tt(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(a,c)},unwrap:()=>r.unwrap()}}function Vs(e,t){let r=wc(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var Ec="libp2p",_c="autonat",Sc="1.0.0";var H;(function(e){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=e.MessageType||(e.MessageType={}));let r;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(r||(r={})),(function(u){u.codec=()=>Ve(r)})(t=e.MessageType||(e.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=e.ResponseStatus||(e.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(u){u.codec=()=>Ve(o)})(n=e.ResponseStatus||(e.ResponseStatus={}));let s;(function(u){let h;u.codec=()=>(h==null&&(h=Zt((f,l,p={})=>{if(p.lengthDelimited!==!1&&l.fork(),f.id!=null&&(l.uint32(10),l.bytes(f.id)),f.addrs!=null)for(let d of f.addrs)l.uint32(18),l.bytes(d);p.lengthDelimited!==!1&&l.ldelim()},(f,l,p={})=>{let d={addrs:[]},x=l==null?f.len:f.pos+l;for(;f.pos<x;){let E=f.uint32();switch(E>>>3){case 1:{d.id=f.bytes();break}case 2:{if(p.limits?.addrs!=null&&d.addrs.length===p.limits.addrs)throw new sn('Decode error - map field "addrs" had too many elements');d.addrs.push(f.bytes());break}default:{f.skipType(E&7);break}}}return d})),h),u.encode=f=>Gt(f,u.codec()),u.decode=(f,l)=>$t(f,u.codec(),l)})(s=e.PeerInfo||(e.PeerInfo={}));let i;(function(u){let h;u.codec=()=>(h==null&&(h=Zt((f,l,p={})=>{p.lengthDelimited!==!1&&l.fork(),f.peer!=null&&(l.uint32(10),e.PeerInfo.codec().encode(f.peer,l)),p.lengthDelimited!==!1&&l.ldelim()},(f,l,p={})=>{let d={},x=l==null?f.len:f.pos+l;for(;f.pos<x;){let E=f.uint32();switch(E>>>3){case 1:{d.peer=e.PeerInfo.codec().decode(f,f.uint32(),{limits:p.limits?.peer});break}default:{f.skipType(E&7);break}}}return d})),h),u.encode=f=>Gt(f,u.codec()),u.decode=(f,l)=>$t(f,u.codec(),l)})(i=e.Dial||(e.Dial={}));let c;(function(u){let h;u.codec=()=>(h==null&&(h=Zt((f,l,p={})=>{p.lengthDelimited!==!1&&l.fork(),f.status!=null&&(l.uint32(8),e.ResponseStatus.codec().encode(f.status,l)),f.statusText!=null&&(l.uint32(18),l.string(f.statusText)),f.addr!=null&&(l.uint32(26),l.bytes(f.addr)),p.lengthDelimited!==!1&&l.ldelim()},(f,l,p={})=>{let d={},x=l==null?f.len:f.pos+l;for(;f.pos<x;){let E=f.uint32();switch(E>>>3){case 1:{d.status=e.ResponseStatus.codec().decode(f);break}case 2:{d.statusText=f.string();break}case 3:{d.addr=f.bytes();break}default:{f.skipType(E&7);break}}}return d})),h),u.encode=f=>Gt(f,u.codec()),u.decode=(f,l)=>$t(f,u.codec(),l)})(c=e.DialResponse||(e.DialResponse={}));let a;e.codec=()=>(a==null&&(a=Zt((u,h,f={})=>{f.lengthDelimited!==!1&&h.fork(),u.type!=null&&(h.uint32(8),e.MessageType.codec().encode(u.type,h)),u.dial!=null&&(h.uint32(18),e.Dial.codec().encode(u.dial,h)),u.dialResponse!=null&&(h.uint32(26),e.DialResponse.codec().encode(u.dialResponse,h)),f.lengthDelimited!==!1&&h.ldelim()},(u,h,f={})=>{let l={},p=h==null?u.len:u.pos+h;for(;u.pos<p;){let d=u.uint32();switch(d>>>3){case 1:{l.type=e.MessageType.codec().decode(u);break}case 2:{l.dial=e.Dial.codec().decode(u,u.uint32(),{limits:f.limits?.dial});break}case 3:{l.dialResponse=e.DialResponse.codec().decode(u,u.uint32(),{limits:f.limits?.dialResponse});break}default:{u.skipType(d&7);break}}}return l})),a),e.encode=u=>Gt(u,e.codec()),e.decode=(u,h)=>$t(u,e.codec(),h)})(H||(H={}));var Eh=4,_h=8,zn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${r.protocolPrefix??Ec}/${_c}/${Sc}`,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.connectionThreshold=r.connectionThreshold??80,this.maxMessageSize=r.maxMessageSize??8192,this.dialResults=yc({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=gc(this.findRandomPeers.bind(this),6e4),this.addressFilter=xs(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Gs]=["@libp2p/autonat"];get[Zs](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(r=>{this.log.error("error handling incoming autonat stream - %e",r)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,r)=>{this.verifyExternalAddresses(r).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let r=Un([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:r})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:r})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t){let r=AbortSignal.timeout(this.timeout);let n=Vs(t.stream,{maxDataLength:this.maxMessageSize}).pb(H);try{let o=await n.read({signal:r}),s=await this.handleAutonatMessage(o,t.connection,{signal:r});await n.write(s,{signal:r}),await n.unwrap().unwrap().close({signal:r})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.stream.abort(o)}}async handleAutonatMessage(t,r,n){let o=this.components.addressManager.getAddresses().map(f=>f.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,c=s.peer;if(c?.id==null)return this.log.error("PeerId missing from message"),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=fe(c.id);i=pn(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!r.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,r.remotePeer),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let a=c.addrs.map(f=>Lr(f)).filter(f=>{try{let l=f.toOptions();return ks(f)?!1:l.host!==r.remoteAddr.toOptions().host?(this.log.trace("not dialing %a - target host did not match remote host %a",f,r.remoteAddr),!1):o.includes(l.host)?!1:this.components.transportManager.dialTransportForMultiaddr(f)==null?(this.log.trace("not dialing %a - transport unsupported",f),!1):!0}catch{return!1}}).map(f=>(f.getPeerId()==null&&(f=f.encapsulate(`/p2p/${i.toString()}`)),f));if(a.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",a.map(f=>f.toString()).join(", "),i);let u="",h=a[0];for(let f of a){let l;h=f;try{if(l=await this.components.connectionManager.openConnection(f,n),!l.remoteAddr.equals(f))throw this.log.error("tried to dial %a but dialed %a",f,l.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,f),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.OK,addr:l.remoteAddr.decapsulateCode(cc("p2p").code).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),u=p.message}finally{l!=null&&await l.close()}}return{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:h.bytes}}}getFirstUnverifiedMultiaddr(t,r){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||o.multiaddr.toOptions().family===6&&(!r||!uc(o.multiaddr))||ks(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let c=o.expires<Date.now();if(c&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:ms(),queue:new Nn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>i.toOptions().family===6),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,r,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %p to verify multiaddr %s",t.remotePeer,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let c=Vs(i).pb(H),[,a]=await Promise.all([c.write({type:H.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),c.read({signal:s})]);if(a.type!==H.MessageType.DIAL_RESPONSE||a.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,a);return}let u=a.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==H.ResponseStatus.OK&&u!==H.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,a.dialResponse.status);return}if(o.networkSegments.includes(r)){this.log.trace("%a results included network segment %s",n.multiaddr,r);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(r),u===H.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===H.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Eh&&this.confirmAddress(o),o.failure===_h&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(c){i.abort(c)}}}hasConnectionCapacity(){let r=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return r/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let r=t.toOptions();return r.family===4?r.host.split(".")[0].padStart(3,"0"):r.host.split(":")[0].padStart(4,"0")}};function Sh(e={}){return t=>new zn(t,e)}return Lc(vh);})();
2
+ "use strict";var Libp2PAutonat=(()=>{var uc=Object.create;var Pr=Object.defineProperty;var fc=Object.getOwnPropertyDescriptor;var lc=Object.getOwnPropertyNames;var hc=Object.getPrototypeOf,dc=Object.prototype.hasOwnProperty;var pc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var r in t)Pr(e,r,{get:t[r],enumerable:!0})},Us=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of lc(t))!dc.call(e,o)&&o!==r&&Pr(e,o,{get:()=>t[o],enumerable:!(n=fc(t,o))||n.enumerable});return e};var mc=(e,t,r)=>(r=e!=null?uc(hc(e)):{},Us(t||!e||!e.__esModule?Pr(r,"default",{value:e,enumerable:!0}):r,e)),gc=e=>Us(Pr({},"__esModule",{value:!0}),e);var Ka=pc(Tr=>{(function(){var e,t,r,n,o,s,i,c;c=function(a){var u,h,f,l;return u=(a&255<<24)>>>24,h=(a&255<<16)>>>16,f=(a&65280)>>>8,l=a&255,[u,h,f,l].join(".")},i=function(a){var u,h,f,l,d,p;for(u=[],f=l=0;l<=3&&a.length!==0;f=++l){if(f>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}p=t(a),d=p[0],h=p[1],a=a.substring(h),u.push(d)}if(a.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")}},r=function(a){return a.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),t=function(a){var u,h,f,l,d;for(l=0,u=10,h="9",f=0,a.length>1&&a[f]==="0"&&(a[f+1]==="x"||a[f+1]==="X"?(f+=2,u=16):"0"<=a[f+1]&&a[f+1]<="9"&&(f++,u=8,h="7")),d=f;f<a.length;){if("0"<=a[f]&&a[f]<=h)l=l*u+(r(a[f])-n)>>>0;else if(u===16)if("a"<=a[f]&&a[f]<="f")l=l*u+(10+r(a[f])-s)>>>0;else if("A"<=a[f]&&a[f]<="F")l=l*u+(10+r(a[f])-o)>>>0;else break;else break;if(l>4294967295)throw new Error("too large");f++}if(f===d)throw new Error("empty octet");return[l,f]},e=(function(){function a(u,h){var f,l,d,p;if(typeof u!="string")throw new Error("Missing `net' parameter");if(h||(p=u.split("/",2),u=p[0],h=p[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(x){throw f=x,new Error("Invalid mask: "+h)}for(l=d=32;d>=0;l=--d)if(this.maskLong===4294967295<<32-l>>>0){this.bitmask=l;break}}else if(h||h===0)this.bitmask=parseInt(h,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(x){throw f=x,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+h);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var h,f,l;for(l=i(this.first),f=i(this.last),h=0;l<=f;)u(c(l),l,h),h++,l++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a})(),Tr.ip2long=i,Tr.long2ip=c,Tr.Netmask=e}).call(Tr)});var Bh={};bt(Bh,{autoNAT:()=>Ih});var Dt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ft=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Rr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Or=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Je=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var On=Symbol.for("@libp2p/peer-id");var Nr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var ks=Symbol.for("@libp2p/service-capabilities"),Ms=Symbol.for("@libp2p/service-dependencies");var Kn={};bt(Kn,{base58btc:()=>Y,base58flickr:()=>vc});var nd=new Uint8Array(0);function Ks(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Fs(e){return new TextEncoder().encode(e)}function zs(e){return new TextDecoder().decode(e)}function yc(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),h=Math.log(256)/Math.log(c);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var x=0,E=0,y=0,_=p.length;y!==_&&p[y]===0;)y++,x++;for(var w=(_-y)*h+1>>>0,T=new Uint8Array(w);y!==_;){for(var P=p[y],M=0,k=w-1;(P!==0||M<E)&&k!==-1;k--,M++)P+=256*T[k]>>>0,T[k]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");E=M,y++}for(var O=w-E;O!==w&&T[O]===0;)O++;for(var S=a.repeat(x);O<w;++O)S+=e.charAt(T[O]);return S}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var x=0;if(p[x]!==" "){for(var E=0,y=0;p[x]===a;)E++,x++;for(var _=(p.length-x)*u+1>>>0,w=new Uint8Array(_);p[x];){var T=r[p.charCodeAt(x)];if(T===255)return;for(var P=0,M=_-1;(T!==0||P<y)&&M!==-1;M--,P++)T+=c*w[M]>>>0,w[M]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");y=P,x++}if(p[x]!==" "){for(var k=_-y;k!==_&&w[k]===0;)k++;for(var O=new Uint8Array(E+(_-k)),S=E;k!==_;)O[S++]=w[k++];return O}}}function d(p){var x=l(p);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:l,decode:d}}var bc=yc,xc=bc,Vs=xc;var Nn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Un=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Hs(this,t)}},kn=class{decoders;constructor(t){this.decoders=t}or(t){return Hs(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Hs(e,t){return new kn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Mn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Nn(t,r,n),this.decoder=new Un(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function _e({name:e,prefix:t,encode:r,decode:n}){return new Mn(e,t,r,n)}function Qt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Vs(r,e);return _e({prefix:t,name:e,encode:n,decode:s=>Pt(o(s))})}function wc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let h=t[e[u]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|h,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ec(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Sc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Sc(n);return _e({prefix:t,name:e,encode(s){return Ec(s,n,r)},decode(s){return wc(s,o,r,e)}})}var Y=Qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),vc=Qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Fn={};bt(Fn,{base32:()=>Jt,base32hex:()=>Bc,base32hexpad:()=>Lc,base32hexpadupper:()=>Cc,base32hexupper:()=>Tc,base32pad:()=>Ac,base32padupper:()=>Ic,base32upper:()=>_c,base32z:()=>Dc});var Jt=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),_c=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ac=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ic=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Bc=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Tc=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Lc=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Cc=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Dc=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zn={};bt(zn,{base36:()=>tr,base36upper:()=>Pc});var tr=Qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Pc=Qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Rc=Gs,$s=128,Oc=127,Nc=~Oc,Uc=Math.pow(2,31);function Gs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Uc;)t[r++]=e&255|$s,e/=128;for(;e&Nc;)t[r++]=e&255|$s,e>>>=7;return t[r]=e|0,Gs.bytes=r-n+1,t}var kc=qn,Mc=128,js=127;function qn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw qn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&js)<<o:(i&js)*Math.pow(2,o),o+=7}while(i>=Mc);return qn.bytes=s-n,r}var Kc=Math.pow(2,7),Fc=Math.pow(2,14),zc=Math.pow(2,21),qc=Math.pow(2,28),Vc=Math.pow(2,35),Hc=Math.pow(2,42),$c=Math.pow(2,49),jc=Math.pow(2,56),Gc=Math.pow(2,63),Zc=function(e){return e<Kc?1:e<Fc?2:e<zc?3:e<qc?4:e<Vc?5:e<Hc?6:e<$c?7:e<jc?8:e<Gc?9:10},Wc={encode:Rc,decode:kc,encodingLength:Zc},Xc=Wc,er=Xc;function rr(e,t=0){return[er.decode(e,t),er.decode.bytes]}function Ae(e,t,r=0){return er.encode(e,t,r),t}function Ie(e){return er.encodingLength(e)}function Te(e,t){let r=t.byteLength,n=Ie(e),o=n+Ie(r),s=new Uint8Array(o+r);return Ae(e,s,0),Ae(r,s,n),s.set(t,o),new Be(e,r,t,s)}function ue(e){let t=Pt(e),[r,n]=rr(t),[o,s]=rr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Be(r,o,i,t)}function Zs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ks(e.bytes,r.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Ws(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Qc(r,Vn(e),t??Y.encoder);default:return Jc(r,Vn(e),t??Jt.encoder)}}var Xs=new WeakMap;function Vn(e){let t=Xs.get(e);if(t==null){let r=new Map;return Xs.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=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:r}=this;if(t!==nr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==tu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Te(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Zs(t.multihash,n.multihash)}toString(t){return Ws(this,t)}toJSON(){return{"/":Ws(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Ys(n,o,s.bytes))}else if(r[eu]===!0){let{version:n,multihash:o,code:s}=r,i=ue(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==nr)throw new Error(`Version 0 CID must use dag-pb (code: ${nr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ys(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,nr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Pt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Be(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[f,l]=rr(t.subarray(r));return r+=l,f},o=n(),s=nr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,h=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:h,size:u}}static parse(t,r){let[n,o]=Yc(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Vn(s).set(n,t),s}};function Yc(e,t){switch(e[0]){case"Q":{let r=t??Y;return[Y.prefix,r.decode(`${Y.prefix}${e}`)]}case Y.prefix:{let r=t??Y;return[Y.prefix,r.decode(e)]}case Jt.prefix:{let r=t??Jt;return[Jt.prefix,r.decode(e)]}case tr.prefix:{let r=t??tr;return[tr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Qc(e,t,r){let{prefix:n}=r;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Jc(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var nr=112,tu=18;function Ys(e,t,r){let n=Ie(e),o=n+Ie(t),s=new Uint8Array(o+r.byteLength);return Ae(e,s,0),Ae(t,s,n),s.set(r,o),s}var eu=Symbol.for("@ipld/js-cid/CID");var Hn={};bt(Hn,{identity:()=>_t});var Qs=0,ru="identity",Js=Pt;function nu(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Te(Qs,Js(e))}var _t={code:Qs,name:ru,encode:Js,digest:nu};function lt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function At(e=0){return new Uint8Array(e)}function mt(e=0){return new Uint8Array(e)}function Rt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=mt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var ei=Symbol.for("@achingbrain/uint8arraylist");function ti(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function kr(e){return!!e?.[ei]}var tt=class e{bufs;length;[ei]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(kr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(kr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=ti(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ti(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(kr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Rt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Rt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,h=r>c&&r<=a;if(u&&h){if(t===c&&r===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(h){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!kr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,h;for(let f=r;f<=a;f+=h){h=0;for(let l=u;l>=0;l--){let d=this.get(f+l);if(n[l]!==d){h=Math.max(1,l-c[d]);break}}if(h===0)return f}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=At(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=At(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=At(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=At(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=At(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=At(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=At(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=At(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!lt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var $n={};bt($n,{base10:()=>ou});var ou=Qt({prefix:"9",name:"base10",alphabet:"0123456789"});var jn={};bt(jn,{base16:()=>su,base16upper:()=>iu});var su=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),iu=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Gn={};bt(Gn,{base2:()=>au});var au=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Zn={};bt(Zn,{base256emoji:()=>hu});var ri=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}"),cu=ri.reduce((e,t,r)=>(e[r]=t,e),[]),uu=ri.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function fu(e){return e.reduce((t,r)=>(t+=cu[r],t),"")}function lu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=uu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var hu=_e({prefix:"\u{1F680}",name:"base256emoji",encode:fu,decode:lu});var Xn={};bt(Xn,{base64:()=>du,base64pad:()=>pu,base64url:()=>Wn,base64urlpad:()=>mu});var du=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),pu=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Wn=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),mu=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yn={};bt(Yn,{base8:()=>gu});var gu=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qn={};bt(Qn,{identity:()=>yu});var yu=_e({prefix:"\0",name:"identity",encode:e=>zs(e),decode:e=>Fs(e)});var Fd=new TextEncoder,zd=new TextDecoder;var eo={};bt(eo,{sha256:()=>or,sha512:()=>Eu});var wu=20;function to({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Jn(e,t,r,n,o)}var Jn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??wu,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ni(n,this.code,r?.truncate):n.then(o=>ni(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ni(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Te(t,e)}function si(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var or=to({name:"sha2-256",code:18,encode:si("SHA-256")}),Eu=to({name:"sha2-512",code:19,encode:si("SHA-512")});var sr={...Qn,...Gn,...Yn,...$n,...jn,...Fn,...zn,...Kn,...Xn,...Zn},Jd={...eo,...Hn};function ai(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ii=ai("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),ro=ai("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=mt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Su={utf8:ii,"utf-8":ii,hex:sr.base16,latin1:ro,ascii:ro,binary:ro,...sr},Mr=Su;function $(e,t="utf8"){let r=Mr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function J(e,t="utf8"){let r=Mr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var vu=parseInt("11111",2),no=parseInt("10000000",2),_u=parseInt("01111111",2),ci={0:ir,1:ir,2:Au,3:Tu,4:Lu,5:Bu,6:Iu,16:ir,22:ir,48:ir};function oo(e,t={offset:0}){let r=e[t.offset]&vu;if(t.offset++,ci[r]!=null)return ci[r](e,t);throw new Error("No decoder for tag "+r)}function ar(e,t){let r=0;if((e[t.offset]&no)===no){let n=e[t.offset]&_u,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function ir(e,t){ar(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=oo(e,t);if(n===null)break;r.push(n)}return r}function Au(e,t){let r=ar(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Iu(e,t){let r=ar(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let h=0;for(let f=0;f<a.length;f++)h+=a[f]<<f*7;c+=`.${h}`,a=[]}}return c}function Bu(e,t){return t.offset++,null}function Tu(e,t){let r=ar(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Lu(e,t){let r=ar(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Cu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new tt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function so(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Cu(e.byteLength);return new tt(Uint8Array.from([t.byteLength|no]),t)}function ui(e){let t=new tt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new tt(Uint8Array.from([2]),so(t),t)}function fi(e){let t=Uint8Array.from([0]),r=new tt(t,e);return new tt(Uint8Array.from([3]),so(r),r)}function Kr(e,t=48){let r=new tt;for(let n of e)r.append(n);return new tt(Uint8Array.from([t]),so(r),r)}async function li(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Du=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Pu=Uint8Array.from([6,5,43,129,4,0,34]),Ru=Uint8Array.from([6,5,43,129,4,0,35]),Ou={ext:!0,kty:"EC",crv:"P-256"},Nu={ext:!0,kty:"EC",crv:"P-384"},Uu={ext:!0,kty:"EC",crv:"P-521"},io=32,ao=48,co=66;function hi(e){let t=oo(e);return di(t)}function di(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===io*2+1)return n=J(t.subarray(r,r+io),"base64url"),o=J(t.subarray(r+io),"base64url"),new Le({...Ou,key_ops:["verify"],x:n,y:o});if(t.byteLength===ao*2+1)return n=J(t.subarray(r,r+ao),"base64url"),o=J(t.subarray(r+ao),"base64url"),new Le({...Nu,key_ops:["verify"],x:n,y:o});if(t.byteLength===co*2+1)return n=J(t.subarray(r,r+co),"base64url"),o=J(t.subarray(r+co),"base64url"),new Le({...Uu,key_ops:["verify"],x:n,y:o});throw new ft(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function pi(e){return Kr([ui(Uint8Array.from([1])),Kr([ku(e.crv)],160),Kr([fi(new tt(Uint8Array.from([4]),$(e.x??"","base64url"),$(e.y??"","base64url")))],161)]).subarray()}function ku(e){if(e==="P-256")return Du;if(e==="P-384")return Pu;if(e==="P-521")return Ru;throw new ft(`Invalid curve ${e}`)}var Le=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 _t.digest(Ce(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,r,n){return li(this.jwk,r,t,n)}};var fe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Nt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function cr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function gt(e,...t){if(!Nt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Fr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");cr(e.outputLen),cr(e.blockLen)}function Pe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function gi(e,t){gt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ut(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function zr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var yi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Mu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function vt(e){if(gt(e),yi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Mu[e[r]];return t}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function mi(e){if(e>=Ot._0&&e<=Ot._9)return e-Ot._0;if(e>=Ot.A&&e<=Ot.F)return e-(Ot.A-10);if(e>=Ot.a&&e<=Ot.f)return e-(Ot.a-10)}function le(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(yi)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=mi(e.charCodeAt(s)),c=mi(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function uo(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ur(e){return typeof e=="string"&&(e=uo(e)),gt(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];gt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var De=class{};function fo(e){let t=n=>e().update(ur(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Re(e=32){if(fe&&typeof fe.getRandomValues=="function")return fe.getRandomValues(new Uint8Array(e));if(fe&&typeof fe.randomBytes=="function")return Uint8Array.from(fe.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Ku(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function bi(e,t,r){return e&t^~e&r}function xi(e,t,r){return e&t^e&r^t&r}var fr=class extends De{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=zr(this.buffer)}update(t){Pe(this),t=ur(t),gt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=zr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Pe(this),gi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;Ku(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=zr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,h[f],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},kt=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 qr=BigInt(4294967295),wi=BigInt(32);function Fu(e,t=!1){return t?{h:Number(e&qr),l:Number(e>>wi&qr)}:{h:Number(e>>wi&qr)|0,l:Number(e&qr)|0}}function Ei(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Fu(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var lo=(e,t,r)=>e>>>r,ho=(e,t,r)=>e<<32-r|t>>>r,he=(e,t,r)=>e>>>r|t<<32-r,de=(e,t,r)=>e<<32-r|t>>>r,lr=(e,t,r)=>e<<64-r|t>>>r-32,hr=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Si=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),vi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,_i=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ai=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ii=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Bi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/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]),ee=new Uint32Array(64),po=class extends fr{constructor(t=32){super(64,t,8,!1),this.A=kt[0]|0,this.B=kt[1]|0,this.C=kt[2]|0,this.D=kt[3]|0,this.E=kt[4]|0,this.F=kt[5]|0,this.G=kt[6]|0,this.H=kt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let f=0;f<16;f++,r+=4)ee[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){let l=ee[f-15],d=ee[f-2],p=It(l,7)^It(l,18)^l>>>3,x=It(d,17)^It(d,19)^d>>>10;ee[f]=x+ee[f-7]+p+ee[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:h}=this;for(let f=0;f<64;f++){let l=It(c,6)^It(c,11)^It(c,25),d=h+l+bi(c,a,u)+qu[f]+ee[f]|0,x=(It(n,2)^It(n,13)^It(n,22))+xi(n,o,s)|0;h=u,u=a,a=c,c=i+d|0,i=s,s=o,o=n,n=d+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,h=h+this.H|0,this.set(n,o,s,i,c,a,u,h)}roundClean(){Ut(ee)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}};var Ti=Ei(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Vu=Ti[0],Hu=Ti[1],re=new Uint32Array(80),ne=new Uint32Array(80),mo=class extends fr{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:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:h,Fh:f,Fl:l,Gh:d,Gl:p,Hh:x,Hl:E}=this;return[t,r,n,o,s,i,c,a,u,h,f,l,d,p,x,E]}set(t,r,n,o,s,i,c,a,u,h,f,l,d,p,x,E){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=h|0,this.Fh=f|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=x|0,this.Hl=E|0}process(t,r){for(let w=0;w<16;w++,r+=4)re[w]=t.getUint32(r),ne[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let T=re[w-15]|0,P=ne[w-15]|0,M=he(T,P,1)^he(T,P,8)^lo(T,P,7),k=de(T,P,1)^de(T,P,8)^ho(T,P,7),O=re[w-2]|0,S=ne[w-2]|0,L=he(O,S,19)^lr(O,S,61)^lo(O,S,6),N=de(O,S,19)^hr(O,S,61)^ho(O,S,6),C=_i(k,N,ne[w-7],ne[w-16]),b=Ai(C,M,L,re[w-7],re[w-16]);re[w]=b|0,ne[w]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:h,Eh:f,El:l,Fh:d,Fl:p,Gh:x,Gl:E,Hh:y,Hl:_}=this;for(let w=0;w<80;w++){let T=he(f,l,14)^he(f,l,18)^lr(f,l,41),P=de(f,l,14)^de(f,l,18)^hr(f,l,41),M=f&d^~f&x,k=l&p^~l&E,O=Ii(_,P,k,Hu[w],ne[w]),S=Bi(O,y,T,M,Vu[w],re[w]),L=O|0,N=he(n,o,28)^lr(n,o,34)^lr(n,o,39),C=de(n,o,28)^hr(n,o,34)^hr(n,o,39),b=n&s^n&c^s&c,m=o&i^o&a^i&a;y=x|0,_=E|0,x=d|0,E=p|0,d=f|0,p=l|0,{h:f,l}=Ct(u|0,h|0,S|0,L|0),u=c|0,h=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let g=Si(L,C,m);n=vi(g,S,N,b),o=g|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ct(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:h}=Ct(this.Dh|0,this.Dl|0,u|0,h|0),{h:f,l}=Ct(this.Eh|0,this.El|0,f|0,l|0),{h:d,l:p}=Ct(this.Fh|0,this.Fl|0,d|0,p|0),{h:x,l:E}=Ct(this.Gh|0,this.Gl|0,x|0,E|0),{h:y,l:_}=Ct(this.Hh|0,this.Hl|0,y|0,_|0),this.set(n,o,s,i,c,a,u,h,f,l,d,p,x,E,y,_)}roundClean(){Ut(re,ne)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Li=fo(()=>new po);var Ci=fo(()=>new mo);var bo=BigInt(0),yo=BigInt(1);function Mt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xt(e,t,r=""){let n=Nt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function dr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Di(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?bo:BigInt("0x"+e)}function Oe(e){return Di(vt(e))}function Kt(e){return gt(e),Di(vt(Uint8Array.from(e).reverse()))}function Vr(e,t){return le(e.toString(16).padStart(t*2,"0"))}function xo(e,t){return Vr(e,t).reverse()}function z(e,t,r){let n;if(typeof t=="string")try{n=le(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Nt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Pi(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function wo(e){return Uint8Array.from(e)}var go=e=>typeof e=="bigint"&&bo<=e;function Ri(e,t,r){return go(e)&&go(t)&&go(r)&&t<=e&&e<r}function pr(e,t,r,n){if(!Ri(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Hr(e){let t;for(t=0;e>bo;e>>=yo,t+=1);return t}var oe=e=>(yo<<BigInt(e))-yo;function Oi(e,t,r){if(typeof e!="number"||e<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 r!="function")throw new Error("hmacFn must be a function");let n=d=>new Uint8Array(d),o=d=>Uint8Array.of(d),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...d)=>r(i,s,...d),h=(d=n(0))=>{i=u(o(0),d),s=u(),d.length!==0&&(i=u(o(1),d),s=u())},f=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,p=[];for(;d<t;){s=u();let x=s.slice();p.push(x),d+=s.length}return ht(...p)};return(d,p)=>{a(),h(d);let x;for(;!(x=p(f()));)h();return a(),x}}function se(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Eo=()=>{throw new Error("not implemented")};function Ne(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var dt=BigInt(0),et=BigInt(1),pe=BigInt(2),ki=BigInt(3),Mi=BigInt(4),Ki=BigInt(5),$u=BigInt(7),Fi=BigInt(8),ju=BigInt(9),zi=BigInt(16);function X(e,t){let r=e%t;return r>=dt?r:t+r}function H(e,t,r){let n=e;for(;t-- >dt;)n*=n,n%=r;return n}function Ni(e,t){if(e===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let r=X(e,t),n=t,o=dt,s=et,i=et,c=dt;for(;r!==dt;){let u=n/r,h=n%r,f=o-i*u,l=s-c*u;n=r,r=h,o=i,s=c,i=f,c=l}if(n!==et)throw new Error("invert: does not exist");return X(o,t)}function So(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function qi(e,t){let r=(e.ORDER+et)/Mi,n=e.pow(t,r);return So(e,n,t),n}function Gu(e,t){let r=(e.ORDER-Ki)/Fi,n=e.mul(t,pe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,pe),o),c=e.mul(s,e.sub(i,e.ONE));return So(e,c,t),c}function Zu(e){let t=wt(e),r=Vi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+$u)/zi;return(c,a)=>{let u=c.pow(a,i),h=c.mul(u,n),f=c.mul(u,o),l=c.mul(u,s),d=c.eql(c.sqr(h),a),p=c.eql(c.sqr(f),a);u=c.cmov(u,h,d),h=c.cmov(l,f,p);let x=c.eql(c.sqr(h),a),E=c.cmov(u,h,x);return So(c,E,a),E}}function Vi(e){if(e<ki)throw new Error("sqrt is not defined for small field");let t=e-et,r=0;for(;t%pe===dt;)t/=pe,r++;let n=pe,o=wt(e);for(;Ui(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return qi;let s=o.pow(n,t),i=(t+et)/pe;return function(a,u){if(a.is0(u))return u;if(Ui(a,u)!==1)throw new Error("Cannot find square root");let h=r,f=a.mul(a.ONE,s),l=a.pow(u,t),d=a.pow(u,i);for(;!a.eql(l,a.ONE);){if(a.is0(l))return a.ZERO;let p=1,x=a.sqr(l);for(;!a.eql(x,a.ONE);)if(p++,x=a.sqr(x),p===h)throw new Error("Cannot find square root");let E=et<<BigInt(h-p-1),y=a.pow(f,E);h=p,f=a.sqr(y),l=a.mul(l,f),d=a.mul(d,y)}return d}}function Wu(e){return e%Mi===ki?qi:e%Fi===Ki?Gu:e%zi===ju?Zu(e):Vi(e)}var Ft=(e,t)=>(X(e,t)&et)===et,Xu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Xu.reduce((n,o)=>(n[o]="function",n),t);return se(e,r),e}function Yu(e,t,r){if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return e.ONE;if(r===et)return t;let n=e.ONE,o=t;for(;r>dt;)r&et&&(n=e.mul(n,o)),o=e.sqr(o),r>>=et;return n}function mr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Ui(e,t){let r=(e.ORDER-et)/pe,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function $r(e,t){t!==void 0&&cr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function wt(e,t,r=!1,n={}){if(e<=dt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(o=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(r=l.isLE),typeof l.modFromBytes=="boolean"&&(i=l.modFromBytes),c=l.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=$r(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let h,f=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:oe(a),ZERO:dt,ONE:et,allowedLengths:c,create:l=>X(l,e),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return dt<=l&&l<e},is0:l=>l===dt,isValidNot0:l=>!f.is0(l)&&f.isValid(l),isOdd:l=>(l&et)===et,neg:l=>X(-l,e),eql:(l,d)=>l===d,sqr:l=>X(l*l,e),add:(l,d)=>X(l+d,e),sub:(l,d)=>X(l-d,e),mul:(l,d)=>X(l*d,e),pow:(l,d)=>Yu(f,l,d),div:(l,d)=>X(l*Ni(d,e),e),sqrN:l=>l*l,addN:(l,d)=>l+d,subN:(l,d)=>l-d,mulN:(l,d)=>l*d,inv:l=>Ni(l,e),sqrt:s||(l=>(h||(h=Wu(e)),h(f,l))),toBytes:l=>r?xo(l,u):Vr(l,u),fromBytes:(l,d=!0)=>{if(c){if(!c.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+l.length);let x=new Uint8Array(u);x.set(l,r?0:x.length-l.length),l=x}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let p=r?Kt(l):Oe(l);if(i&&(p=X(p,e)),!d&&!f.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:l=>mr(f,l),cmov:(l,d,p)=>p?d:l});return Object.freeze(f)}function Hi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function _o(e){let t=Hi(e);return t+Math.ceil(t/2)}function Ao(e,t,r=!1){let n=e.length,o=Hi(t),s=_o(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Kt(e):Oe(e),c=X(i,t-et)+et;return r?xo(c,o):Vr(c,o)}var Ue=BigInt(0),me=BigInt(1);function gr(e,t){let r=t.negate();return e?r:t}function zt(e,t){let r=mr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Zi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Io(e,t){Zi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=oe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function $i(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=me);let u=t*n,h=u+Math.abs(c)-1,f=c===0,l=c<0,d=t%2!==0;return{nextN:a,offset:h,isZero:f,isNeg:l,isNegF:d,offsetF:u}}function Qu(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Ju(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Bo=new WeakMap,Wi=new WeakMap;function To(e){return Wi.get(e)||1}function ji(e){if(e!==Ue)throw new Error("invalid wNAF")}var ke=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Ue;)r&me&&(n=n.add(o)),o=o.double(),r>>=me;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Io(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Io(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:h,isNeg:f,isNegF:l,offsetF:d}=$i(n,c,i);n=a,h?s=s.add(gr(l,r[d])):o=o.add(gr(f,r[u]))}return ji(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Io(t,this.bits);for(let i=0;i<s.windows&&n!==Ue;i++){let{nextN:c,offset:a,isZero:u,isNeg:h}=$i(n,i,s);if(n=c,!u){let f=r[a];o=o.add(h?f.negate():f)}}return ji(n),o}getPrecomputes(t,r,n){let o=Bo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Bo.set(r,o))),o}cached(t,r,n){let o=To(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=To(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Zi(r,this.bits),Wi.set(t,r),Bo.delete(t)}hasCache(t){return To(t)!==1}};function Xi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Ue||n>Ue;)r&me&&(s=s.add(o)),n&me&&(i=i.add(o)),o=o.double(),r>>=me,n>>=me;return{p1:s,p2:i}}function Me(e,t,r,n){Qu(r,e),Ju(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Hr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=oe(a),h=new Array(Number(u)+1).fill(i),f=Math.floor((t.BITS-1)/a)*a,l=i;for(let d=f;d>=0;d-=a){h.fill(i);for(let x=0;x<s;x++){let E=n[x],y=Number(E>>BigInt(d)&u);h[y]=h[y].add(r[x])}let p=i;for(let x=h.length-1,E=i;x>0;x--)E=E.add(h[x]),p=p.add(E);if(l=l.add(p),d!==0)for(let x=0;x<a;x++)l=l.double()}return l}function Gi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return vo(t),t}else return wt(e,{isLE:r})}function jr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Ue))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Gi(t.p,r.Fp,n),s=Gi(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var ie=BigInt(0),rt=BigInt(1),Lo=BigInt(2),tf=BigInt(8);function ef(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function rf(e,t={}){let r=jr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;se(t,{},{uvRatio:"function"});let c=Lo<<BigInt(o.BYTES*8)-rt,a=E=>n.create(E),u=t.uvRatio||((E,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(E,y))}}catch{return{isValid:!1,value:ie}}});if(!ef(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function h(E,y,_=!1){let w=_?rt:ie;return pr("coordinate "+E,y,w,c),y}function f(E){if(!(E instanceof p))throw new Error("ExtendedPoint expected")}let l=Ne((E,y)=>{let{X:_,Y:w,Z:T}=E,P=E.is0();y==null&&(y=P?tf:n.inv(T));let M=a(_*y),k=a(w*y),O=n.mul(T,y);if(P)return{x:ie,y:rt};if(O!==rt)throw new Error("invZ was invalid");return{x:M,y:k}}),d=Ne(E=>{let{a:y,d:_}=s;if(E.is0())throw new Error("bad point: ZERO");let{X:w,Y:T,Z:P,T:M}=E,k=a(w*w),O=a(T*T),S=a(P*P),L=a(S*S),N=a(k*y),C=a(S*a(N+O)),b=a(L+a(_*a(k*O)));if(C!==b)throw new Error("bad point: equation left != right (1)");let m=a(w*T),g=a(P*M);if(m!==g)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(y,_,w,T){this.X=h("x",y),this.Y=h("y",_),this.Z=h("z",w,!0),this.T=h("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof p)throw new Error("extended point not allowed");let{x:_,y:w}=y||{};return h("x",_),h("y",w),new p(_,w,rt,a(_*w))}static fromBytes(y,_=!1){let w=n.BYTES,{a:T,d:P}=s;y=wo(xt(y,w,"point")),Mt(_,"zip215");let M=wo(y),k=y[w-1];M[w-1]=k&-129;let O=Kt(M),S=_?c:n.ORDER;pr("point.y",O,ie,S);let L=a(O*O),N=a(L-rt),C=a(P*L-T),{isValid:b,value:m}=u(N,C);if(!b)throw new Error("bad point: invalid y coordinate");let g=(m&rt)===rt,v=(k&128)!==0;if(!_&&m===ie&&v)throw new Error("bad point: x=0 and x_0=1");return v!==g&&(m=a(-m)),p.fromAffine({x:m,y:O})}static fromHex(y,_=!1){return p.fromBytes(z("point",y),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,_=!0){return x.createCache(this,y),_||this.multiply(Lo),this}assertValidity(){d(this)}equals(y){f(y);let{X:_,Y:w,Z:T}=this,{X:P,Y:M,Z:k}=y,O=a(_*k),S=a(P*T),L=a(w*k),N=a(M*T);return O===S&&L===N}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:y}=s,{X:_,Y:w,Z:T}=this,P=a(_*_),M=a(w*w),k=a(Lo*a(T*T)),O=a(y*P),S=_+w,L=a(a(S*S)-P-M),N=O+M,C=N-k,b=O-M,m=a(L*C),g=a(N*b),v=a(L*b),A=a(C*N);return new p(m,g,A,v)}add(y){f(y);let{a:_,d:w}=s,{X:T,Y:P,Z:M,T:k}=this,{X:O,Y:S,Z:L,T:N}=y,C=a(T*O),b=a(P*S),m=a(k*w*N),g=a(M*L),v=a((T+P)*(O+S)-C-b),A=g-m,D=g+m,I=a(b-_*C),B=a(v*A),R=a(D*I),U=a(v*I),j=a(A*D);return new p(B,R,j,U)}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:w}=x.cached(this,y,T=>zt(p,T));return zt(p,[_,w])[0]}multiplyUnsafe(y,_=p.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===ie?p.ZERO:this.is0()||y===rt?this:x.unsafe(this,y,w=>zt(p,w),_)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return x.unsafe(this,s.n).is0()}toAffine(y){return l(this,y)}clearCofactor(){return i===rt?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:_}=this.toAffine(),w=n.toBytes(_);return w[w.length-1]|=y&rt?128:0,w}toHex(){return vt(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 zt(p,y)}static msm(y,_){return Me(p,o,y,_)}_setWindowSize(y){this.precompute(y)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,rt,a(s.Gx*s.Gy)),p.ZERO=new p(ie,rt,rt,ie),p.Fp=n,p.Fn=o;let x=new ke(p,o.BITS);return p.BASE.precompute(8),p}var Gr=class{constructor(t){this.ep=t}static fromBytes(t){Eo()}static fromHex(t){Eo()}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 vt(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,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function nf(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');se(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||Re,a=r.adjustScalarBytes||(S=>S),u=r.domain||((S,L,N)=>{if(Mt(N,"phflag"),L.length||N)throw new Error("Contexts/pre-hash are not supported");return S});function h(S){return i.create(Kt(S))}function f(S){let L=w.secretKey;S=z("private key",S,L);let N=z("hashed private key",t(S),2*L),C=a(N.slice(0,L)),b=N.slice(L,2*L),m=h(C);return{head:C,prefix:b,scalar:m}}function l(S){let{head:L,prefix:N,scalar:C}=f(S),b=o.multiply(C),m=b.toBytes();return{head:L,prefix:N,scalar:C,point:b,pointBytes:m}}function d(S){return l(S).pointBytes}function p(S=Uint8Array.of(),...L){let N=ht(...L);return h(t(u(N,z("context",S),!!n)))}function x(S,L,N={}){S=z("message",S),n&&(S=n(S));let{prefix:C,scalar:b,pointBytes:m}=l(L),g=p(N.context,C,S),v=o.multiply(g).toBytes(),A=p(N.context,v,m,S),D=i.create(g+A*b);if(!i.isValid(D))throw new Error("sign failed: invalid s");let I=ht(v,i.toBytes(D));return xt(I,w.signature,"result")}let E={zip215:!0};function y(S,L,N,C=E){let{context:b,zip215:m}=C,g=w.signature;S=z("signature",S,g),L=z("message",L),N=z("publicKey",N,w.publicKey),m!==void 0&&Mt(m,"zip215"),n&&(L=n(L));let v=g/2,A=S.subarray(0,v),D=Kt(S.subarray(v,g)),I,B,R;try{I=e.fromBytes(N,m),B=e.fromBytes(A,m),R=o.multiplyUnsafe(D)}catch{return!1}if(!m&&I.isSmallOrder())return!1;let U=p(b,B.toBytes(),I.toBytes(),L);return B.add(I.multiplyUnsafe(U)).subtract(R).clearCofactor().is0()}let _=s.BYTES,w={secretKey:_,publicKey:_,signature:2*_,seed:_};function T(S=c(w.seed)){return xt(S,w.seed,"seed")}function P(S){let L=O.randomSecretKey(S);return{secretKey:L,publicKey:d(L)}}function M(S){return Nt(S)&&S.length===i.BYTES}function k(S,L){try{return!!e.fromBytes(S,L)}catch{return!1}}let O={getExtendedPublicKey:l,randomSecretKey:T,isValidSecretKey:M,isValidPublicKey:k,toMontgomery(S){let{y:L}=e.fromBytes(S),N=w.publicKey,C=N===32;if(!C&&N!==57)throw new Error("only defined for 25519 and 448");let b=C?s.div(rt+L,rt-L):s.div(L-rt,L+rt);return s.toBytes(b)},toMontgomerySecret(S){let L=w.secretKey;xt(S,L);let N=t(S.subarray(0,L));return a(N).subarray(0,L)},randomPrivateKey:T,precompute(S=8,L=e.BASE){return L.precompute(S,!1)}};return Object.freeze({keygen:P,getPublicKey:d,sign:x,verify:y,utils:O,Point:e,lengths:w})}function of(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=wt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function sf(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Yi(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=of(e),s=rf(t,r),i=nf(s,n,o);return sf(e,i)}var af=BigInt(0),qt=BigInt(1),Qi=BigInt(2),a0=BigInt(3),cf=BigInt(5),uf=BigInt(8),Ke=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yr={p:Ke,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:uf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ff(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ke,c=e*e%s*e%s,a=H(c,Qi,s)*c%s,u=H(a,qt,s)*e%s,h=H(u,cf,s)*u%s,f=H(h,t,s)*h%s,l=H(f,r,s)*f%s,d=H(l,n,s)*l%s,p=H(d,o,s)*d%s,x=H(p,o,s)*d%s,E=H(x,t,s)*h%s;return{pow_p_5_8:H(E,Qi,s)*e%s,b2:c}}function lf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Co=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ro(e,t){let r=Ke,n=X(t*t*t,r),o=X(n*n*t,r),s=ff(e*o).pow_p_5_8,i=X(e*n*s,r),c=X(t*i*i,r),a=i,u=X(i*Co,r),h=c===e,f=c===X(-e,r),l=c===X(-e*Co,r);return h&&(i=a),(f||l)&&(i=u),Ft(i,r)&&(i=X(-i,r)),{isValid:h||f,value:i}}var ae=wt(yr.p,{isLE:!0}),hf=wt(yr.n,{isLE:!0}),df={...yr,Fp:ae,hash:Ci,adjustScalarBytes:lf,uvRatio:Ro},Vt=Yi(df);var Do=Co,pf=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),mf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),gf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),yf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ji=e=>Ro(qt,e),bf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Po=e=>Vt.Point.Fp.create(Kt(e)&bf);function ta(e){let{d:t}=yr,r=Ke,n=y=>ae.create(y),o=n(Do*e*e),s=n((o+qt)*gf),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=Ro(s,c),h=n(u*e);Ft(h,r)||(h=n(-h)),a||(u=h),a||(i=o);let f=n(i*(o-qt)*yf-c),l=u*u,d=n((u+u)*c),p=n(f*pf),x=n(qt-l),E=n(qt+l);return new Vt.Point(n(d*E),n(x*p),n(p*E),n(d*x))}function xf(e){gt(e,64);let t=Po(e.subarray(0,32)),r=ta(t),n=Po(e.subarray(32,64)),o=ta(n);return new Ht(r.add(o))}var Ht=class e extends Gr{constructor(t){super(t)}static fromAffine(t){return new e(Vt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return xf(z("ristrettoHash",t,64))}static fromBytes(t){gt(t,32);let{a:r,d:n}=yr,o=Ke,s=T=>ae.create(T),i=Po(t);if(!Pi(ae.toBytes(i),t)||Ft(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(qt+r*c),u=s(qt-r*c),h=s(a*a),f=s(u*u),l=s(r*n*h-f),{isValid:d,value:p}=Ji(s(l*f)),x=s(p*u),E=s(p*x*l),y=s((i+i)*x);Ft(y,o)&&(y=s(-y));let _=s(a*E),w=s(y*_);if(!d||Ft(w,o)||_===af)throw new Error("invalid ristretto255 encoding 2");return new e(new Vt.Point(y,_,qt,w))}static fromHex(t){return e.fromBytes(z("ristrettoHex",t,32))}static msm(t,r){return Me(e,Vt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ke,i=E=>ae.create(E),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:h}=Ji(i(c*u)),f=i(h*c),l=i(h*a),d=i(f*l*o),p;if(Ft(o*d,s)){let E=i(r*Do),y=i(t*Do);t=E,r=y,p=i(f*mf)}else p=l;Ft(t*d,s)&&(r=i(-r));let x=i((n-r)*p);return Ft(x,s)&&(x=i(-x)),ae.toBytes(x)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ae.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};Ht.BASE=new Ht(Vt.Point.BASE);Ht.ZERO=new Ht(Vt.Point.ZERO);Ht.Fp=ae;Ht.Fn=hf;var br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ea={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Zr("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=ea;var Xr=32;var Oo,wf=(async()=>{try{return await Wr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ef(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Wr.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Wr.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Sf(e,t,r){return Vt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ra(e,t,r){return Oo==null&&(Oo=await wf),Oo?Ef(e,t,r):Sf(e,t,r)}function Yr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Qr=class{type="Ed25519";raw;constructor(t){this.raw=No(t,Xr)}toMultihash(){return _t.digest(Ce(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ra(this.raw,r,t);return Yr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function oa(e){return e=No(e,Xr),new Qr(e)}function No(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ft(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var _f=Math.pow(2,7),Af=Math.pow(2,14),If=Math.pow(2,21),Uo=Math.pow(2,28),ko=Math.pow(2,35),Mo=Math.pow(2,42),Ko=Math.pow(2,49),F=128,ct=127;function yt(e){if(e<_f)return 1;if(e<Af)return 2;if(e<If)return 3;if(e<Uo)return 4;if(e<ko)return 5;if(e<Mo)return 6;if(e<Ko)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Fe(e,t,r=0){switch(yt(e)){case 8:t[r++]=e&255|F,e/=128;case 7:t[r++]=e&255|F,e/=128;case 6:t[r++]=e&255|F,e/=128;case 5:t[r++]=e&255|F,e/=128;case 4:t[r++]=e&255|F,e>>>=7;case 3:t[r++]=e&255|F,e>>>=7;case 2:t[r++]=e&255|F,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Bf(e,t,r=0){switch(yt(e)){case 8:t.set(r++,e&255|F),e/=128;case 7:t.set(r++,e&255|F),e/=128;case 6:t.set(r++,e&255|F),e/=128;case 5:t.set(r++,e&255|F),e/=128;case 4:t.set(r++,e&255|F),e>>>=7;case 3:t.set(r++,e&255|F),e>>>=7;case 2:t.set(r++,e&255|F),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Fo(e,t){let r=e[t],n=0;if(n+=r&ct,r<F||(r=e[t+1],n+=(r&ct)<<7,r<F)||(r=e[t+2],n+=(r&ct)<<14,r<F)||(r=e[t+3],n+=(r&ct)<<21,r<F)||(r=e[t+4],n+=(r&ct)*Uo,r<F)||(r=e[t+5],n+=(r&ct)*ko,r<F)||(r=e[t+6],n+=(r&ct)*Mo,r<F)||(r=e[t+7],n+=(r&ct)*Ko,r<F))return n;throw new RangeError("Could not decode varint")}function Tf(e,t){let r=e.get(t),n=0;if(n+=r&ct,r<F||(r=e.get(t+1),n+=(r&ct)<<7,r<F)||(r=e.get(t+2),n+=(r&ct)<<14,r<F)||(r=e.get(t+3),n+=(r&ct)<<21,r<F)||(r=e.get(t+4),n+=(r&ct)*Uo,r<F)||(r=e.get(t+5),n+=(r&ct)*ko,r<F)||(r=e.get(t+6),n+=(r&ct)*Mo,r<F)||(r=e.get(t+7),n+=(r&ct)*Ko,r<F))return n;throw new RangeError("Could not decode varint")}function sa(e,t,r=0){return t==null&&(t=mt(yt(e))),t instanceof Uint8Array?Fe(e,t,r):Bf(e,t,r)}function xr(e,t=0){return e instanceof Uint8Array?Fo(e,t):Tf(e,t)}var zo=new Float32Array([-0]),ce=new Uint8Array(zo.buffer);function aa(e,t,r){zo[0]=e,t[r]=ce[0],t[r+1]=ce[1],t[r+2]=ce[2],t[r+3]=ce[3]}function ca(e,t){return ce[0]=e[t],ce[1]=e[t+1],ce[2]=e[t+2],ce[3]=e[t+3],zo[0]}var qo=new Float64Array([-0]),ut=new Uint8Array(qo.buffer);function ua(e,t,r){qo[0]=e,t[r]=ut[0],t[r+1]=ut[1],t[r+2]=ut[2],t[r+3]=ut[3],t[r+4]=ut[4],t[r+5]=ut[5],t[r+6]=ut[6],t[r+7]=ut[7]}function fa(e,t){return ut[0]=e[t],ut[1]=e[t+1],ut[2]=e[t+2],ut[3]=e[t+3],ut[4]=e[t+4],ut[5]=e[t+5],ut[6]=e[t+6],ut[7]=e[t+7],qo[0]}var Lf=BigInt(Number.MAX_SAFE_INTEGER),Cf=BigInt(Number.MIN_SAFE_INTEGER),Et=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<Lf&&t>Cf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>la&&(o=0n,++n>la&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ge}},ge=new Et(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var la=4294967296n;function ha(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function da(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Vo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Bt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Jr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Ho=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,Bt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Jr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Jr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=ca(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=fa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return da(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=Jr(this.buf,this.pos+=4),r=Jr(this.buf,this.pos+=4);return new Et(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Fo(this.buf,this.pos);return this.pos+=yt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function $o(e){return new Ho(e instanceof Uint8Array?e:e.subarray())}function $t(e,t,r){let n=$o(e);return t.decode(n,void 0,r)}function jo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return mt(i);o+i>t&&(n=mt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var ye=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Go(){}var Wo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Df=jo();function Pf(e){return globalThis.Buffer!=null?mt(e):Df(e)}var Er=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye(Go,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ye(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Xo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(tn,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Et.fromBigInt(t);return this._push(tn,r.length(),r)}uint64Number(t){return this._push(Fe,yt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Et.fromBigInt(t).zzEncode();return this._push(tn,r.length(),r)}sint64Number(t){let r=Et.fromNumber(t).zzEncode();return this._push(tn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zo,1,t?1:0)}fixed32(t){return this._push(wr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Et.fromBigInt(t);return this._push(wr,4,r.lo)._push(wr,4,r.hi)}fixed64Number(t){let r=Et.fromNumber(t);return this._push(wr,4,r.lo)._push(wr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(aa,4,t)}double(t){return this._push(ua,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Zo,1,0):this.uint32(r)._push(Of,r,t)}string(t){let r=ha(t);return r!==0?this.uint32(r)._push(Vo,r,t):this._push(Zo,1,0)}fork(){return this.states=new Wo(this),this.head=this.tail=new ye(Go,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ye(Go,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Pf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Zo(e,t,r){t[r]=e&255}function Rf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Xo=class extends ye{next;constructor(t,r){super(Rf,t,r),this.next=void 0}};function tn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function wr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Of(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Er.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Nf,t,e),this},Er.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Uf,t,e),this});function Nf(e,t,r){t.set(e,r)}function Uf(e,t,r){e.length<40?Vo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set($(e),r)}function Yo(){return new Er}function jt(e,t){let r=Yo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var ze;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(ze||(ze={}));function en(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function qe(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return en("enum",ze.VARINT,r,n)}function Gt(e,t){return en("message",ze.LENGTH_DELIMITED,e,t)}var rn=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var St;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(St||(St={}));var Qo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Qo||(Qo={}));(function(e){e.codec=()=>qe(Qo)})(St||(St={}));var Sr;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),St.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=St.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>jt(r,e.codec()),e.decode=(r,n)=>$t(r,e.codec(),n)})(Sr||(Sr={}));var Jo;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),St.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=St.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>jt(r,e.codec()),e.decode=(r,n)=>$t(r,e.codec(),n)})(Jo||(Jo={}));var nn=class extends De{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Fr(t);let n=ur(r);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 Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),gt(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:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ts=(e,t,r)=>new nn(e,t).update(r).digest();ts.create=(e,t)=>new nn(e,t);var ma=(e,t)=>(e+(e>=0?t:-t)/ga)/t;function Mf(e,t,r){let[[n,o],[s,i]]=t,c=ma(i*e,r),a=ma(-o*e,r),u=e-c*n-a*s,h=-c*o-a*i,f=u<Wt,l=h<Wt;f&&(u=-u),l&&(h=-h);let d=oe(Math.ceil(Hr(r)/2))+He;if(u<Wt||u>=d||h<Wt||h>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:u,k2neg:l,k2:h}}function rs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function es(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Mt(r.lowS,"lowS"),Mt(r.prehash,"prehash"),r.format!==void 0&&rs(r.format),r}var ns=class extends Error{constructor(t=""){super(t)}},Zt={Err:ns,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=dr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?dr(o.length/2|128):"";return dr(e)+s+o+t},decode(e,t){let{Err:r}=Zt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let h of u)i=i<<8|h;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Zt;if(e<Wt)throw new t("integer: negative integers are not allowed");let r=dr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Zt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Oe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Zt,o=z("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:h}=n.decode(2,a);if(h.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Wt=BigInt(0),He=BigInt(1),ga=BigInt(2),on=BigInt(3),Kf=BigInt(4);function Ve(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=z("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Ff(e,t={}){let r=jr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;se(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=ba(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(C,b,m){let{x:g,y:v}=b.toAffine(),A=n.toBytes(g);if(Mt(m,"isCompressed"),m){h();let D=!n.isOdd(v);return ht(ya(D),A)}else return ht(Uint8Array.of(4),A,n.toBytes(v))}function l(C){xt(C,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=u,g=C.length,v=C[0],A=C.subarray(1);if(g===b&&(v===2||v===3)){let D=n.fromBytes(A);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let I=x(D),B;try{B=n.sqrt(I)}catch(j){let q=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}h();let R=n.isOdd(B);return(v&1)===1!==R&&(B=n.neg(B)),{x:D,y:B}}else if(g===m&&v===4){let D=n.BYTES,I=n.fromBytes(A.subarray(0,D)),B=n.fromBytes(A.subarray(D,D*2));if(!E(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 d=t.toBytes||f,p=t.fromBytes||l;function x(C){let b=n.sqr(C),m=n.mul(b,C);return n.add(n.add(m,n.mul(C,s.a)),s.b)}function E(C,b){let m=n.sqr(b),g=x(C);return n.eql(m,g)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,on),Kf),_=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,_)))throw new Error("bad curve params: a or b");function w(C,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${C}`);return b}function T(C){if(!(C instanceof S))throw new Error("ProjectivePoint expected")}function P(C){if(!a||!a.basises)throw new Error("no endo");return Mf(C,a.basises,o.ORDER)}let M=Ne((C,b)=>{let{X:m,Y:g,Z:v}=C;if(n.eql(v,n.ONE))return{x:m,y:g};let A=C.is0();b==null&&(b=A?n.ONE:n.inv(v));let D=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:D,y:I}}),k=Ne(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=C.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!E(b,m))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function O(C,b,m,g,v){return m=new S(n.mul(m.X,C),m.Y,m.Z),b=gr(g,b),m=gr(v,m),b.add(m)}class S{constructor(b,m,g){this.X=w("x",b),this.Y=w("y",m,!0),this.Z=w("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 S)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(g)?S.ZERO:new S(m,g,n.ONE)}static fromBytes(b){let m=S.fromAffine(p(xt(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return S.fromBytes(z("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return N.createCache(this,b),m||this.multiply(on),this}assertValidity(){k(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){T(b);let{X:m,Y:g,Z:v}=this,{X:A,Y:D,Z:I}=b,B=n.eql(n.mul(m,I),n.mul(A,v)),R=n.eql(n.mul(g,I),n.mul(D,v));return B&&R}negate(){return new S(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,g=n.mul(m,on),{X:v,Y:A,Z:D}=this,I=n.ZERO,B=n.ZERO,R=n.ZERO,U=n.mul(v,v),j=n.mul(A,A),q=n.mul(D,D),K=n.mul(v,A);return K=n.add(K,K),R=n.mul(v,D),R=n.add(R,R),I=n.mul(b,R),B=n.mul(g,q),B=n.add(I,B),I=n.sub(j,B),B=n.add(j,B),B=n.mul(I,B),I=n.mul(K,I),R=n.mul(g,R),q=n.mul(b,q),K=n.sub(U,q),K=n.mul(b,K),K=n.add(K,R),R=n.add(U,U),U=n.add(R,U),U=n.add(U,q),U=n.mul(U,K),B=n.add(B,U),q=n.mul(A,D),q=n.add(q,q),U=n.mul(q,K),I=n.sub(I,U),R=n.mul(q,j),R=n.add(R,R),R=n.add(R,R),new S(I,B,R)}add(b){T(b);let{X:m,Y:g,Z:v}=this,{X:A,Y:D,Z:I}=b,B=n.ZERO,R=n.ZERO,U=n.ZERO,j=s.a,q=n.mul(s.b,on),K=n.mul(m,A),G=n.mul(g,D),Q=n.mul(v,I),pt=n.add(m,g),Z=n.add(A,D);pt=n.mul(pt,Z),Z=n.add(K,G),pt=n.sub(pt,Z),Z=n.add(m,v);let it=n.add(A,I);return Z=n.mul(Z,it),it=n.add(K,Q),Z=n.sub(Z,it),it=n.add(g,v),B=n.add(D,I),it=n.mul(it,B),B=n.add(G,Q),it=n.sub(it,B),U=n.mul(j,Z),B=n.mul(q,Q),U=n.add(B,U),B=n.sub(G,U),U=n.add(G,U),R=n.mul(B,U),G=n.add(K,K),G=n.add(G,K),Q=n.mul(j,Q),Z=n.mul(q,Z),G=n.add(G,Q),Q=n.sub(K,Q),Q=n.mul(j,Q),Z=n.add(Z,Q),K=n.mul(G,Z),R=n.add(R,K),K=n.mul(it,Z),B=n.mul(pt,B),B=n.sub(B,K),K=n.mul(pt,G),U=n.mul(it,U),U=n.add(U,K),new S(B,R,U)}subtract(b){return this.add(b.negate())}is0(){return this.equals(S.ZERO)}multiply(b){let{endo:m}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let g,v,A=D=>N.cached(this,D,I=>zt(S,I));if(m){let{k1neg:D,k1:I,k2neg:B,k2:R}=P(b),{p:U,f:j}=A(I),{p:q,f:K}=A(R);v=j.add(K),g=O(m.beta,U,q,D,B)}else{let{p:D,f:I}=A(b);g=D,v=I}return zt(S,[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===Wt||g.is0())return S.ZERO;if(b===He)return g;if(N.hasCache(this))return this.multiply(b);if(m){let{k1neg:v,k1:A,k2neg:D,k2:I}=P(b),{p1:B,p2:R}=Xi(S,g,A,I);return O(m.beta,B,R,v,D)}else return N.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===He?!0:b?b(S,this):N.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===He?this:b?b(S,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return Mt(b,"isCompressed"),this.assertValidity(),d(S,this,b)}toHex(b=!0){return vt(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 zt(S,b)}static msm(b,m){return Me(S,o,b,m)}static fromPrivateKey(b){return S.BASE.multiply(Ve(o,b))}}S.BASE=new S(s.Gx,s.Gy,n.ONE),S.ZERO=new S(n.ZERO,n.ONE,n.ZERO),S.Fp=n,S.Fn=o;let L=o.BITS,N=new ke(S,t.endo?Math.ceil(L/2):L);return S.BASE.precompute(8),S}function ya(e){return Uint8Array.of(e?2:3)}function ba(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function zf(e,t={}){let{Fn:r}=e,n=t.randomBytes||Re,o=Object.assign(ba(e.Fp,r),{seed:_o(r.ORDER)});function s(d){try{return!!Ve(r,d)}catch{return!1}}function i(d,p){let{publicKey:x,publicKeyUncompressed:E}=o;try{let y=d.length;return p===!0&&y!==x||p===!1&&y!==E?!1:!!e.fromBytes(d)}catch{return!1}}function c(d=n(o.seed)){return Ao(xt(d,o.seed,"seed"),r.ORDER)}function a(d,p=!0){return e.BASE.multiply(Ve(r,d)).toBytes(p)}function u(d){let p=c(d);return{secretKey:p,publicKey:a(p)}}function h(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let{secretKey:p,publicKey:x,publicKeyUncompressed:E}=o;if(r.allowedLengths||p===x)return;let y=z("key",d).length;return y===x||y===E}function f(d,p,x=!0){if(h(d)===!0)throw new Error("first arg must be private key");if(h(p)===!1)throw new Error("second arg must be public key");let E=Ve(r,d);return e.fromHex(p).multiply(E).toBytes(x)}return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:d=>Ve(r,d),precompute(d=8,p=e.BASE){return p.precompute(d,!1)}},lengths:o})}function qf(e,t,r={}){Fr(t),se(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||Re,o=r.hmac||((m,...g)=>ts(t,m,ht(...g))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:h,getSharedSecret:f,utils:l,lengths:d}=zf(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},x="compact";function E(m){let g=c>>He;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){rs(g);let v=d.signature,A=g==="compact"?v:g==="recovered"?v+1:void 0;return xt(m,A,`${g} signature`)}class w{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=x){_(g,v);let A;if(v==="der"){let{r:R,s:U}=Zt.toSig(xt(g));return new w(R,U)}v==="recovered"&&(A=g[0],v="compact",g=g.subarray(1));let D=i.BYTES,I=g.subarray(0,D),B=g.subarray(D,D*2);return new w(i.fromBytes(I),i.fromBytes(B),A)}static fromHex(g,v){return this.fromBytes(le(g),v)}addRecoveryBit(g){return new w(this.r,this.s,g)}recoverPublicKey(g){let v=s.ORDER,{r:A,s:D,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(c*ga<v&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=I===2||I===3?A+c:A;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let U=s.toBytes(R),j=e.fromBytes(ht(ya((I&1)===0),U)),q=i.inv(R),K=P(z("msgHash",g)),G=i.create(-K*q),Q=i.create(D*q),pt=e.BASE.multiplyUnsafe(G).add(j.multiplyUnsafe(Q));if(pt.is0())throw new Error("point at infinify");return pt.assertValidity(),pt}hasHighS(){return E(this.s)}toBytes(g=x){if(rs(g),g==="der")return le(Zt.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 ht(Uint8Array.of(this.recovery),v,A)}return ht(v,A)}toHex(g){return vt(this.toBytes(g))}assertValidity(){}static fromCompact(g){return w.fromBytes(z("sig",g),"compact")}static fromDER(g){return w.fromBytes(z("sig",g),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return vt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return vt(this.toBytes("compact"))}}let T=r.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");let v=Oe(g),A=g.length*8-a;return A>0?v>>BigInt(A):v},P=r.bits2int_modN||function(g){return i.create(T(g))},M=oe(a);function k(m){return pr("num < 2^"+a,m,Wt,M),i.toBytes(m)}function O(m,g){return xt(m,void 0,"message"),g?xt(t(m),void 0,"prehashed message"):m}function S(m,g,v){if(["recovered","canonical"].some(G=>G in v))throw new Error("sign() legacy options not supported");let{lowS:A,prehash:D,extraEntropy:I}=es(v,p);m=O(m,D);let B=P(m),R=Ve(i,g),U=[k(R),k(B)];if(I!=null&&I!==!1){let G=I===!0?n(d.secretKey):I;U.push(z("extraEntropy",G))}let j=ht(...U),q=B;function K(G){let Q=T(G);if(!i.isValidNot0(Q))return;let pt=i.inv(Q),Z=e.BASE.multiply(Q).toAffine(),it=i.create(Z.x);if(it===Wt)return;let Dr=i.create(pt*i.create(q+it*R));if(Dr===Wt)return;let Os=(Z.x===it?0:2)|Number(Z.y&He),Ns=Dr;return A&&E(Dr)&&(Ns=i.neg(Dr),Os^=1),new w(it,Ns,Os)}return{seed:j,k2sig:K}}function L(m,g,v={}){m=z("message",m);let{seed:A,k2sig:D}=S(m,g,v);return Oi(t.outputLen,i.BYTES,o)(A,D)}function N(m){let g,v=typeof m=="string"||Nt(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 w(m.r,m.s);else if(v){try{g=w.fromBytes(z("sig",m),"der")}catch(D){if(!(D instanceof Zt.Err))throw D}if(!g)try{g=w.fromBytes(z("sig",m),"compact")}catch{return!1}}return g||!1}function C(m,g,v,A={}){let{lowS:D,prehash:I,format:B}=es(A,p);if(v=z("publicKey",v),g=O(z("message",g),I),"strict"in A)throw new Error("options.strict was renamed to lowS");let R=B===void 0?N(m):w.fromBytes(z("sig",m),B);if(R===!1)return!1;try{let U=e.fromBytes(v);if(D&&R.hasHighS())return!1;let{r:j,s:q}=R,K=P(g),G=i.inv(q),Q=i.create(K*G),pt=i.create(j*G),Z=e.BASE.multiplyUnsafe(Q).add(U.multiplyUnsafe(pt));return Z.is0()?!1:i.create(Z.x)===j}catch{return!1}}function b(m,g,v={}){let{prehash:A}=es(v,p);return g=O(g,A),w.fromBytes(m,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:h,getSharedSecret:f,utils:l,lengths:d,Point:e,sign:L,verify:C,recoverPublicKey:b,Signature:w,hash:t})}function Vf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=wt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function Hf(e){let{CURVE:t,curveOpts:r}=Vf(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function $f(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,$r(r.Fn.ORDER,r.Fn.BITS))})}function xa(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=Hf(e),s=Ff(t,r),i=qf(s,n,o);return $f(e,i)}function wa(e,t){let r=n=>xa({...e,hash:n});return{...r(t),create:r}}var ss={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},jf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ea=BigInt(2);function Gf(e){let t=ss.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,h=u*u*e%t,f=H(h,r,t)*h%t,l=H(f,r,t)*h%t,d=H(l,Ea,t)*u%t,p=H(d,o,t)*d%t,x=H(p,s,t)*p%t,E=H(x,c,t)*x%t,y=H(E,a,t)*E%t,_=H(y,c,t)*x%t,w=H(_,r,t)*h%t,T=H(w,i,t)*p%t,P=H(T,n,t)*u%t,M=H(P,Ea,t);if(!os.eql(os.sqr(M),e))throw new Error("Cannot find square root");return M}var os=wt(ss.p,{sqrt:Gf}),$e=wa({...ss,Fp:os,lowS:!0,endo:jf},Li);function Sa(e,t,r,n){let o=or.digest(r instanceof Uint8Array?r:r.subarray());if(Yr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),$e.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new br(String(s))});try{return n?.signal?.throwIfAborted(),$e.verify(t,o.digest,e)}catch(s){throw new br(String(s))}}var sn=class{type="secp256k1";raw;_key;constructor(t){this._key=_a(t),this.raw=va(this._key)}toMultihash(){return _t.digest(Ce(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){return Sa(this._key,r,t,n)}};function Aa(e){return new sn(e)}function va(e){return $e.ProjectivePoint.fromHex(e).toRawBytes(!0)}function _a(e){try{return $e.ProjectivePoint.fromHex(e),e}catch(t){throw new Rr(String(t))}}function Ia(e){let{Type:t,Data:r}=Sr.decode(e.digest),n=r??new Uint8Array;switch(t){case St.Ed25519:return oa(n);case St.secp256k1:return Aa(n);case St.ECDSA:return hi(n);default:throw new Je}}function Ce(e){return Sr.encode({Type:St[e.type],Data:e.raw})}var Ba=Symbol.for("nodejs.util.inspect.custom"),Zf=114,vr=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()})`}[On]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Zf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ba](){return`PeerId(${this.toString()})`}},an=class extends vr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},cn=class extends vr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},un=class extends vr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Wf=2336,fn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest($(this.url))}[Ba](){return`PeerId(${this.url})`}[On]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Wf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=J(t)),t.toString()===this.toString())}};function ln(e){if(Yf(e))return new an({multihash:e});if(Xf(e))try{let t=Ia(e);if(t.type==="Ed25519")return new cn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new un({multihash:e,publicKey:t})}catch{let r=J(e.digest);return new fn(new URL(r))}throw new Or("Supplied PeerID Multihash is invalid")}function Xf(e){return e.code===_t.code}function Yf(e){return e.code===or.code}function is(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function hn(e){let t=ue(Y.decode(`z${e}`));return ln(t)}var dn=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return is(this.set.entries(),t=>{let r=hn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=hn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return is(this.set.values(),t=>hn(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function as(){return new dn}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},La=new globalThis.TextEncoder;function Qf(e,t){let r=cs[t],n=Ta[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function Jf(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=cs[t],o=Ta[t],s=e;for(;s.length>0;){let i=La.encodeInto(s,r);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(r[c]),o=BigInt.asUintN(t,o*n)}return o}function us(e,{size:t=32,utf8Buffer:r}={}){if(!cs[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof e=="string"){if(r)return Jf(e,t,r);e=La.encode(e)}return Qf(e,t)}var _r={hash:e=>Number(us(e,{size:32})),hashV:(e,t)=>tl(_r.hash(e,t))};function tl(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),$(t,"base16")}var fs=64,Tt=class{fp;h;seed;constructor(t,r,n,o=2){if(o>fs)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=At(o);for(let c=0;c<i.length;c++)i[c]=s[c];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?lt(this.fp,t.fp):!1}};function be(e,t){return Math.floor(Math.random()*(t-e))+e}var xe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=t,!0;return!0}swap(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let r=be(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=t,n}remove(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var el=500,Ar=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??_r,this.seed=t.seed??be(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=$(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new xe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new xe(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[be(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize));for(let c=0;c<el;c++){let a=this.buckets[i].swap(r);if(a!=null&&(i=(i^a.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new xe(this.bucketSize)),this.buckets[i].add(a)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=$(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(t){typeof t=="string"&&(t=$(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},rl={1:.5,2:.84,4:.95,8:.98};function nl(e=.001){return e>.002?2:e>1e-5?4:8}function Ca(e,t=.001){let r=nl(t),n=rl[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),fs);return{filterSize:o,bucketSize:r,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??_r,this.seed=t.seed??be(0,Math.pow(2,10)),this.filterSeries=[new Ar({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=$(t)),this.has(t))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new Ar({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(t)}has(t){typeof t=="string"&&(t=$(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=$(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,r)=>t+r.count,0)}};function ls(e,t=.001,r){return new pn({...Ca(e,t),...r??{}})}function Lt(e){let t=e.getComponents(),r={},n=0;if(t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n].name==="ip4"||t[n].name==="ip6"||t[n].name==="dns"||t[n].name==="dns4"||t[n].name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n].name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null)throw new ft(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r}var mn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let l=Number.parseInt(f,t);if(!Number.isNaN(l))return l});if(h===void 0)break;if(s*=t,s+=h,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Da=45,ol=15,je=new mn;function gn(e){if(!(e.length>ol))return je.new(e).parseWith(()=>je.readIPv4Addr())}function yn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Da))return je.new(e).parseWith(()=>je.readIPv6Addr())}function Ge(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Da)return;let r=je.new(e).parseWith(()=>je.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function Pa(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Ra(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function hs(e){switch(e.length){case we:return e.join(".");case Ee:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Oa(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function Na(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var we=4,Ee=16,hy=parseInt("0xFFFF",16),sl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ir(e,t){t.length===Ee&&e.length===we&&Pa(t,0,11)&&(t=t.slice(12)),t.length===we&&e.length===Ee&&Ra(e,sl,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function Ua(e,t){if(typeof t=="string"&&(t=Ge(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function ds(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=we,o=gn(t);if(o==null&&(n=Ee,o=yn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+e);let i=ps(s,8*n);return{network:Ir(o,i),mask:i}}function ps(e,t){if(t!==8*we&&t!==8*Ee)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var Br=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=ds(t));else{let n=Ge(t);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Ge(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ps(o,8*n.length);this.network=Ir(n,this.mask)}}contains(t){return Ua({network:this.network,mask:this.mask},t)}toString(){let t=Oa(this.mask),r=t!==-1?String(t):Na(this.mask);return hs(this.network)+"/"+r}};function ka(e,t){return new Br(e).contains(t)}function Ma(e){try{let t=Lt(e);switch(t.type){case"ip6":return ka("2000::/3",t.host);default:return!1}}catch{return!1}}function Ze(e){return!!gn(e)}function bn(e){return!!yn(e)}var Fa=mc(Ka(),1),il=["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"],al=il.map(e=>new Fa.Netmask(e));function ms(e){for(let t of al)if(t.contains(e))return!0;return!1}function cl(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function ul(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return ms(o)}function fl(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function ll(e){let t=e.split(":"),r=t[t.length-1];return ms(r)}function hl(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function za(e){if(Ze(e))return ms(e);if(cl(e))return ul(e);if(fl(e))return ll(e);if(bn(e))return hl(e)}function gs(e){try{let t=Lt(e);switch(t.type){case"ip4":case"ip6":return za(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function We(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var xn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Xe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new xn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new xn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var ys=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function wn(e={}){return dl(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function dl(e,t){t=t??{};let r=t.onEnd,n=new Xe,o,s,i,c=We(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((E,y)=>{s=_=>{s=null,n.push(_);try{E(e(n))}catch(w){y(w)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=We()})}},u=E=>s!=null?s(E):(n.push(E),o),h=E=>(n=new Xe,s!=null?s({error:E}):(n.push({error:E}),o)),f=E=>{if(i)return o;if(t?.objectMode!==!0&&E?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:E})},l=E=>i?o:(i=!0,E!=null?h(E):u({done:!0})),d=()=>(n=new Xe,l(),{done:!0}),p=E=>(l(E),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:d,throw:p,push:f,end:l,get readableLength(){return n.size},onEmpty:async E=>{let y=E?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let _,w;y!=null&&(_=new Promise((T,P)=>{w=()=>{P(new ys)},y.addEventListener("abort",w)}));try{await Promise.race([c.promise,_])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},r==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(E){return x.throw(E),r!=null&&(r(E),r=void 0),{done:!0}},return(){return x.return(),r!=null&&(r(),r=void 0),{done:!0}},push:f,end(E){return x.end(E),r!=null&&(r(E),r=void 0),o},get readableLength(){return x.readableLength},onEmpty:E=>x.onEmpty(E)},o}var bs=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},xs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},qa=e=>globalThis.DOMException===void 0?new xs(e):new DOMException(e),Va=e=>{let t=e.reason===void 0?qa("This operation was aborted."):e.reason;return t instanceof Error?t:qa(t)};function ws(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,u=new Promise((h,f)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:d}=t;d.aborted&&f(Va(d)),c=()=>{f(Va(d))},d.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(h,f);return}let l=new bs;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(d){f(d)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?h():o instanceof Error?f(o):(l.message=o??`Promise timed out after ${r} milliseconds`,f(l))},r),(async()=>{try{h(await e)}catch(d){f(d)}})()}).finally(()=>{u.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var pl=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function ml(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[t].flat(),a=[],{addListener:u,removeListener:h}=pl(e),f=(...d)=>{let p=r.multiArgs?d:d[0];r.filter&&!r.filter(p)||(a.push(p),r.count===a.length&&(n(),s(a)))},l=d=>{n(),i(d)};n=()=>{for(let d of c)h(d,f);for(let d of r.rejectionEvents)h(d,l)};for(let d of c)u(d,f);for(let d of r.rejectionEvents)u(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});if(o.cancel=n,typeof r.timeout=="number"){let s=ws(o,{milliseconds:r.timeout});return s.cancel=n,s}return o}function Ye(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=ml(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Lr(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var En=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Se=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function gl(e){return e.reason}async function Sn(e,t,r){if(t==null)return e;let n=r?.translateError??gl;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var vn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=We(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Dt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function yl(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var _n=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=yl(),this.status="queued",this.fn=t,this.options=r,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((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Dt),this.cleanup())}async join(t={}){let r=new vn(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Sn(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var An=class extends Nr{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=Lr(this.emitEmpty.bind(this),1),this.emitIdle=Lr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new En;let n=new _n(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).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 Dt)}),this.clear()}async onEmpty(t){this.size!==0&&await Ye(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await Ye(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Ye(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=wn({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),r.end(a)},o=a=>{a.detail!=null&&r.push(a.detail)},s=a=>{n(a.detail.error)},i=()=>{n()},c=()=>{n(new Dt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",c);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",c),n()}}};function In(e){let t=new globalThis.AbortController;function r(){t.abort();for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let s of e){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}var st=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Xt=class extends Error{static name="ValidationError";name="ValidationError"},Bn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Tn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Ss(e){return t=>J(t,e)}function vs(e){return t=>$(t,e)}function Qe(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function ve(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Ha(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=$(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=ve(n);return Rt([r,o],r.length+o.length)}function $a(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Jt.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=ve(n);return Rt([r,o],r.length+o.length)}function _s(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=J(t,"base32"),o=Qe(r);return`${n}:${o}`}var As=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new st("Invalid byte value in IP address");t[n]=o}),t},ja=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=Ze(r[n]),i;s&&(i=As(r[n]),r[n]=J(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,J(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new st("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ga=function(e){if(e.byteLength!==4)throw new st("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Za=function(e){if(e.byteLength!==16)throw new st("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${r}"`)}};function Wa(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${e}"`)}}var Es=Object.values(sr).map(e=>e.decoder),bl=(function(){let e=Es[0].or(Es[1]);return Es.slice(2).forEach(t=>e=e.or(t)),e})();function Xa(e){return bl.decode(e)}function Ya(e){return t=>e.encoder.encode(t)}function xl(e){if(parseInt(e).toString()!==e)throw new Xt("Value must be an integer")}function wl(e){if(e<0)throw new Xt("Value must be a positive integer, or zero")}function El(e){return t=>{if(t>e)throw new Xt(`Value must be smaller than or equal to ${e}`)}}function Sl(...e){return t=>{for(let r of e)r(t)}}var Cr=Sl(xl,wl,El(65535));var nt=-1,Is=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Tn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Yt=new Is,ch=[{code:4,name:"ip4",size:32,valueToBytes:As,bytesToValue:Ga,validate:e=>{if(!Ze(e))throw new Xt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ve,bytesToValue:Qe,validate:Cr},{code:273,name:"udp",size:16,valueToBytes:ve,bytesToValue:Qe,validate:Cr},{code:33,name:"dccp",size:16,valueToBytes:ve,bytesToValue:Qe,validate:Cr},{code:41,name:"ip6",size:128,valueToBytes:ja,bytesToValue:Za,stringToValue:Wa,validate:e=>{if(!bn(e))throw new Xt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:nt},{code:43,name:"ipcidr",size:8,bytesToValue:Ss("base10"),valueToBytes:vs("base10")},{code:53,name:"dns",size:nt},{code:54,name:"dns4",size:nt},{code:55,name:"dns6",size:nt},{code:56,name:"dnsaddr",size:nt},{code:132,name:"sctp",size:16,valueToBytes:ve,bytesToValue:Qe,validate:Cr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:nt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:nt,bytesToValue:Ss("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?vs("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:_s,valueToBytes:Ha},{code:445,name:"onion3",size:296,bytesToValue:_s,valueToBytes:$a},{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:Ya(Wn),valueToBytes:Xa},{code:480,name:"http"},{code:481,name:"http-path",size:nt,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:nt}];ch.forEach(e=>{Yt.addProtocol(e)});function Qa(e){let t=[],r=0;for(;r<e.length;){let n=xr(e,r),o=Yt.getProtocol(n),s=yt(n),i=uh(o,e,r+s),c=0;i>0&&o.size===nt&&(c=yt(i));let a=s+c+i,u={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(i>0){let h=r+s+c,f=e.subarray(h,h+i);u.value=o.bytesToValue?.(f)??J(f)}t.push(u),r+=a}return t}function Ja(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Yt.getProtocol(n.code),s=yt(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??$(n.value),c=i.byteLength,o.size===nt&&(a=yt(c)));let u=new Uint8Array(s+a+c),h=0;Fe(n.code,u,h),h+=s,i!=null&&(o.size===nt&&(Fe(c,u,h),h+=a),u.set(i,h)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Rt(r,t)}function tc(e){if(e.charAt(0)!=="/")throw new st('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let c=s===e.length-1;if(i==="/"||c){let a=Yt.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new st(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new st(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new st("Incomplete multiaddr");return t}function ec(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Yt.getProtocol(t.code);if(r==null)throw new st(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function uh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:xr(t,r)}var fh=Symbol.for("nodejs.util.inspect.custom"),Bs=Symbol.for("@multiformats/multiaddr");function lh(e){if(e==null&&(e="/"),rc(e))return e.getComponents();if(e instanceof Uint8Array)return Qa(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),tc(e);if(Array.isArray(e))return e;throw new st("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Cn=class e{[Bs]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=lh(t),r.validate!==!1&&hh(this)}get bytes(){return this.#r==null&&(this.#r=Ja(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=ec(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Bn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return lt(this.bytes,t.bytes)}[fh](){return`Multiaddr(${this.toString()})`}};function hh(e){e.getComponents().forEach(t=>{let r=Yt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function rc(e){return!!e?.[Bs]}function nc(e){return new Cn(e)}var dh=4194304,Dn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ls=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Cs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ds=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ph(e){return typeof e?.closeRead=="function"}function mh(e){return typeof e?.close=="function"}function Ts(e){return ph(e)?e.readStatus==="closing"||e.readStatus==="closed":mh(e)?e.status!=="open":!1}function gh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function yh(e,t){let r=t?.maxBufferSize??dh,n=new tt,o=Promise.withResolvers(),s=!1;if(!gh(e))throw new ft("Argument should be a Stream or a Multiaddr");let i=h=>{if(n.append(h.data),n.byteLength>r){let f=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${f} > ${r}`))}o.resolve()};e.addEventListener("message",i);let c=h=>{h.error!=null?o.reject(h.error):o.resolve()};e.addEventListener("close",c);let a=()=>{o.resolve()};e.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(h){if(s===!0)throw new Dn("Stream was unwrapped");if(Ts(e)){if(h?.bytes==null)return null;if(n.byteLength<h.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,h.bytes),new Se(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let f=h?.bytes??1;for(;;){if(n.byteLength>=f){o.resolve();break}if(await Sn(o.promise,h?.signal),Ts(e)){if(n.byteLength===0&&h?.bytes==null)return null;break}o=Promise.withResolvers()}let l=h?.bytes??n.byteLength;if(n.byteLength<l){if(Ts(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,l),new Se(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return u.read(h)}let d=n.sublist(0,l);return n.consume(l),d},async write(h,f){if(s===!0)throw new Dn("Stream was unwrapped");e.send(h)||await Ye(e,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function bh(e,t={}){let r=yh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=yt(t.maxDataLength));let n=t?.lengthDecoder??xr,o=t?.lengthEncoder??sa;return{async read(i){let c=-1,a=new tt;for(;;){let h=await r.read({...i,bytes:1});if(h==null)break;a.append(h);try{c=n(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(c<0)throw new Ls("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Ds(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new Cs(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:c});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",c),new Se(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new Se(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(i,c){await r.write(new tt(o(i.byteLength),i),c)},async writeV(i,c){let a=new tt(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function Ps(e,t){let r=bh(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var Pn=class extends An{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function oc(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal};if(r?.timeout!=null){let h=In([o.signal,AbortSignal.timeout(r.timeout)]);u.signal=h}s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let c=Lr(i,r?.debounce??100),a=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{s||(clearTimeout(n),c())},start:()=>{a||(a=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),a=!1}}}var Rs=class extends Map{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function sc(e){let{name:t,metrics:r}=e,n;return r!=null?n=new Rs({name:t,metrics:r}):n=new Map,n}var ic="libp2p",ac="autonat",cc="1.0.0";var V;(function(e){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=e.MessageType||(e.MessageType={}));let r;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(r||(r={})),(function(u){u.codec=()=>qe(r)})(t=e.MessageType||(e.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=e.ResponseStatus||(e.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(u){u.codec=()=>qe(o)})(n=e.ResponseStatus||(e.ResponseStatus={}));let s;(function(u){let h;u.codec=()=>(h==null&&(h=Gt((f,l,d={})=>{if(d.lengthDelimited!==!1&&l.fork(),f.id!=null&&(l.uint32(10),l.bytes(f.id)),f.addrs!=null)for(let p of f.addrs)l.uint32(18),l.bytes(p);d.lengthDelimited!==!1&&l.ldelim()},(f,l,d={})=>{let p={addrs:[]},x=l==null?f.len:f.pos+l;for(;f.pos<x;){let E=f.uint32();switch(E>>>3){case 1:{p.id=f.bytes();break}case 2:{if(d.limits?.addrs!=null&&p.addrs.length===d.limits.addrs)throw new rn('Decode error - map field "addrs" had too many elements');p.addrs.push(f.bytes());break}default:{f.skipType(E&7);break}}}return p})),h),u.encode=f=>jt(f,u.codec()),u.decode=(f,l)=>$t(f,u.codec(),l)})(s=e.PeerInfo||(e.PeerInfo={}));let i;(function(u){let h;u.codec=()=>(h==null&&(h=Gt((f,l,d={})=>{d.lengthDelimited!==!1&&l.fork(),f.peer!=null&&(l.uint32(10),e.PeerInfo.codec().encode(f.peer,l)),d.lengthDelimited!==!1&&l.ldelim()},(f,l,d={})=>{let p={},x=l==null?f.len:f.pos+l;for(;f.pos<x;){let E=f.uint32();switch(E>>>3){case 1:{p.peer=e.PeerInfo.codec().decode(f,f.uint32(),{limits:d.limits?.peer});break}default:{f.skipType(E&7);break}}}return p})),h),u.encode=f=>jt(f,u.codec()),u.decode=(f,l)=>$t(f,u.codec(),l)})(i=e.Dial||(e.Dial={}));let c;(function(u){let h;u.codec=()=>(h==null&&(h=Gt((f,l,d={})=>{d.lengthDelimited!==!1&&l.fork(),f.status!=null&&(l.uint32(8),e.ResponseStatus.codec().encode(f.status,l)),f.statusText!=null&&(l.uint32(18),l.string(f.statusText)),f.addr!=null&&(l.uint32(26),l.bytes(f.addr)),d.lengthDelimited!==!1&&l.ldelim()},(f,l,d={})=>{let p={},x=l==null?f.len:f.pos+l;for(;f.pos<x;){let E=f.uint32();switch(E>>>3){case 1:{p.status=e.ResponseStatus.codec().decode(f);break}case 2:{p.statusText=f.string();break}case 3:{p.addr=f.bytes();break}default:{f.skipType(E&7);break}}}return p})),h),u.encode=f=>jt(f,u.codec()),u.decode=(f,l)=>$t(f,u.codec(),l)})(c=e.DialResponse||(e.DialResponse={}));let a;e.codec=()=>(a==null&&(a=Gt((u,h,f={})=>{f.lengthDelimited!==!1&&h.fork(),u.type!=null&&(h.uint32(8),e.MessageType.codec().encode(u.type,h)),u.dial!=null&&(h.uint32(18),e.Dial.codec().encode(u.dial,h)),u.dialResponse!=null&&(h.uint32(26),e.DialResponse.codec().encode(u.dialResponse,h)),f.lengthDelimited!==!1&&h.ldelim()},(u,h,f={})=>{let l={},d=h==null?u.len:u.pos+h;for(;u.pos<d;){let p=u.uint32();switch(p>>>3){case 1:{l.type=e.MessageType.codec().decode(u);break}case 2:{l.dial=e.Dial.codec().decode(u,u.uint32(),{limits:f.limits?.dial});break}case 3:{l.dialResponse=e.DialResponse.codec().decode(u,u.uint32(),{limits:f.limits?.dialResponse});break}default:{u.skipType(p&7);break}}}return l})),a),e.encode=u=>jt(u,e.codec()),e.decode=(u,h)=>$t(u,e.codec(),h)})(V||(V={}));var _h=4,Ah=8,Rn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${r.protocolPrefix??ic}/${ac}/${cc}`,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.connectionThreshold=r.connectionThreshold??80,this.maxMessageSize=r.maxMessageSize??8192,this.dialResults=sc({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=oc(this.findRandomPeers.bind(this),6e4),this.addressFilter=ls(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ks]=["@libp2p/autonat"];get[Ms](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,r)=>{this.handleIncomingAutonatStream(t,r).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,r)=>{this.verifyExternalAddresses(r).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let r=In([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:r})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:r})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,r){let n=AbortSignal.timeout(this.timeout);try{let o=Ps(t,{maxDataLength:this.maxMessageSize}).pb(V),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,r,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,r,n){let o=this.components.addressManager.getAddresses().map(f=>Lt(f).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,c=s.peer;if(c?.id==null)return this.log.error("PeerId missing from message"),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=ue(c.id);i=ln(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!r.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,r.remotePeer),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let a=c.addrs.map(f=>nc(f)).filter(f=>{try{let l=Lt(f);return gs(f)?!1:l.host!==Lt(r.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",f,r.remoteAddr),!1):o.includes(l.host)?!1:this.components.transportManager.dialTransportForMultiaddr(f)==null?(this.log.trace("not dialing %a - transport unsupported",f),!1):!0}catch{return!1}}).map(f=>(f.getComponents().find(l=>l.code===421)?.value==null&&(f=f.encapsulate(`/p2p/${i.toString()}`)),f));if(a.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",a.map(f=>f.toString()).join(", "),i);let u="",h=a[0];for(let f of a){let l;h=f;try{if(l=await this.components.connectionManager.openConnection(f,n),!l.remoteAddr.equals(f))throw this.log.error("tried to dial %a but dialed %a",f,l.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,f),{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.OK,addr:l.remoteAddr.decapsulateCode(421).bytes}}}catch(d){this.log.error("could not dial %p - %e",i,d),u=d.message}finally{l!=null&&await l.close()}}return{type:V.MessageType.DIAL_RESPONSE,dialResponse:{status:V.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:h.bytes}}}getFirstUnverifiedMultiaddr(t,r){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||Lt(o.multiaddr).type==="ip6"&&(!r||!Ma(o.multiaddr))||gs(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let c=o.expires<Date.now();if(c&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:as(),queue:new Pn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>Lt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,r,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let c=Ps(i).pb(V),[,a]=await Promise.all([c.write({type:V.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),c.read({signal:s})]);if(a.type!==V.MessageType.DIAL_RESPONSE||a.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,a);return}let u=a.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==V.ResponseStatus.OK&&u!==V.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,a.dialResponse.status);return}if(o.networkSegments.includes(r)){this.log.trace("%a results included network segment %s",n.multiaddr,r);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(r),u===V.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===V.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===_h&&this.confirmAddress(o),o.failure===Ah&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(c){i.abort(c)}}}hasConnectionCapacity(){let r=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return r/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let r=Lt(t);switch(r.type){case"ip4":return r.host.split(".")[0].padStart(3,"0");case"ip6":return r.host.split(":")[0].padStart(4,"0");default:throw new ft(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function Ih(e={}){return t=>new Rn(t,e)}return gc(Bh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: