@libp2p/autonat 2.0.34-6c42ea64a → 2.0.34-ae595d8db
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +9 -9
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PAutonat=(()=>{var Xa=Object.create;var _r=Object.defineProperty;var Qa=Object.getOwnPropertyDescriptor;var Ja=Object.getOwnPropertyNames;var tc=Object.getPrototypeOf,ec=Object.prototype.hasOwnProperty;var rc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)_r(r,e,{get:t[e],enumerable:!0})},ws=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ja(t))!ec.call(r,o)&&o!==e&&_r(r,o,{get:()=>t[o],enumerable:!(n=Qa(t,o))||n.enumerable});return r};var nc=(r,t,e)=>(e=r!=null?Xa(tc(r)):{},ws(t||!r||!r.__esModule?_r(e,"default",{value:r,enumerable:!0}):e,r)),oc=r=>ws(_r({},"__esModule",{value:!0}),r);var Ma=rc(Er=>{(function(){var r,t,e,n,o,s,i,a;a=function(u){var c,l,f,h;return c=(u&255<<24)>>>24,l=(u&255<<16)>>>16,f=(u&65280)>>>8,h=u&255,[c,l,f,h].join(".")},i=function(u){var c,l,f,h,m,b;for(c=[],f=h=0;h<=3&&u.length!==0;f=++h){if(f>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}b=t(u),m=b[0],l=b[1],u=u.substring(l),c.push(m)}if(u.length!==0)throw new Error("Invalid IP");switch(c.length){case 1:if(c[0]>4294967295)throw new Error("Invalid IP");return c[0]>>>0;case 2:if(c[0]>255||c[1]>16777215)throw new Error("Invalid IP");return(c[0]<<24|c[1])>>>0;case 3:if(c[0]>255||c[1]>255||c[2]>65535)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2])>>>0;case 4:if(c[0]>255||c[1]>255||c[2]>255||c[3]>255)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2]<<8|c[3])>>>0;default:throw new Error("Invalid IP")}},e=function(u){return u.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(u){var c,l,f,h,m;for(h=0,c=10,l="9",f=0,u.length>1&&u[f]==="0"&&(u[f+1]==="x"||u[f+1]==="X"?(f+=2,c=16):"0"<=u[f+1]&&u[f+1]<="9"&&(f++,c=8,l="7")),m=f;f<u.length;){if("0"<=u[f]&&u[f]<=l)h=h*c+(e(u[f])-n)>>>0;else if(c===16)if("a"<=u[f]&&u[f]<="f")h=h*c+(10+e(u[f])-s)>>>0;else if("A"<=u[f]&&u[f]<="F")h=h*c+(10+e(u[f])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===m)throw new Error("empty octet");return[h,f]},r=function(){function u(c,l){var f,h,m,b;if(typeof c!="string")throw new Error("Missing `net' parameter");if(l||(b=c.split("/",2),c=b[0],l=b[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(w){throw f=w,new Error("Invalid mask: "+l)}for(h=m=32;m>=0;h=--m)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(l||l===0)this.bitmask=parseInt(l,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(c)&this.maskLong)>>>0}catch(w){throw f=w,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return u.prototype.contains=function(c){return typeof c=="string"&&(c.indexOf("/")>0||c.split(".").length!==4)&&(c=new u(c)),c instanceof u?this.contains(c.base)&&this.contains(c.broadcast||c.last):(i(c)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},u.prototype.next=function(c){return c==null&&(c=1),new u(a(this.netLong+this.size*c),this.mask)},u.prototype.forEach=function(c){var l,f,h;for(h=i(this.first),f=i(this.last),l=0;h<=f;)c(a(h),h,l),l++,h++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u}(),Er.ip2long=i,Er.long2ip=a,Er.Netmask=r}).call(Er)});var jl={};dt(jl,{autoNAT:()=>Vl});var Dn=Symbol.for("@libp2p/peer-id");var Bt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Ct=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Sr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var vr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var He=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ar=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Es=Symbol.for("@libp2p/service-capabilities"),_s=Symbol.for("@libp2p/service-dependencies");var Nn={};dt(Nn,{base58btc:()=>V,base58flickr:()=>lc});var yh=new Uint8Array(0);function Ss(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Tt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function vs(r){return new TextEncoder().encode(r)}function As(r){return new TextDecoder().decode(r)}function sc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,u=r.charAt(0),c=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var w=0,d=0,S=0,C=b.length;S!==C&&b[S]===0;)S++,w++;for(var v=(C-S)*l+1>>>0,P=new Uint8Array(v);S!==C;){for(var y=b[S],L=0,D=v-1;(y!==0||L<d)&&D!==-1;D--,L++)y+=256*P[D]>>>0,P[D]=y%a>>>0,y=y/a>>>0;if(y!==0)throw new Error("Non-zero carry");d=L,S++}for(var I=v-d;I!==v&&P[I]===0;)I++;for(var p=u.repeat(w);I<v;++I)p+=r.charAt(P[I]);return p}function h(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var w=0;if(b[w]!==" "){for(var d=0,S=0;b[w]===u;)d++,w++;for(var C=(b.length-w)*c+1>>>0,v=new Uint8Array(C);b[w];){var P=e[b.charCodeAt(w)];if(P===255)return;for(var y=0,L=C-1;(P!==0||y<S)&&L!==-1;L--,y++)P+=a*v[L]>>>0,v[L]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");S=y,w++}if(b[w]!==" "){for(var D=C-S;D!==C&&v[D]===0;)D++;for(var I=new Uint8Array(d+(C-D)),p=d;D!==C;)I[p++]=v[D++];return I}}}function m(b){var w=h(b);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:m}}var ic=sc,ac=ic,Bs=ac;var Ln=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Pn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Cs(this,t)}},Rn=class{decoders;constructor(t){this.decoders=t}or(t){return Cs(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Cs(r,t){return new Rn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var On=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ln(t,e,n),this.decoder=new Pn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ge({name:r,prefix:t,encode:e,decode:n}){return new On(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Bs(e,r);return ge({prefix:t,name:r,encode:n,decode:s=>Tt(o(s))})}function cc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,u=0;for(let c=0;c<o;++c){let l=t[r[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[u++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function uc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function fc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function G({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=fc(n);return ge({prefix:t,name:r,encode(s){return uc(s,n,e)},decode(s){return cc(s,o,e,r)}})}var V=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lc=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kn={};dt(kn,{base32:()=>qt,base32hex:()=>mc,base32hexpad:()=>yc,base32hexpadupper:()=>bc,base32hexupper:()=>gc,base32pad:()=>dc,base32padupper:()=>pc,base32upper:()=>hc,base32z:()=>xc});var qt=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hc=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),dc=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),pc=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mc=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gc=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yc=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),bc=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xc=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Un={};dt(Un,{base36:()=>Ve,base36upper:()=>wc});var Ve=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),wc=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ec=Ls,Ts=128,_c=127,Sc=~_c,vc=Math.pow(2,31);function Ls(r,t,e){t=t||[],e=e||0;for(var n=e;r>=vc;)t[e++]=r&255|Ts,r/=128;for(;r⪼)t[e++]=r&255|Ts,r>>>=7;return t[e]=r|0,Ls.bytes=e-n+1,t}var Ac=Mn,Ic=128,Ds=127;function Mn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Mn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ds)<<o:(i&Ds)*Math.pow(2,o),o+=7}while(i>=Ic);return Mn.bytes=s-n,e}var Bc=Math.pow(2,7),Cc=Math.pow(2,14),Tc=Math.pow(2,21),Dc=Math.pow(2,28),Lc=Math.pow(2,35),Pc=Math.pow(2,42),Rc=Math.pow(2,49),Oc=Math.pow(2,56),Nc=Math.pow(2,63),kc=function(r){return r<Bc?1:r<Cc?2:r<Tc?3:r<Dc?4:r<Lc?5:r<Pc?6:r<Rc?7:r<Oc?8:r<Nc?9:10},Uc={encode:Ec,decode:Ac,encodingLength:kc},Mc=Uc,je=Mc;function Ge(r,t=0){return[je.decode(r,t),je.decode.bytes]}function ye(r,t,e=0){return je.encode(r,t,e),t}function be(r){return je.encodingLength(r)}function Xt(r,t){let e=t.byteLength,n=be(r),o=n+be(e),s=new Uint8Array(o+e);return ye(r,s,0),ye(e,s,n),s.set(t,o),new xe(r,e,t,s)}function Qt(r){let t=Tt(r),[e,n]=Ge(t),[o,s]=Ge(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new xe(e,o,i,t)}function Ps(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ss(r.bytes,e.bytes)}}var xe=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Rs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Kc(e,Fn(r),t??V.encoder);default:return zc(e,Fn(r),t??qt.encoder)}}var Os=new WeakMap;function Fn(r){let t=Os.get(r);if(t==null){let e=new Map;return Os.set(r,e),e}return t}var X=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==$e)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==qc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Xt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ps(t.multihash,n.multihash)}toString(t){return Rs(this,t)}toJSON(){return{"/":Rs(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Ns(n,o,s.bytes))}else if(e[Hc]===!0){let{version:n,multihash:o,code:s}=e,i=Qt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==$e)throw new Error(`Version 0 CID must use dag-pb (code: ${$e}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ns(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,$e,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Tt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new xe(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,h]=Ge(t.subarray(e));return e+=h,f},o=n(),s=$e;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),u=n(),c=e+u,l=c-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:l,size:c}}static parse(t,e){let[n,o]=Fc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Fn(s).set(n,t),s}};function Fc(r,t){switch(r[0]){case"Q":{let e=t??V;return[V.prefix,e.decode(`${V.prefix}${r}`)]}case V.prefix:{let e=t??V;return[V.prefix,e.decode(r)]}case qt.prefix:{let e=t??qt;return[qt.prefix,e.decode(r)]}case Ve.prefix:{let e=t??Ve;return[Ve.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Kc(r,t,e){let{prefix:n}=e;if(n!==V.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function zc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var $e=112,qc=18;function Ns(r,t,e){let n=be(r),o=n+be(t),s=new Uint8Array(o+e.byteLength);return ye(r,s,0),ye(t,s,n),s.set(e,o),s}var Hc=Symbol.for("@ipld/js-cid/CID");var Kn={};dt(Kn,{identity:()=>yt});var ks=0,Vc="identity",Us=Tt;function jc(r){return Xt(ks,Us(r))}var yt={code:ks,name:Vc,encode:Us,digest:jc};function at(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function bt(r=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function Dt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Fs=Symbol.for("@achingbrain/uint8arraylist");function Ms(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Br(r){return!!r?.[Fs]}var W=class r{bufs;length;[Fs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Br(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Br(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ms(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ms(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Br(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Dt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Dt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,u=a+i.byteLength;if(o=u,t>=u)continue;let c=t>=a&&t<u,l=e>a&&e<=u;if(c&&l){if(t===a&&e===u){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===u){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Br(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,u=this.byteLength-n.byteLength,c=n.byteLength-1,l;for(let f=e;f<=u;f+=l){l=0;for(let h=c;h>=0;h--){let m=this.get(f+h);if(n[h]!==m){l=Math.max(1,h-a[m]);break}}if(l===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=bt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=bt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=bt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=bt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=bt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=bt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=bt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=bt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!at(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var zn={};dt(zn,{base10:()=>Gc});var Gc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var qn={};dt(qn,{base16:()=>$c,base16upper:()=>Zc});var $c=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Zc=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Hn={};dt(Hn,{base2:()=>Wc});var Wc=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vn={};dt(Vn,{base256emoji:()=>tu});var Ks=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}"),Yc=Ks.reduce((r,t,e)=>(r[e]=t,r),[]),Xc=Ks.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Qc(r){return r.reduce((t,e)=>(t+=Yc[e],t),"")}function Jc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Xc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var tu=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Qc,decode:Jc});var Gn={};dt(Gn,{base64:()=>eu,base64pad:()=>ru,base64url:()=>jn,base64urlpad:()=>nu});var eu=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ru=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),jn=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nu=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $n={};dt($n,{base8:()=>ou});var ou=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Zn={};dt(Zn,{identity:()=>su});var su=ge({prefix:"\0",name:"identity",encode:r=>As(r),decode:r=>vs(r)});var td=new TextEncoder,ed=new TextDecoder;var Xn={};dt(Xn,{sha256:()=>Ze,sha512:()=>cu});function Yn({name:r,code:t,encode:e}){return new Wn(r,t,e)}var Wn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Xt(this.code,e):e.then(n=>Xt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function qs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ze=Yn({name:"sha2-256",code:18,encode:qs("SHA-256")}),cu=Yn({name:"sha2-512",code:19,encode:qs("SHA-512")});var We={...Zn,...Hn,...$n,...zn,...qn,...kn,...Un,...Nn,...Gn,...Vn},dd={...Xn,...Kn};function Vs(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Hs=Vs("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Qn=Vs("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),uu={utf8:Hs,"utf-8":Hs,hex:We.base16,latin1:Qn,ascii:Qn,binary:Qn,...We},Cr=uu;function M(r,t="utf8"){let e=Cr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function z(r,t="utf8"){let e=Cr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var fu=parseInt("11111",2),Jn=parseInt("10000000",2),lu=parseInt("01111111",2),js={0:Ye,1:Ye,2:hu,3:mu,4:gu,5:pu,6:du,16:Ye,22:Ye,48:Ye};function to(r,t={offset:0}){let e=r[t.offset]&fu;if(t.offset++,js[e]!=null)return js[e](r,t);throw new Error("No decoder for tag "+e)}function Xe(r,t){let e=0;if((r[t.offset]&Jn)===Jn){let n=r[t.offset]&lu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Ye(r,t){Xe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=to(r,t);if(n===null)break;e.push(n)}return e}function hu(r,t){let e=Xe(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function du(r,t){let e=Xe(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,u=[];for(;t.offset<n;){let c=r[t.offset];if(t.offset++,u.push(c&127),c<128){u.reverse();let l=0;for(let f=0;f<u.length;f++)l+=u[f]<<f*7;a+=`.${l}`,u=[]}}return a}function pu(r,t){return t.offset++,null}function mu(r,t){let e=Xe(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function gu(r,t){let e=Xe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function yu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new W;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function eo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=yu(r.byteLength);return new W(Uint8Array.from([t.byteLength|Jn]),t)}function Gs(r){let t=new W,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new W(Uint8Array.from([2]),eo(t),t)}function $s(r){let t=Uint8Array.from([0]),e=new W(t,r);return new W(Uint8Array.from([3]),eo(e),e)}function Tr(r,t=48){let e=new W;for(let n of r)e.append(n);return new W(Uint8Array.from([t]),eo(e),e)}async function Zs(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var bu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),xu=Uint8Array.from([6,5,43,129,4,0,34]),wu=Uint8Array.from([6,5,43,129,4,0,35]),Eu={ext:!0,kty:"EC",crv:"P-256"},_u={ext:!0,kty:"EC",crv:"P-384"},Su={ext:!0,kty:"EC",crv:"P-521"},ro=32,no=48,oo=66;function Ws(r){let t=to(r);return Ys(t)}function Ys(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===ro*2+1)return n=z(t.subarray(e,e+ro),"base64url"),o=z(t.subarray(e+ro),"base64url"),new we({...Eu,key_ops:["verify"],x:n,y:o});if(t.byteLength===no*2+1)return n=z(t.subarray(e,e+no),"base64url"),o=z(t.subarray(e+no),"base64url"),new we({..._u,key_ops:["verify"],x:n,y:o});if(t.byteLength===oo*2+1)return n=z(t.subarray(e,e+oo),"base64url"),o=z(t.subarray(e+oo),"base64url"),new we({...Su,key_ops:["verify"],x:n,y:o});throw new Ct(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Xs(r){return Tr([Gs(Uint8Array.from([1])),Tr([vu(r.crv)],160),Tr([$s(new W(Uint8Array.from([4]),M(r.x??"","base64url"),M(r.y??"","base64url")))],161)]).subarray()}function vu(r){if(r==="P-256")return bu;if(r==="P-384")return xu;if(r==="P-521")return wu;throw new Ct(`Invalid curve ${r}`)}var we=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Xs(this.jwk)),this._raw}toMultihash(){return yt.digest(Ee(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return V.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async verify(t,e,n){return Zs(this.jwk,e,t,n)}};var Jt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Se(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Qe(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function nt(r,...t){if(!Se(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Js(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Qe(r.outputLen),Qe(r.blockLen)}function ve(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function ti(r,t){nt(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Pt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Dr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function xt(r,t){return r<<32-t|r>>>t}var ei=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Au=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function vt(r){if(nt(r),ei)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Au[r[e]];return t}var Lt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Qs(r){if(r>=Lt._0&&r<=Lt._9)return r-Lt._0;if(r>=Lt.A&&r<=Lt.F)return r-(Lt.A-10);if(r>=Lt.a&&r<=Lt.f)return r-(Lt.a-10)}function Ae(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ei)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Qs(r.charCodeAt(s)),a=Qs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let u=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+s)}n[o]=i*16+a}return n}function ri(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Je(r){return typeof r=="string"&&(r=ri(r)),nt(r),r}function pt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];nt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var _e=class{};function so(r){let t=n=>r().update(Je(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function tr(r=32){if(Jt&&typeof Jt.getRandomValues=="function")return Jt.getRandomValues(new Uint8Array(r));if(Jt&&typeof Jt.randomBytes=="function")return Uint8Array.from(Jt.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Iu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),u=n?4:0,c=n?0:4;r.setUint32(t+u,i,n),r.setUint32(t+c,a,n)}function ni(r,t,e){return r&t^~r&e}function oi(r,t,e){return r&t^r&e^t&e}var er=class extends _e{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Dr(this.buffer)}update(t){ve(this),t=Je(t),nt(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let u=Dr(t);for(;o<=s-i;i+=o)this.process(u,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ve(this),ti(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Pt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;Iu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Dr(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let c=u/4,l=this.get();if(c>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<c;f++)a.setUint32(4*f,l[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Rt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Lr=BigInt(4294967295),si=BigInt(32);function Bu(r,t=!1){return t?{h:Number(r&Lr),l:Number(r>>si&Lr)}:{h:Number(r>>si&Lr)|0,l:Number(r&Lr)|0}}function ii(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Bu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var io=(r,t,e)=>r>>>e,ao=(r,t,e)=>r<<32-e|t>>>e,te=(r,t,e)=>r>>>e|t<<32-e,ee=(r,t,e)=>r<<32-e|t>>>e,rr=(r,t,e)=>r<<64-e|t>>>e-32,nr=(r,t,e)=>r>>>e-32|t<<64-e;function At(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var ai=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ci=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ui=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),fi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,li=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),hi=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Tu=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]),Vt=new Uint32Array(64),co=class extends er{constructor(t=32){super(64,t,8,!1),this.A=Rt[0]|0,this.B=Rt[1]|0,this.C=Rt[2]|0,this.D=Rt[3]|0,this.E=Rt[4]|0,this.F=Rt[5]|0,this.G=Rt[6]|0,this.H=Rt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:u}=this;return[t,e,n,o,s,i,a,u]}set(t,e,n,o,s,i,a,u){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=u|0}process(t,e){for(let f=0;f<16;f++,e+=4)Vt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Vt[f-15],m=Vt[f-2],b=xt(h,7)^xt(h,18)^h>>>3,w=xt(m,17)^xt(m,19)^m>>>10;Vt[f]=w+Vt[f-7]+b+Vt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:u,G:c,H:l}=this;for(let f=0;f<64;f++){let h=xt(a,6)^xt(a,11)^xt(a,25),m=l+h+ni(a,u,c)+Tu[f]+Vt[f]|0,w=(xt(n,2)^xt(n,13)^xt(n,22))+oi(n,o,s)|0;l=c,c=u,u=a,a=i+m|0,i=s,s=o,o=n,n=m+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,u=u+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,u,c,l)}roundClean(){Pt(Vt)}destroy(){this.set(0,0,0,0,0,0,0,0),Pt(this.buffer)}};var di=ii(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Du=di[0],Lu=di[1],jt=new Uint32Array(80),Gt=new Uint32Array(80),uo=class extends er{constructor(t=64){super(128,t,16,!1),this.Ah=J[0]|0,this.Al=J[1]|0,this.Bh=J[2]|0,this.Bl=J[3]|0,this.Ch=J[4]|0,this.Cl=J[5]|0,this.Dh=J[6]|0,this.Dl=J[7]|0,this.Eh=J[8]|0,this.El=J[9]|0,this.Fh=J[10]|0,this.Fl=J[11]|0,this.Gh=J[12]|0,this.Gl=J[13]|0,this.Hh=J[14]|0,this.Hl=J[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:u,Eh:c,El:l,Fh:f,Fl:h,Gh:m,Gl:b,Hh:w,Hl:d}=this;return[t,e,n,o,s,i,a,u,c,l,f,h,m,b,w,d]}set(t,e,n,o,s,i,a,u,c,l,f,h,m,b,w,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=u|0,this.Eh=c|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=m|0,this.Gl=b|0,this.Hh=w|0,this.Hl=d|0}process(t,e){for(let v=0;v<16;v++,e+=4)jt[v]=t.getUint32(e),Gt[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let P=jt[v-15]|0,y=Gt[v-15]|0,L=te(P,y,1)^te(P,y,8)^io(P,y,7),D=ee(P,y,1)^ee(P,y,8)^ao(P,y,7),I=jt[v-2]|0,p=Gt[v-2]|0,E=te(I,p,19)^rr(I,p,61)^io(I,p,6),g=ee(I,p,19)^nr(I,p,61)^ao(I,p,6),x=ui(D,g,Gt[v-7],Gt[v-16]),_=fi(x,L,E,jt[v-7],jt[v-16]);jt[v]=_|0,Gt[v]=x|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:u,Dh:c,Dl:l,Eh:f,El:h,Fh:m,Fl:b,Gh:w,Gl:d,Hh:S,Hl:C}=this;for(let v=0;v<80;v++){let P=te(f,h,14)^te(f,h,18)^rr(f,h,41),y=ee(f,h,14)^ee(f,h,18)^nr(f,h,41),L=f&m^~f&w,D=h&b^~h&d,I=li(C,y,D,Lu[v],Gt[v]),p=hi(I,S,P,L,Du[v],jt[v]),E=I|0,g=te(n,o,28)^rr(n,o,34)^rr(n,o,39),x=ee(n,o,28)^nr(n,o,34)^nr(n,o,39),_=n&s^n&a^s&a,B=o&i^o&u^i&u;S=w|0,C=d|0,w=m|0,d=b|0,m=f|0,b=h|0,{h:f,l:h}=At(c|0,l|0,p|0,E|0),c=a|0,l=u|0,a=s|0,u=i|0,s=n|0,i=o|0;let A=ai(E,x,B);n=ci(A,p,g,_),o=A|0}({h:n,l:o}=At(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=At(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:u}=At(this.Ch|0,this.Cl|0,a|0,u|0),{h:c,l}=At(this.Dh|0,this.Dl|0,c|0,l|0),{h:f,l:h}=At(this.Eh|0,this.El|0,f|0,h|0),{h:m,l:b}=At(this.Fh|0,this.Fl|0,m|0,b|0),{h:w,l:d}=At(this.Gh|0,this.Gl|0,w|0,d|0),{h:S,l:C}=At(this.Hh|0,this.Hl|0,S|0,C|0),this.set(n,o,s,i,a,u,c,l,f,h,m,b,w,d,S,C)}roundClean(){Pt(jt,Gt)}destroy(){Pt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var pi=so(()=>new co);var mi=so(()=>new uo);var ho=BigInt(0),lo=BigInt(1);function Ot(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function or(r){let t=r.toString(16);return t.length&1?"0"+t:t}function gi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?ho:BigInt("0x"+r)}function Ie(r){return gi(vt(r))}function re(r){return nt(r),gi(vt(Uint8Array.from(r).reverse()))}function Pr(r,t){return Ae(r.toString(16).padStart(t*2,"0"))}function Be(r,t){return Pr(r,t).reverse()}function q(r,t,e){let n;if(typeof t=="string")try{n=Ae(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Se(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}var fo=r=>typeof r=="bigint"&&ho<=r;function yi(r,t,e){return fo(r)&&fo(t)&&fo(e)&&t<=r&&r<e}function $t(r,t,e,n){if(!yi(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function bi(r){let t;for(t=0;r>ho;r>>=lo,t+=1);return t}var ne=r=>(lo<<BigInt(r))-lo;function xi(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=m=>new Uint8Array(m),o=m=>Uint8Array.of(m),s=n(r),i=n(r),a=0,u=()=>{s.fill(1),i.fill(0),a=0},c=(...m)=>e(i,s,...m),l=(m=n(0))=>{i=c(o(0),m),s=c(),m.length!==0&&(i=c(o(1),m),s=c())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let m=0,b=[];for(;m<t;){s=c();let w=s.slice();b.push(w),m+=s.length}return pt(...b)};return(m,b)=>{u(),l(m);let w;for(;!(w=b(f()));)l();return u(),w}}function Zt(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let u=typeof a;if(u!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${u}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function Ce(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var ct=BigInt(0),Q=BigInt(1),oe=BigInt(2),Pu=BigInt(3),_i=BigInt(4),Si=BigInt(5),vi=BigInt(8);function j(r,t){let e=r%t;return e>=ct?e:t+e}function H(r,t,e){let n=r;for(;t-- >ct;)n*=n,n%=e;return n}function wi(r,t){if(r===ct)throw new Error("invert: expected non-zero number");if(t<=ct)throw new Error("invert: expected positive modulus, got "+t);let e=j(r,t),n=t,o=ct,s=Q,i=Q,a=ct;for(;e!==ct;){let c=n/e,l=n%e,f=o-i*c,h=s-a*c;n=e,e=l,o=i,s=a,i=f,a=h}if(n!==Q)throw new Error("invert: does not exist");return j(o,t)}function Ai(r,t){let e=(r.ORDER+Q)/_i,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function Ru(r,t){let e=(r.ORDER-Si)/vi,n=r.mul(t,oe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,oe),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function Ou(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-Q,e=0;for(;t%oe===ct;)t/=oe,e++;let n=oe,o=wt(r);for(;Ei(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ai;let s=o.pow(n,t),i=(t+Q)/oe;return function(u,c){if(u.is0(c))return c;if(Ei(u,c)!==1)throw new Error("Cannot find square root");let l=e,f=u.mul(u.ONE,s),h=u.pow(c,t),m=u.pow(c,i);for(;!u.eql(h,u.ONE);){if(u.is0(h))return u.ZERO;let b=1,w=u.sqr(h);for(;!u.eql(w,u.ONE);)if(b++,w=u.sqr(w),b===l)throw new Error("Cannot find square root");let d=Q<<BigInt(l-b-1),S=u.pow(f,d);l=b,f=u.sqr(S),h=u.mul(h,f),m=u.mul(m,S)}return m}}function Nu(r){return r%_i===Pu?Ai:r%vi===Si?Ru:Ou(r)}var Ii=(r,t)=>(j(r,t)&Q)===Q,ku=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function po(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=ku.reduce((n,o)=>(n[o]="function",n),t);return Zt(r,e),r}function Uu(r,t,e){if(e<ct)throw new Error("invalid exponent, negatives unsupported");if(e===ct)return r.ONE;if(e===Q)return t;let n=r.ONE,o=t;for(;e>ct;)e&Q&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Q;return n}function sr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,u)=>r.is0(a)?i:(n[u]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,u)=>r.is0(a)?i:(n[u]=r.mul(i,n[u]),r.mul(i,a)),s),n}function Ei(r,t){let e=(r.ORDER-Q)/oe,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Bi(r,t){t!==void 0&&Qe(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function wt(r,t,e=!1,n={}){if(r<=ct)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(o=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(e=l.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Bi(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u,c=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ne(i),ZERO:ct,ONE:Q,create:l=>j(l,r),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return ct<=l&&l<r},is0:l=>l===ct,isValidNot0:l=>!c.is0(l)&&c.isValid(l),isOdd:l=>(l&Q)===Q,neg:l=>j(-l,r),eql:(l,f)=>l===f,sqr:l=>j(l*l,r),add:(l,f)=>j(l+f,r),sub:(l,f)=>j(l-f,r),mul:(l,f)=>j(l*f,r),pow:(l,f)=>Uu(c,l,f),div:(l,f)=>j(l*wi(f,r),r),sqrN:l=>l*l,addN:(l,f)=>l+f,subN:(l,f)=>l-f,mulN:(l,f)=>l*f,inv:l=>wi(l,r),sqrt:s||(l=>(u||(u=Nu(r)),u(c,l))),toBytes:l=>e?Be(l,a):Pr(l,a),fromBytes:l=>{if(l.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);return e?re(l):Ie(l)},invertBatch:l=>sr(c,l),cmov:(l,f,h)=>h?f:l});return Object.freeze(c)}function Ci(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function mo(r){let t=Ci(r);return t+Math.ceil(t/2)}function Ti(r,t,e=!1){let n=r.length,o=Ci(t),s=mo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?re(r):Ie(r),a=j(i,t-Q)+Q;return e?Be(a,o):Pr(a,o)}var De=BigInt(0),se=BigInt(1);function Te(r,t){let e=t.negate();return r?e:t}function Rr(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=sr(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}function Ri(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function go(r,t){Ri(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ne(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Di(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),u=r>>i;a>n&&(a-=s,u+=se);let c=t*n,l=c+Math.abs(a)-1,f=a===0,h=a<0,m=t%2!==0;return{nextN:u,offset:l,isZero:f,isNeg:h,isNegF:m,offsetF:c}}function Mu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Fu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var yo=new WeakMap,Oi=new WeakMap;function bo(r){return Oi.get(r)||1}function Li(r){if(r!==De)throw new Error("invalid wNAF")}function Or(r,t){return{constTimeNegate:Te,hasPrecomputes(e){return bo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>De;)n&se&&(o=o.add(s)),s=s.double(),n>>=se;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=go(n,t),i=[],a=e,u=a;for(let c=0;c<o;c++){u=a,i.push(u);for(let l=1;l<s;l++)u=u.add(a),i.push(u);a=u.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=go(e,t);for(let u=0;u<a.windows;u++){let{nextN:c,offset:l,isZero:f,isNeg:h,isNegF:m,offsetF:b}=Di(o,u,a);o=c,f?i=i.add(Te(m,n[b])):s=s.add(Te(h,n[l]))}return Li(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=go(e,t);for(let a=0;a<i.windows&&o!==De;a++){let{nextN:u,offset:c,isZero:l,isNeg:f}=Di(o,a,i);if(o=u,!l){let h=n[c];s=s.add(f?h.negate():h)}}return Li(o),s},getPrecomputes(e,n,o){let s=yo.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),yo.set(n,s))),s},wNAFCached(e,n,o){let s=bo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=bo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Ri(n,t),Oi.set(e,n),yo.delete(e)}}}function Ni(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>De||n>De;)e&se&&(s=s.add(o)),n&se&&(i=i.add(o)),o=o.double(),e>>=se,n>>=se;return{p1:s,p2:i}}function Nr(r,t,e,n){Mu(e,r),Fu(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=bi(BigInt(o)),u=1;a>12?u=a-3:a>4?u=a-2:a>0&&(u=2);let c=ne(u),l=new Array(Number(c)+1).fill(i),f=Math.floor((t.BITS-1)/u)*u,h=i;for(let m=f;m>=0;m-=u){l.fill(i);for(let w=0;w<s;w++){let d=n[w],S=Number(d>>BigInt(m)&c);l[S]=l[S].add(e[w])}let b=i;for(let w=l.length-1,d=i;w>0;w--)d=d.add(l[w]),b=b.add(d);if(h=h.add(b),m!==0)for(let w=0;w<u;w++)h=h.double()}return h}function Pi(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return po(t),t}else return wt(r)}function kr(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>De))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Pi(t.p,e.Fp),o=Pi(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var It=BigInt(0),ut=BigInt(1),xo=BigInt(2),Ku=BigInt(8),zu={zip215:!0};function qu(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Hu(r,t={}){let{Fp:e,Fn:n}=kr("edwards",r,t),{h:o,n:s}=r;Zt(t,{},{uvRatio:"function"});let i=xo<<BigInt(n.BYTES*8)-ut,a=w=>e.create(w),u=t.uvRatio||((w,d)=>{try{return{isValid:!0,value:e.sqrt(e.div(w,d))}}catch{return{isValid:!1,value:It}}});if(!qu(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function c(w,d,S=!1){let C=S?ut:It;return $t("coordinate "+w,d,C,i),d}function l(w){if(!(w instanceof m))throw new Error("ExtendedPoint expected")}let f=Ce((w,d)=>{let{ex:S,ey:C,ez:v}=w,P=w.is0();d==null&&(d=P?Ku:e.inv(v));let y=a(S*d),L=a(C*d),D=a(v*d);if(P)return{x:It,y:ut};if(D!==ut)throw new Error("invZ was invalid");return{x:y,y:L}}),h=Ce(w=>{let{a:d,d:S}=r;if(w.is0())throw new Error("bad point: ZERO");let{ex:C,ey:v,ez:P,et:y}=w,L=a(C*C),D=a(v*v),I=a(P*P),p=a(I*I),E=a(L*d),g=a(I*a(E+D)),x=a(p+a(S*a(L*D)));if(g!==x)throw new Error("bad point: equation left != right (1)");let _=a(C*v),B=a(P*y);if(_!==B)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(d,S,C,v){this.ex=c("x",d),this.ey=c("y",S),this.ez=c("z",C,!0),this.et=c("t",v),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof m)throw new Error("extended point not allowed");let{x:S,y:C}=d||{};return c("x",S),c("y",C),new m(S,C,ut,a(S*C))}static normalizeZ(d){return Rr(m,"ez",d)}static msm(d,S){return Nr(m,n,d,S)}_setWindowSize(d){this.precompute(d)}precompute(d=8,S=!0){return b.setWindowSize(this,d),S||this.multiply(xo),this}assertValidity(){h(this)}equals(d){l(d);let{ex:S,ey:C,ez:v}=this,{ex:P,ey:y,ez:L}=d,D=a(S*L),I=a(P*v),p=a(C*L),E=a(y*v);return D===I&&p===E}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:d}=r,{ex:S,ey:C,ez:v}=this,P=a(S*S),y=a(C*C),L=a(xo*a(v*v)),D=a(d*P),I=S+C,p=a(a(I*I)-P-y),E=D+y,g=E-L,x=D-y,_=a(p*g),B=a(E*x),A=a(p*x),T=a(g*E);return new m(_,B,T,A)}add(d){l(d);let{a:S,d:C}=r,{ex:v,ey:P,ez:y,et:L}=this,{ex:D,ey:I,ez:p,et:E}=d,g=a(v*D),x=a(P*I),_=a(L*C*E),B=a(y*p),A=a((v+P)*(D+I)-g-x),T=B-_,O=B+_,R=a(x-S*g),$=a(A*T),U=a(O*R),N=a(A*R),Z=a(T*O);return new m($,U,Z,N)}subtract(d){return this.add(d.negate())}multiply(d){let S=d;$t("scalar",S,ut,s);let{p:C,f:v}=b.wNAFCached(this,S,m.normalizeZ);return m.normalizeZ([C,v])[0]}multiplyUnsafe(d,S=m.ZERO){let C=d;return $t("scalar",C,It,s),C===It?m.ZERO:this.is0()||C===ut?this:b.wNAFCachedUnsafe(this,C,m.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return b.wNAFCachedUnsafe(this,s).is0()}toAffine(d){return f(this,d)}clearCofactor(){return o===ut?this:this.multiplyUnsafe(o)}static fromBytes(d,S=!1){return nt(d),this.fromHex(d,S)}static fromHex(d,S=!1){let{d:C,a:v}=r,P=e.BYTES;d=q("pointHex",d,P),Ot("zip215",S);let y=d.slice(),L=d[P-1];y[P-1]=L&-129;let D=re(y),I=S?i:e.ORDER;$t("pointHex.y",D,It,I);let p=a(D*D),E=a(p-ut),g=a(C*p-v),{isValid:x,value:_}=u(E,g);if(!x)throw new Error("Point.fromHex: invalid y coordinate");let B=(_&ut)===ut,A=(L&128)!==0;if(!S&&_===It&&A)throw new Error("Point.fromHex: x=0 and x_0=1");return A!==B&&(_=a(-_)),m.fromAffine({x:_,y:D})}static fromPrivateScalar(d){return m.BASE.multiply(d)}toBytes(){let{x:d,y:S}=this.toAffine(),C=Be(S,e.BYTES);return C[C.length-1]|=d&ut?128:0,C}toRawBytes(){return this.toBytes()}toHex(){return vt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}m.BASE=new m(r.Gx,r.Gy,ut,a(r.Gx*r.Gy)),m.ZERO=new m(It,ut,ut,It),m.Fp=e,m.Fn=n;let b=Or(m,n.BYTES*8);return m}function Vu(r,t){Zt(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,u=t.randomBytes||tr,c=t.adjustScalarBytes||(y=>y),l=t.domain||((y,L,D)=>{if(Ot("phflag",D),L.length||D)throw new Error("Contexts/pre-hash are not supported");return y});function f(y){return i.create(y)}function h(y){return f(re(y))}function m(y){let L=s.BYTES;y=q("private key",y,L);let D=q("hashed private key",n(y),2*L),I=c(D.slice(0,L)),p=D.slice(L,2*L),E=h(I);return{head:I,prefix:p,scalar:E}}function b(y){let{head:L,prefix:D,scalar:I}=m(y),p=o.multiply(I),E=p.toBytes();return{head:L,prefix:D,scalar:I,point:p,pointBytes:E}}function w(y){return b(y).pointBytes}function d(y=Uint8Array.of(),...L){let D=pt(...L);return h(n(l(D,q("context",y),!!e)))}function S(y,L,D={}){y=q("message",y),e&&(y=e(y));let{prefix:I,scalar:p,pointBytes:E}=b(L),g=d(D.context,I,y),x=o.multiply(g).toBytes(),_=d(D.context,x,E,y),B=f(g+_*p);$t("signature.s",B,It,a);let A=s.BYTES,T=pt(x,Be(B,A));return q("result",T,A*2)}let C=zu;function v(y,L,D,I=C){let{context:p,zip215:E}=I,g=s.BYTES;y=q("signature",y,2*g),L=q("message",L),D=q("publicKey",D,g),E!==void 0&&Ot("zip215",E),e&&(L=e(L));let x=re(y.slice(g,2*g)),_,B,A;try{_=r.fromHex(D,E),B=r.fromHex(y.slice(0,g),E),A=o.multiplyUnsafe(x)}catch{return!1}if(!E&&_.isSmallOrder())return!1;let T=d(p,B.toBytes(),_.toBytes(),L);return B.add(_.multiplyUnsafe(T)).subtract(A).clearCofactor().is0()}return o.precompute(8),{getPublicKey:w,sign:S,verify:v,utils:{getExtendedPublicKey:b,randomPrivateKey:()=>u(s.BYTES),precompute(y=8,L=r.BASE){return L.precompute(y,!1)}},Point:r}}function ju(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=wt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function Gu(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function ki(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=ju(r),o=Hu(t,e),s=Vu(o,n);return Gu(r,s)}var bp=BigInt(0),$u=BigInt(1),Ui=BigInt(2),xp=BigInt(3),Zu=BigInt(5),Wu=BigInt(8),Ur={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Wu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Yu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ur.p,a=r*r%s*r%s,u=H(a,Ui,s)*a%s,c=H(u,$u,s)*r%s,l=H(c,Zu,s)*c%s,f=H(l,t,s)*l%s,h=H(f,e,s)*f%s,m=H(h,n,s)*h%s,b=H(m,o,s)*m%s,w=H(b,o,s)*m%s,d=H(w,t,s)*l%s;return{pow_p_5_8:H(d,Ui,s)*r%s,b2:a}}function Xu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Mi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Qu(r,t){let e=Ur.p,n=j(t*t*t,e),o=j(n*n*t,e),s=Yu(r*o).pow_p_5_8,i=j(r*n*s,e),a=j(t*i*i,e),u=i,c=j(i*Mi,e),l=a===r,f=a===j(-r,e),h=a===j(-r*Mi,e);return l&&(i=u),(f||h)&&(i=c),Ii(i,e)&&(i=j(-i,e)),{isValid:l||f,value:i}}var Ju=wt(Ur.p,void 0,!0),tf={...Ur,Fp:Ju,hash:mi,adjustScalarBytes:Xu,uvRatio:Qu},Fi=ki(tf);var ir=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Mr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ki={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Mr("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 Fr=Ki;var Kr=32;var wo,ef=(async()=>{try{return await Fr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function rf(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Fr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Fr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function nf(r,t,e){return Fi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function zi(r,t,e){return wo==null&&(wo=await ef),wo?rf(r,t,e):nf(r,t,e)}function zr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var qr=class{type="Ed25519";raw;constructor(t){this.raw=Eo(t,Kr)}toMultihash(){return yt.digest(Ee(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return V.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=zi(this.raw,e,t);return zr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Hi(r){return r=Eo(r,Kr),new qr(r)}function Eo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Ct(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var sf=Math.pow(2,7),af=Math.pow(2,14),cf=Math.pow(2,21),_o=Math.pow(2,28),So=Math.pow(2,35),vo=Math.pow(2,42),Ao=Math.pow(2,49),k=128,ot=127;function lt(r){if(r<sf)return 1;if(r<af)return 2;if(r<cf)return 3;if(r<_o)return 4;if(r<So)return 5;if(r<vo)return 6;if(r<Ao)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Le(r,t,e=0){switch(lt(r)){case 8:t[e++]=r&255|k,r/=128;case 7:t[e++]=r&255|k,r/=128;case 6:t[e++]=r&255|k,r/=128;case 5:t[e++]=r&255|k,r/=128;case 4:t[e++]=r&255|k,r>>>=7;case 3:t[e++]=r&255|k,r>>>=7;case 2:t[e++]=r&255|k,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function uf(r,t,e=0){switch(lt(r)){case 8:t.set(e++,r&255|k),r/=128;case 7:t.set(e++,r&255|k),r/=128;case 6:t.set(e++,r&255|k),r/=128;case 5:t.set(e++,r&255|k),r/=128;case 4:t.set(e++,r&255|k),r>>>=7;case 3:t.set(e++,r&255|k),r>>>=7;case 2:t.set(e++,r&255|k),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Io(r,t){let e=r[t],n=0;if(n+=e&ot,e<k||(e=r[t+1],n+=(e&ot)<<7,e<k)||(e=r[t+2],n+=(e&ot)<<14,e<k)||(e=r[t+3],n+=(e&ot)<<21,e<k)||(e=r[t+4],n+=(e&ot)*_o,e<k)||(e=r[t+5],n+=(e&ot)*So,e<k)||(e=r[t+6],n+=(e&ot)*vo,e<k)||(e=r[t+7],n+=(e&ot)*Ao,e<k))return n;throw new RangeError("Could not decode varint")}function ff(r,t){let e=r.get(t),n=0;if(n+=e&ot,e<k||(e=r.get(t+1),n+=(e&ot)<<7,e<k)||(e=r.get(t+2),n+=(e&ot)<<14,e<k)||(e=r.get(t+3),n+=(e&ot)<<21,e<k)||(e=r.get(t+4),n+=(e&ot)*_o,e<k)||(e=r.get(t+5),n+=(e&ot)*So,e<k)||(e=r.get(t+6),n+=(e&ot)*vo,e<k)||(e=r.get(t+7),n+=(e&ot)*Ao,e<k))return n;throw new RangeError("Could not decode varint")}function Vi(r,t,e=0){return t==null&&(t=ft(lt(r))),t instanceof Uint8Array?Le(r,t,e):uf(r,t,e)}function ar(r,t=0){return r instanceof Uint8Array?Io(r,t):ff(r,t)}var Bo=new Float32Array([-0]),Wt=new Uint8Array(Bo.buffer);function Gi(r,t,e){Bo[0]=r,t[e]=Wt[0],t[e+1]=Wt[1],t[e+2]=Wt[2],t[e+3]=Wt[3]}function $i(r,t){return Wt[0]=r[t],Wt[1]=r[t+1],Wt[2]=r[t+2],Wt[3]=r[t+3],Bo[0]}var Co=new Float64Array([-0]),st=new Uint8Array(Co.buffer);function Zi(r,t,e){Co[0]=r,t[e]=st[0],t[e+1]=st[1],t[e+2]=st[2],t[e+3]=st[3],t[e+4]=st[4],t[e+5]=st[5],t[e+6]=st[6],t[e+7]=st[7]}function Wi(r,t){return st[0]=r[t],st[1]=r[t+1],st[2]=r[t+2],st[3]=r[t+3],st[4]=r[t+4],st[5]=r[t+5],st[6]=r[t+6],st[7]=r[t+7],Co[0]}var lf=BigInt(Number.MAX_SAFE_INTEGER),hf=BigInt(Number.MIN_SAFE_INTEGER),mt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ie;if(t<lf&&t>hf)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Yi&&(o=0n,++n>Yi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ie;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ie}},ie=new mt(0,0);ie.toBigInt=function(){return 0n};ie.zzEncode=ie.zzDecode=function(){return this};ie.length=function(){return 1};var Yi=4294967296n;function Xi(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Qi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function To(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Et(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Hr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Do=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,Et(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 Et(this,4);return Hr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Et(this,4);return Hr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Et(this,4);let t=$i(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Et(this,4);let t=Wi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Et(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Qi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Et(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Et(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new mt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Et(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Et(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Et(this,8);let t=Hr(this.buf,this.pos+=4),e=Hr(this.buf,this.pos+=4);return new mt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Io(this.buf,this.pos);return this.pos+=lt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Lo(r){return new Do(r instanceof Uint8Array?r:r.subarray())}function Nt(r,t,e){let n=Lo(r);return t.decode(n,void 0,e)}function Po(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ae=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ro(){}var No=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},df=Po();function pf(r){return globalThis.Buffer!=null?ft(r):df(r)}var ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new ae(Ro,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ae(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ko((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(Vr,10,mt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=mt.fromBigInt(t);return this._push(Vr,e.length(),e)}uint64Number(t){return this._push(Le,lt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=mt.fromBigInt(t).zzEncode();return this._push(Vr,e.length(),e)}sint64Number(t){let e=mt.fromNumber(t).zzEncode();return this._push(Vr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Oo,1,t?1:0)}fixed32(t){return this._push(cr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=mt.fromBigInt(t);return this._push(cr,4,e.lo)._push(cr,4,e.hi)}fixed64Number(t){let e=mt.fromNumber(t);return this._push(cr,4,e.lo)._push(cr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Gi,4,t)}double(t){return this._push(Zi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Oo,1,0):this.uint32(e)._push(gf,e,t)}string(t){let e=Xi(t);return e!==0?this.uint32(e)._push(To,e,t):this._push(Oo,1,0)}fork(){return this.states=new No(this),this.head=this.tail=new ae(Ro,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 ae(Ro,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=pf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Oo(r,t,e){t[e]=r&255}function mf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ko=class extends ae{next;constructor(t,e){super(mf,t,e),this.next=void 0}};function Vr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function cr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function gf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ur.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(yf,t,r),this},ur.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(bf,t,r),this});function yf(r,t,e){t.set(r,e)}function bf(r,t,e){r.length<40?To(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(M(r),e)}function Uo(){return new ur}function kt(r,t){let e=Uo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Pe;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Pe||(Pe={}));function jr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Re(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return jr("enum",Pe.VARINT,e,n)}function Ut(r,t){return jr("message",Pe.LENGTH_DELIMITED,r,t)}var Gr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var gt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(gt||(gt={}));var Mo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Mo||(Mo={}));(function(r){r.codec=()=>Re(Mo)})(gt||(gt={}));var fr;(function(r){let t;r.codec=()=>(t==null&&(t=Ut((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=gt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>kt(e,r.codec()),r.decode=(e,n)=>Nt(e,r.codec(),n)})(fr||(fr={}));var Fo;(function(r){let t;r.codec=()=>(t==null&&(t=Ut((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=gt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>kt(e,r.codec()),r.decode=(e,n)=>Nt(e,r.codec(),n)})(Fo||(Fo={}));var $r=class extends _e{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Js(t);let n=Je(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Pt(s)}update(t){return ve(this),this.iHash.update(t),this}digestInto(t){ve(this),nt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ko=(r,t,e)=>new $r(r,t).update(e).digest();Ko.create=(r,t)=>new $r(r,t);function ta(r){r.lowS!==void 0&&Ot("lowS",r.lowS),r.prehash!==void 0&&Ot("prehash",r.prehash)}var zo=class extends Error{constructor(t=""){super(t)}},Mt={Err:zo,_tlv:{encode:(r,t)=>{let{Err:e}=Mt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=or(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?or(o.length/2|128):"";return or(r)+s+o+t},decode(r,t){let{Err:e}=Mt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let u=o&127;if(!u)throw new e("tlv.decode(long): indefinite length not supported");if(u>4)throw new e("tlv.decode(long): byte length is too big");let c=t.subarray(n,n+u);if(c.length!==u)throw new e("tlv.decode: length bytes not complete");if(c[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of c)i=i<<8|l;if(n+=u,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Mt;if(r<lr)throw new t("integer: negative integers are not allowed");let e=or(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Mt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ie(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Mt,o=q("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:u}=n.decode(2,s),{v:c,l}=n.decode(2,u);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(c)}},hexFromSig(r){let{_tlv:t,_int:e}=Mt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},lr=BigInt(0),hr=BigInt(1),wf=BigInt(2),Zr=BigInt(3),Ef=BigInt(4);function _f(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function ea(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=q("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let u=new Uint8Array(n);u.set(a,u.length-a.length),a=u}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function Sf(r,t={}){let{Fp:e,Fn:n}=kr("weierstrass",r,t),{h:o,n:s}=r;Zt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(I,p,E){let{x:g,y:x}=p.toAffine(),_=e.toBytes(g);if(Ot("isCompressed",E),E){a();let B=!e.isOdd(x);return pt(ra(B),_)}else return pt(Uint8Array.of(4),_,e.toBytes(x))}function c(I){nt(I);let p=e.BYTES,E=p+1,g=2*p+1,x=I.length,_=I[0],B=I.subarray(1);if(x===E&&(_===2||_===3)){let A=e.fromBytes(B);if(!e.isValid(A))throw new Error("bad point: is not on curve, wrong x");let T=h(A),O;try{O=e.sqrt(T)}catch(U){let N=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+N)}a();let R=e.isOdd(O);return(_&1)===1!==R&&(O=e.neg(O)),{x:A,y:O}}else if(x===g&&_===4){let A=e.fromBytes(B.subarray(p*0,p*1)),T=e.fromBytes(B.subarray(p*1,p*2));if(!m(A,T))throw new Error("bad point: is not on curve");return{x:A,y:T}}else throw new Error(`bad point: got length ${x}, expected compressed=${E} or uncompressed=${g}`)}let l=t.toBytes||u,f=t.fromBytes||c,h=_f(e,r.a,r.b);function m(I,p){let E=e.sqr(p),g=h(I);return e.eql(E,g)}if(!m(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let b=e.mul(e.pow(r.a,Zr),Ef),w=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(b,w)))throw new Error("bad curve params: a or b");function d(I,p,E=!1){if(!e.isValid(p)||E&&e.is0(p))throw new Error(`bad point coordinate ${I}`);return p}function S(I){if(!(I instanceof y))throw new Error("ProjectivePoint expected")}let C=Ce((I,p)=>{let{px:E,py:g,pz:x}=I;if(e.eql(x,e.ONE))return{x:E,y:g};let _=I.is0();p==null&&(p=_?e.ONE:e.inv(x));let B=e.mul(E,p),A=e.mul(g,p),T=e.mul(x,p);if(_)return{x:e.ZERO,y:e.ZERO};if(!e.eql(T,e.ONE))throw new Error("invZ was invalid");return{x:B,y:A}}),v=Ce(I=>{if(I.is0()){if(t.allowInfinityPoint&&!e.is0(I.py))return;throw new Error("bad point: ZERO")}let{x:p,y:E}=I.toAffine();if(!e.isValid(p)||!e.isValid(E))throw new Error("bad point: x or y not field elements");if(!m(p,E))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function P(I,p,E,g,x){return E=new y(e.mul(E.px,I),E.py,E.pz),p=Te(g,p),E=Te(x,E),p.add(E)}class y{constructor(p,E,g){this.px=d("x",p),this.py=d("y",E,!0),this.pz=d("z",g),Object.freeze(this)}static fromAffine(p){let{x:E,y:g}=p||{};if(!p||!e.isValid(E)||!e.isValid(g))throw new Error("invalid affine point");if(p instanceof y)throw new Error("projective point not allowed");return e.is0(E)&&e.is0(g)?y.ZERO:new y(E,g,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(p){return Rr(y,"pz",p)}static fromBytes(p){return nt(p),y.fromHex(p)}static fromHex(p){let E=y.fromAffine(f(q("pointHex",p)));return E.assertValidity(),E}static fromPrivateKey(p){let E=ea(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return y.BASE.multiply(E(p))}static msm(p,E){return Nr(y,n,p,E)}precompute(p=8,E=!0){return D.setWindowSize(this,p),E||this.multiply(Zr),this}_setWindowSize(p){this.precompute(p)}assertValidity(){v(this)}hasEvenY(){let{y:p}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(p)}equals(p){S(p);let{px:E,py:g,pz:x}=this,{px:_,py:B,pz:A}=p,T=e.eql(e.mul(E,A),e.mul(_,x)),O=e.eql(e.mul(g,A),e.mul(B,x));return T&&O}negate(){return new y(this.px,e.neg(this.py),this.pz)}double(){let{a:p,b:E}=r,g=e.mul(E,Zr),{px:x,py:_,pz:B}=this,A=e.ZERO,T=e.ZERO,O=e.ZERO,R=e.mul(x,x),$=e.mul(_,_),U=e.mul(B,B),N=e.mul(x,_);return N=e.add(N,N),O=e.mul(x,B),O=e.add(O,O),A=e.mul(p,O),T=e.mul(g,U),T=e.add(A,T),A=e.sub($,T),T=e.add($,T),T=e.mul(A,T),A=e.mul(N,A),O=e.mul(g,O),U=e.mul(p,U),N=e.sub(R,U),N=e.mul(p,N),N=e.add(N,O),O=e.add(R,R),R=e.add(O,R),R=e.add(R,U),R=e.mul(R,N),T=e.add(T,R),U=e.mul(_,B),U=e.add(U,U),R=e.mul(U,N),A=e.sub(A,R),O=e.mul(U,$),O=e.add(O,O),O=e.add(O,O),new y(A,T,O)}add(p){S(p);let{px:E,py:g,pz:x}=this,{px:_,py:B,pz:A}=p,T=e.ZERO,O=e.ZERO,R=e.ZERO,$=r.a,U=e.mul(r.b,Zr),N=e.mul(E,_),Z=e.mul(g,B),Y=e.mul(x,A),rt=e.add(E,g),F=e.add(_,B);rt=e.mul(rt,F),F=e.add(N,Z),rt=e.sub(rt,F),F=e.add(E,x);let it=e.add(_,A);return F=e.mul(F,it),it=e.add(N,Y),F=e.sub(F,it),it=e.add(g,x),T=e.add(B,A),it=e.mul(it,T),T=e.add(Z,Y),it=e.sub(it,T),R=e.mul($,F),T=e.mul(U,Y),R=e.add(T,R),T=e.sub(Z,R),R=e.add(Z,R),O=e.mul(T,R),Z=e.add(N,N),Z=e.add(Z,N),Y=e.mul($,Y),F=e.mul(U,F),Z=e.add(Z,Y),Y=e.sub(N,Y),Y=e.mul($,Y),F=e.add(F,Y),N=e.mul(Z,F),O=e.add(O,N),N=e.mul(it,F),T=e.mul(rt,T),T=e.sub(T,N),N=e.mul(rt,Z),R=e.mul(it,R),R=e.add(R,N),new y(T,O,R)}subtract(p){return this.add(p.negate())}is0(){return this.equals(y.ZERO)}multiply(p){let{endo:E}=t;if(!n.isValidNot0(p))throw new Error("invalid scalar: out of range");let g,x,_=B=>D.wNAFCached(this,B,y.normalizeZ);if(E){let{k1neg:B,k1:A,k2neg:T,k2:O}=E.splitScalar(p),{p:R,f:$}=_(A),{p:U,f:N}=_(O);x=$.add(N),g=P(E.beta,R,U,B,T)}else{let{p:B,f:A}=_(p);g=B,x=A}return y.normalizeZ([g,x])[0]}multiplyUnsafe(p){let{endo:E}=t,g=this;if(!n.isValid(p))throw new Error("invalid scalar: out of range");if(p===lr||g.is0())return y.ZERO;if(p===hr)return g;if(D.hasPrecomputes(this))return this.multiply(p);if(E){let{k1neg:x,k1:_,k2neg:B,k2:A}=E.splitScalar(p),{p1:T,p2:O}=Ni(y,g,_,A);return P(E.beta,T,O,x,B)}else return D.wNAFCachedUnsafe(g,p)}multiplyAndAddUnsafe(p,E,g){let x=this.multiplyUnsafe(E).add(p.multiplyUnsafe(g));return x.is0()?void 0:x}toAffine(p){return C(this,p)}isTorsionFree(){let{isTorsionFree:p}=t;return o===hr?!0:p?p(y,this):D.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:p}=t;return o===hr?this:p?p(y,this):this.multiplyUnsafe(o)}toBytes(p=!0){return Ot("isCompressed",p),this.assertValidity(),l(y,this,p)}toRawBytes(p=!0){return this.toBytes(p)}toHex(p=!0){return vt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}y.BASE=new y(r.Gx,r.Gy,e.ONE),y.ZERO=new y(e.ZERO,e.ONE,e.ZERO),y.Fp=e,y.Fn=n;let L=n.BITS,D=Or(y,t.endo?Math.ceil(L/2):L);return y}function ra(r){return Uint8Array.of(r?2:3)}function vf(r,t,e={}){Zt(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||tr,o=t.hmac||((g,...x)=>Ko(t.hash,g,pt(...x))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:u}=i;function c(g){let x=a>>hr;return g>x}function l(g){return c(g)?i.neg(g):g}function f(g,x){if(!i.isValidNot0(x))throw new Error(`invalid signature ${g}: out of range 1..CURVE.n`)}class h{constructor(x,_,B){f("r",x),f("s",_),this.r=x,this.s=_,B!=null&&(this.recovery=B),Object.freeze(this)}static fromCompact(x){let _=i.BYTES,B=q("compactSignature",x,_*2);return new h(i.fromBytes(B.subarray(0,_)),i.fromBytes(B.subarray(_,_*2)))}static fromDER(x){let{r:_,s:B}=Mt.toSig(q("DER",x));return new h(_,B)}assertValidity(){}addRecoveryBit(x){return new h(this.r,this.s,x)}recoverPublicKey(x){let _=s.ORDER,{r:B,s:A,recovery:T}=this;if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");if(a*wf<_&&T>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=T===2||T===3?B+a:B;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let $=s.toBytes(R),U=r.fromHex(pt(ra((T&1)===0),$)),N=i.inv(R),Z=v(q("msgHash",x)),Y=i.create(-Z*N),rt=i.create(A*N),F=r.BASE.multiplyUnsafe(Y).add(U.multiplyUnsafe(rt));if(F.is0())throw new Error("point at infinify");return F.assertValidity(),F}hasHighS(){return c(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i.neg(this.s),this.recovery):this}toBytes(x){if(x==="compact")return pt(i.toBytes(this.r),i.toBytes(this.s));if(x==="der")return Ae(Mt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return vt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return vt(this.toBytes("compact"))}}let m=ea(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),b={isValidPrivateKey(g){try{return m(g),!0}catch{return!1}},normPrivateKeyToScalar:m,randomPrivateKey:()=>{let g=a;return Ti(n(mo(g)),g)},precompute(g=8,x=r.BASE){return x.precompute(g,!1)}};function w(g,x=!0){return r.fromPrivateKey(g).toBytes(x)}function d(g){if(typeof g=="bigint")return!1;if(g instanceof r)return!0;let _=q("key",g).length,B=s.BYTES,A=B+1,T=2*B+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===A))return _===A||_===T}function S(g,x,_=!0){if(d(g)===!0)throw new Error("first arg must be private key");if(d(x)===!1)throw new Error("second arg must be public key");return r.fromHex(x).multiply(m(g)).toBytes(_)}let C=t.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");let x=Ie(g),_=g.length*8-u;return _>0?x>>BigInt(_):x},v=t.bits2int_modN||function(g){return i.create(C(g))},P=ne(u);function y(g){return $t("num < 2^"+u,g,lr,P),i.toBytes(g)}function L(g,x,_=D){if(["recovered","canonical"].some(rt=>rt in _))throw new Error("sign() legacy options not supported");let{hash:B}=t,{lowS:A,prehash:T,extraEntropy:O}=_;A==null&&(A=!0),g=q("msgHash",g),ta(_),T&&(g=q("prehashed msgHash",B(g)));let R=v(g),$=m(x),U=[y($),y(R)];if(O!=null&&O!==!1){let rt=O===!0?n(s.BYTES):O;U.push(q("extraEntropy",rt))}let N=pt(...U),Z=R;function Y(rt){let F=C(rt);if(!i.isValidNot0(F))return;let it=i.inv(F),qe=r.BASE.multiply(F).toAffine(),pe=i.create(qe.x);if(pe===lr)return;let Yt=i.create(it*i.create(Z+pe*$));if(Yt===lr)return;let Tn=(qe.x===pe?0:2)|Number(qe.y&hr),me=Yt;return A&&c(Yt)&&(me=l(Yt),Tn^=1),new h(pe,me,Tn)}return{seed:N,k2sig:Y}}let D={lowS:t.lowS,prehash:!1},I={lowS:t.lowS,prehash:!1};function p(g,x,_=D){let{seed:B,k2sig:A}=L(g,x,_);return xi(t.hash.outputLen,i.BYTES,o)(B,A)}r.BASE.precompute(8);function E(g,x,_,B=I){let A=g;x=q("msgHash",x),_=q("publicKey",_),ta(B);let{lowS:T,prehash:O,format:R}=B;if("strict"in B)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&!["compact","der","js"].includes(R))throw new Error('format must be "compact", "der" or "js"');let $=typeof A=="string"||Se(A),U=!$&&!R&&typeof A=="object"&&A!==null&&typeof A.r=="bigint"&&typeof A.s=="bigint";if(!$&&!U)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let N,Z;try{if(U)if(R===void 0||R==="js")N=new h(A.r,A.s);else throw new Error("invalid format");if($){try{R!=="compact"&&(N=h.fromDER(A))}catch(me){if(!(me instanceof Mt.Err))throw me}!N&&R!=="der"&&(N=h.fromCompact(A))}Z=r.fromHex(_)}catch{return!1}if(!N||T&&N.hasHighS())return!1;O&&(x=t.hash(x));let{r:Y,s:rt}=N,F=v(x),it=i.inv(rt),qe=i.create(F*it),pe=i.create(Y*it),Yt=r.BASE.multiplyUnsafe(qe).add(Z.multiplyUnsafe(pe));return Yt.is0()?!1:i.create(Yt.x)===Y}return Object.freeze({getPublicKey:w,getSharedSecret:S,sign:p,verify:E,utils:b,Point:r,Signature:h})}function Af(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=wt(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function If(r){let{CURVE:t,curveOpts:e}=Af(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function Bf(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function na(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=If(r),o=Sf(t,e),s=vf(o,n,e);return Bf(r,s)}function oa(r,t){let e=n=>na({...r,hash:n});return{...e(t),create:e}}var Wr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},M0=BigInt(0),Cf=BigInt(1),qo=BigInt(2),sa=(r,t)=>(r+t/qo)/t;function Tf(r){let t=Wr.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),u=BigInt(88),c=r*r*r%t,l=c*c*r%t,f=H(l,e,t)*l%t,h=H(f,e,t)*l%t,m=H(h,qo,t)*c%t,b=H(m,o,t)*m%t,w=H(b,s,t)*b%t,d=H(w,a,t)*w%t,S=H(d,u,t)*d%t,C=H(S,a,t)*w%t,v=H(C,e,t)*l%t,P=H(v,i,t)*b%t,y=H(P,n,t)*c%t,L=H(y,qo,t);if(!Ho.eql(Ho.sqr(L),r))throw new Error("Cannot find square root");return L}var Ho=wt(Wr.p,void 0,void 0,{sqrt:Tf}),Oe=oa({...Wr,Fp:Ho,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Wr.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Cf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=sa(s*r,t),u=sa(-n*r,t),c=j(r-a*e-u*o,t),l=j(-a*n-u*s,t),f=c>i,h=l>i;if(f&&(c=t-c),h&&(l=t-l),c>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:c,k2neg:h,k2:l}}}},pi);function ia(r,t,e,n){let o=Ze.digest(e instanceof Uint8Array?e:e.subarray());if(zr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Oe.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new ir(String(s))});try{return n?.signal?.throwIfAborted(),Oe.verify(t,o.digest,r)}catch(s){throw new ir(String(s))}}var Yr=class{type="secp256k1";raw;_key;constructor(t){this._key=ca(t),this.raw=aa(this._key)}toMultihash(){return yt.digest(Ee(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return V.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){return ia(this._key,e,t,n)}};function ua(r){return new Yr(r)}function aa(r){return Oe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ca(r){try{return Oe.ProjectivePoint.fromHex(r),r}catch(t){throw new Sr(String(t))}}function fa(r){let{Type:t,Data:e}=fr.decode(r.digest),n=e??new Uint8Array;switch(t){case gt.Ed25519:return Hi(n);case gt.secp256k1:return ua(n);case gt.ECDSA:return Ws(n);default:throw new He}}function Ee(r){return fr.encode({Type:gt[r.type],Data:r.raw})}var la=Symbol.for("nodejs.util.inspect.custom"),Df=114,dr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Dn]=!0;toString(){return this.string==null&&(this.string=V.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return X.createV1(Df,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return at(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return at(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[la](){return`PeerId(${this.toString()})`}},Xr=class extends dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Qr=class extends dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Jr=class extends dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Lf=2336,tn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=yt.digest(M(this.url))}[la](){return`PeerId(${this.url})`}[Dn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return X.createV1(Lf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function en(r){if(Rf(r))return new Xr({multihash:r});if(Pf(r))try{let t=fa(r);if(t.type==="Ed25519")return new Qr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Jr({multihash:r,publicKey:t})}catch{let e=z(r.digest);return new tn(new URL(e))}throw new vr("Supplied PeerID Multihash is invalid")}function Pf(r){return r.code===yt.code}function Rf(r){return r.code===Ze.code}function Vo(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function rn(r){let t=Qt(V.decode(`z${r}`));return en(t)}var nn=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Vo(this.set.entries(),t=>{let e=rn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=rn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Vo(this.set.values(),t=>rn(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function jo(){return new nn}var Go={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ha={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},da=new globalThis.TextEncoder;function Of(r,t){let e=Go[t],n=ha[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Nf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Go[t],o=ha[t],s=r;for(;s.length>0;){let i=da.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function $o(r,{size:t=32,utf8Buffer:e}={}){if(!Go[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return Nf(r,t,e);r=da.encode(r)}return Of(r,t)}var pr={hash:r=>Number($o(r,{size:32})),hashV:(r,t)=>kf(pr.hash(r,t))};function kf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),M(t,"base16")}var Zo=64,_t=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Zo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=bt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?at(this.fp,t.fp):!1}};function ce(r,t){return Math.floor(Math.random()*(t-r))+r}var ue=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");let e=ce(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Uf=500,mr=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??pr,this.seed=t.seed??ce(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=M(t));let e=new _t(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ue(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ue(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[ce(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ue(this.bucketSize));for(let a=0;a<Uf;a++){let u=this.buckets[i].swap(e);if(u!=null&&(i=(i^u.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ue(this.bucketSize)),this.buckets[i].add(u)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=M(t));let e=new _t(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=M(t));let e=new _t(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Mf={1:.5,2:.84,4:.95,8:.98};function Ff(r=.001){return r>.002?2:r>1e-5?4:8}function pa(r,t=.001){let e=Ff(t),n=Mf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Zo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var on=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??pr,this.seed=t.seed??ce(0,Math.pow(2,10)),this.filterSeries=[new mr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=M(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new mr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=M(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=M(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function Wo(r,t=.001,e){return new on({...pa(r,t),...e??{}})}var sn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let u=a==="0",c=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(s*=t,s+=l,s>c||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&u&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ma=45,Kf=15,Ne=new sn;function an(r){if(!(r.length>Kf))return Ne.new(r).parseWith(()=>Ne.readIPv4Addr())}function cn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ma))return Ne.new(r).parseWith(()=>Ne.readIPv6Addr())}function ke(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>ma)return;let e=Ne.new(r).parseWith(()=>Ne.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function ga(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function ya(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Yo(r){switch(r.length){case fe:return r.join(".");case le:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function ba(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function xa(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var fe=4,le=16,vg=parseInt("0xFFFF",16),zf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function gr(r,t){t.length===le&&r.length===fe&&ga(t,0,11)&&(t=t.slice(12)),t.length===fe&&r.length===le&&ya(r,zf,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function wa(r,t){if(typeof t=="string"&&(t=ke(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Xo(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=fe,o=an(t);if(o==null&&(n=le,o=cn(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=Qo(s,8*n);return{network:gr(o,i),mask:i}}function Qo(r,t){if(t!==8*fe&&t!==8*le)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var Ue=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Xo(t));else{let n=ke(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=ke(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Qo(o,8*n.length);this.network=gr(n,this.mask)}}contains(t){return wa({network:this.network,mask:this.mask},t)}toString(){let t=ba(this.mask),e=t!==-1?String(t):xa(this.mask);return Yo(this.network)+"/"+e}};function Ea(r,t){return new Ue(r).contains(t)}var tt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ft=class extends Error{static name="ValidationError";name="ValidationError"},yr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},un=class extends Error{static name="InvalidProtocolError";name="InvalidProtocolError"};function Me(r){return!!an(r)}function fn(r){return!!cn(r)}function ts(r){return t=>z(t,r)}function es(r){return t=>M(t,r)}function Fe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function he(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function _a(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=M(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=he(n);return Dt([e,o],e.length+o.length)}function Sa(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=qt.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=he(n);return Dt([e,o],e.length+o.length)}function rs(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=z(t,"base32"),o=Fe(e);return`${n}:${o}`}var ns=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new tt("Invalid byte value in IP address");t[n]=o}),t},va=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Me(e[n]),i;s&&(i=ns(e[n]),e[n]=z(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,z(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new tt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Aa=function(r){if(r.byteLength!==4)throw new tt("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Ia=function(r){if(r.byteLength!==16)throw new tt("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new tt(`Invalid IPv6 address "${e}"`)}};function Ba(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new tt(`Invalid IPv6 address "${r}"`)}}var Jo=Object.values(We).map(r=>r.decoder),qf=function(){let r=Jo[0].or(Jo[1]);return Jo.slice(2).forEach(t=>r=r.or(t)),r}();function Ca(r){return qf.decode(r)}function Ta(r){return t=>r.encoder.encode(t)}function Hf(r){if(parseInt(r).toString()!==r)throw new Ft("Value must be an integer")}function Vf(r){if(r<0)throw new Ft("Value must be a positive integer, or zero")}function jf(r){return t=>{if(t>r)throw new Ft(`Value must be smaller than or equal to ${r}`)}}function Gf(...r){return t=>{for(let e of r)e(t)}}var br=Gf(Hf,Vf,jf(65535));var et=-1,os=class{protocolsByCode=new Map;protocolsByName=new Map;getCodec(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new un(`Protocol ${t} was unknown`);return e}addCodec(t,e,n){this.protocolsByCode.set(t,e),this.protocolsByName.set(e.name,e),n?.forEach(o=>{this.protocolsByName.set(o,e)})}deleteCodec(t){let e=this.getCodec(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ht=new os,_l=[{code:4,name:"ip4",size:32,valueToBytes:ns,bytesToValue:Aa,validate:r=>{if(!Me(r))throw new Ft(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:he,bytesToValue:Fe,validate:br},{code:273,name:"udp",size:16,valueToBytes:he,bytesToValue:Fe,validate:br},{code:33,name:"dccp",size:16,valueToBytes:he,bytesToValue:Fe,validate:br},{code:41,name:"ip6",size:128,valueToBytes:va,bytesToValue:Ia,stringToValue:Ba,validate:r=>{if(!fn(r))throw new Ft(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:et},{code:43,name:"ipcidr",size:8,bytesToValue:ts("base10"),valueToBytes:es("base10")},{code:53,name:"dns",size:et,resolvable:!0},{code:54,name:"dns4",size:et,resolvable:!0},{code:55,name:"dns6",size:et,resolvable:!0},{code:56,name:"dnsaddr",size:et,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:he,bytesToValue:Fe,validate:br},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:et,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:et,bytesToValue:ts("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?es("base58btc")(r):X.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:rs,valueToBytes:_a},{code:445,name:"onion3",size:296,bytesToValue:rs,valueToBytes:Sa},{code:446,name:"garlic64",size:et},{code:447,name:"garlic32",size:et},{code:448,name:"tls"},{code:449,name:"sni",size:et},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:et,bytesToValue:Ta(jn),valueToBytes:Ca},{code:480,name:"http"},{code:481,name:"http-path",size:et,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:et}];_l.forEach(r=>{ht.addCodec(r.code,r,r.aliases)});function Da(r){let t=[],e=0;for(;e<r.length;){let n=ar(r,e),o=ht.getCodec(n),s=lt(n),i=Sl(o,r,e+s),a=0;i>0&&o.size===et&&(a=lt(i));let u=s+a+i,c={code:n,name:o.name,bytes:r.subarray(e,e+u)};if(i>0){let l=e+s+a,f=r.subarray(l,l+i);c.value=o.bytesToValue?.(f)??z(f)}t.push(c),e+=u}return t}function La(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=ht.getCodec(n.code),s=lt(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??M(n.value),a=i.byteLength,o.size===et&&(u=lt(a)));let c=new Uint8Array(s+u+a),l=0;Le(n.code,c,l),l+=s,i!=null&&(o.size===et&&(Le(a,c,l),l+=u),c.set(i,l)),n.bytes=c}e.push(n.bytes),t+=n.bytes.byteLength}return Dt(e,t)}function Pa(r){if(r.charAt(0)!=="/")throw new tt('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let u=ht.getCodec(o);if(e==="protocol"){if(u.size==null||u.size===0){t.push({code:u.code,name:u.name}),n="",o="",e="protocol";continue}else if(a)throw new tt(`Component ${o} was missing value`);e="value"}else if(e==="value"){let c={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new tt(`Component ${o} was missing value`);c.value=u.stringToValue?.(n)??n}t.push(c),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new tt("Incomplete multiaddr");return t}function Ra(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=ht.getCodec(t.code);if(e==null)throw new tt(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Sl(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:ar(t,e)}var vl=Symbol.for("nodejs.util.inspect.custom"),ls=Symbol.for("@multiformats/multiaddr"),Al=[53,54,55,56],fs=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Il(r){if(r==null&&(r="/"),Na(r))return r.getComponents();if(r instanceof Uint8Array)return Da(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Pa(r);if(Array.isArray(r))return r;throw new tt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var pn=class r{[ls]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Il(t),e.validate!==!1&&Bl(this)}get bytes(){return this.#r==null&&(this.#r=La(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Ra(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:u,value:c}of this.#t)a===42&&(s=`%${c??""}`),Al.includes(a)&&(e="tcp",o=443,n=`${c??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=u==="tcp"?"tcp":"udp",o=parseInt(c??"")),(a===4||a===41)&&(e="tcp",n=`${c??""}${s}`,t=a===41?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=ht.getCodec(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=ht.getCodec(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??M(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new yr(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?z(V.decode(`z${n}`),"base58btc"):z(X.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(ht.getCodec(t.code).path)return t.value??null;return null}equals(t){return at(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Oa.get(e.name);if(n==null)throw new fs(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>wr(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)}[vl](){return`Multiaddr(${this.toString()})`}};function Bl(r){r.getComponents().forEach(t=>{let e=ht.getCodec(t.code);t.value!=null&&e.validate?.(t.value)})}var Oa=new Map;function Na(r){return!!r?.[ls]}function wr(r){return new pn(r)}function ka(r){let t=ht.getCodec(r);return{code:t.code,size:t.size??0,name:t.name,resolvable:!!t.resolvable,path:!!t.path}}function Ua(r){try{for(let{code:t,value:e}of r.getComponents())if(e!=null&&t===41)return Ea("2000::/3",e)}catch{}return!1}var Fa=nc(Ma(),1),Cl=["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"],Tl=Cl.map(r=>new Fa.Netmask(r));function hs(r){for(let t of Tl)if(t.contains(r))return!0;return!1}function Dl(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Ll(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return hs(o)}function Pl(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Rl(r){let t=r.split(":"),e=t[t.length-1];return hs(e)}function Ol(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Ka(r){if(Me(r))return hs(r);if(Dl(r))return Ll(r);if(Pl(r))return Rl(r);if(fn(r))return Ol(r)}function za(r){try{for(let{code:t}of r.getComponents())if(t!==42)return t===4||t===41}catch{}return!1}function ds(r){try{if(!za(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:Ka(t)??!1}catch{}return!0}function St(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var mn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new mn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new mn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var ps=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function qa(r={}){return Nl(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Nl(r,t){t=t??{};let e=t.onEnd,n=new ze,o,s,i,a=St(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,S)=>{s=C=>{s=null,n.push(C);try{d(r(n))}catch(v){S(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=St()})}},c=d=>s!=null?s(d):(n.push(d),o),l=d=>(n=new ze,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:d})},h=d=>i?o:(i=!0,d!=null?l(d):c({done:!0})),m=()=>(n=new ze,h(),{done:!0}),b=d=>(h(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:m,throw:b,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let S=d?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let C,v;S!=null&&(C=new Promise((P,y)=>{v=()=>{y(new ps)},S.addEventListener("abort",v)}));try{await Promise.race([a.promise,C])}finally{v!=null&&S!=null&&S?.removeEventListener("abort",v)}}},e==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(d){return w.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return w.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return w.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return w.readableLength},onEmpty:d=>w.onEmpty(d)},o}var ms=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function gn(r,t,e,n){let o=new ms(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",l),r.removeEventListener(t,u),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,c)}let u=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),i(h);return}a(),s(f)},c=f=>{a(),i(f.detail)},l=()=>{a(),i(o)};e?.addEventListener("abort",l),r.addEventListener(t,u),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,c)})}function gs(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var yn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var bn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function de(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new bn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new bn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var xn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=St(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Bt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function kl(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var wn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=kl(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Bt),this.cleanup())}async join(t={}){let e=new xn(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await de(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var En=class extends Ar{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=gs(this.emitEmpty.bind(this),1),this.emitIdle=gs(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new yn;let n=new wn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("error",{detail:o}),this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Bt)}),this.clear()}async onEmpty(t){this.size!==0&&await gn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await gn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await gn(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=qa({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),e.end(u)},o=u=>{u.detail!=null&&e.push(u.detail)},s=u=>{n(u.detail)},i=()=>{n()},a=()=>{n(new Bt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var _n=class extends En{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Sn(r){let t=new globalThis.AbortController;function e(){t.abort();for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}function Ha(r,t,e){let n,o;function s(){let a={signal:o.signal};if(e?.timeout!=null){let u=Sn([o.signal,AbortSignal.timeout(e.timeout)]);a.signal=u}Promise.resolve().then(async()=>{await r(a)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{setInterval:a=>{t!==a&&(t=a,n!=null&&(clearTimeout(n),n=setTimeout(s,t)))},setTimeout:a=>{e??={},e.timeout=a},start:()=>{i||(i=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),i=!1}}}var ys=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Va(r){let{name:t,metrics:e}=r,n;return e!=null?n=new ys({name:t,metrics:e}):n=new Map,n}var bs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=St(),this.haveNext=St()}[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=St(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=St(),await de(this.readNext.promise,e?.signal,e)}};function ja(){return new bs}var vn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ga(r,t){let e=ja();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new W;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:u,value:c}=await de(n.next(),i?.signal);return u===!0?null:c}for(;o.byteLength<i.bytes;){let{value:u,done:c}=await de(n.next(),i?.signal);if(c===!0)throw new vn("unexpected end of input");o.append(u)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var An=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},In=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Bn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $a(r,t={}){let e=Ga(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=lt(t.maxDataLength));let n=t?.lengthDecoder??ar,o=t?.lengthEncoder??Vi;return{read:async i=>{let a=-1,u=new W;for(;;){u.append(await e.read({...i,bytes:1}));try{a=n(u)}catch(c){if(c instanceof RangeError)continue;throw c}if(a<0)throw new An("Invalid message length");if(t?.maxLengthLength!=null&&u.byteLength>t.maxLengthLength)throw new Bn("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new In("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new W(o(i.byteLength),i),a)},writeV:async(i,a)=>{let u=new W(...i.flatMap(c=>[o(c.byteLength),c]));await e.write(u,a)},unwrap:()=>e.unwrap()}}function xs(r,t){let e=$a(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Za="libp2p",Wa="autonat",Ya="1.0.0";var K;(function(r){let t;(function(c){c.DIAL="DIAL",c.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(c){c[c.DIAL=0]="DIAL",c[c.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(c){c.codec=()=>Re(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(c){c.OK="OK",c.E_DIAL_ERROR="E_DIAL_ERROR",c.E_DIAL_REFUSED="E_DIAL_REFUSED",c.E_BAD_REQUEST="E_BAD_REQUEST",c.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(c){c[c.OK=0]="OK",c[c.E_DIAL_ERROR=100]="E_DIAL_ERROR",c[c.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",c[c.E_BAD_REQUEST=200]="E_BAD_REQUEST",c[c.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(c){c.codec=()=>Re(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(c){let l;c.codec=()=>(l==null&&(l=Ut((f,h,m={})=>{if(m.lengthDelimited!==!1&&h.fork(),f.id!=null&&(h.uint32(10),h.bytes(f.id)),f.addrs!=null)for(let b of f.addrs)h.uint32(18),h.bytes(b);m.lengthDelimited!==!1&&h.ldelim()},(f,h,m={})=>{let b={addrs:[]},w=h==null?f.len:f.pos+h;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{b.id=f.bytes();break}case 2:{if(m.limits?.addrs!=null&&b.addrs.length===m.limits.addrs)throw new Gr('Decode error - map field "addrs" had too many elements');b.addrs.push(f.bytes());break}default:{f.skipType(d&7);break}}}return b})),l),c.encode=f=>kt(f,c.codec()),c.decode=(f,h)=>Nt(f,c.codec(),h)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(c){let l;c.codec=()=>(l==null&&(l=Ut((f,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),f.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(f.peer,h)),m.lengthDelimited!==!1&&h.ldelim()},(f,h,m={})=>{let b={},w=h==null?f.len:f.pos+h;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{b.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:m.limits?.peer});break}default:{f.skipType(d&7);break}}}return b})),l),c.encode=f=>kt(f,c.codec()),c.decode=(f,h)=>Nt(f,c.codec(),h)})(i=r.Dial||(r.Dial={}));let a;(function(c){let l;c.codec=()=>(l==null&&(l=Ut((f,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),f.status!=null&&(h.uint32(8),r.ResponseStatus.codec().encode(f.status,h)),f.statusText!=null&&(h.uint32(18),h.string(f.statusText)),f.addr!=null&&(h.uint32(26),h.bytes(f.addr)),m.lengthDelimited!==!1&&h.ldelim()},(f,h,m={})=>{let b={},w=h==null?f.len:f.pos+h;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{b.status=r.ResponseStatus.codec().decode(f);break}case 2:{b.statusText=f.string();break}case 3:{b.addr=f.bytes();break}default:{f.skipType(d&7);break}}}return b})),l),c.encode=f=>kt(f,c.codec()),c.decode=(f,h)=>Nt(f,c.codec(),h)})(a=r.DialResponse||(r.DialResponse={}));let u;r.codec=()=>(u==null&&(u=Ut((c,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),c.type!=null&&(l.uint32(8),r.MessageType.codec().encode(c.type,l)),c.dial!=null&&(l.uint32(18),r.Dial.codec().encode(c.dial,l)),c.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(c.dialResponse,l)),f.lengthDelimited!==!1&&l.ldelim()},(c,l,f={})=>{let h={},m=l==null?c.len:c.pos+l;for(;c.pos<m;){let b=c.uint32();switch(b>>>3){case 1:{h.type=r.MessageType.codec().decode(c);break}case 2:{h.dial=r.Dial.codec().decode(c,c.uint32(),{limits:f.limits?.dial});break}case 3:{h.dialResponse=r.DialResponse.codec().decode(c,c.uint32(),{limits:f.limits?.dialResponse});break}default:{c.skipType(b&7);break}}}return h})),u),r.encode=c=>kt(c,r.codec()),r.decode=(c,l)=>Nt(c,r.codec(),l)})(K||(K={}));var ql=4,Hl=8,Cn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${e.protocolPrefix??Za}/${Wa}/${Ya}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.connectionThreshold=e.connectionThreshold??80,this.maxMessageSize=e.maxMessageSize??8192,this.dialResults=Va({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=Ha(this.findRandomPeers.bind(this),6e4),this.addressFilter=Wo(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Es]=["@libp2p/autonat"];get[_s](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream - %e",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=Sn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t){let e=AbortSignal.timeout(this.timeout);let n=xs(t.stream,{maxDataLength:this.maxMessageSize}).pb(K);try{let o=await n.read({signal:e}),s=await this.handleAutonatMessage(o,t.connection,{signal:e});await n.write(s,{signal:e}),await n.unwrap().unwrap().close({signal:e})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.stream.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(f=>f.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("PeerId missing from message"),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Qt(a.id);i=en(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let u=a.addrs.map(f=>wr(f)).filter(f=>{let h=f.toOptions();return ds(f)?!1:h.host!==e.remoteAddr.toOptions().host?(this.log.trace("not dialing %a - target host did not match remote host %a",f,e.remoteAddr),!1):o.includes(h.host)?!1:this.components.transportManager.dialTransportForMultiaddr(f)==null?(this.log.trace("not dialing %a - transport unsupported",f),!1):!0}).map(f=>(f.getPeerId()==null&&(f=f.encapsulate(`/p2p/${i.toString()}`)),f));if(u.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",u.map(f=>f.toString()).join(", "),i);let c="",l=u[0];for(let f of u){let h;l=f;try{if(h=await this.components.connectionManager.openConnection(f,n),!h.remoteAddr.equals(f))throw this.log.error("tried to dial %a but dialed %a",f,h.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,f),{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(ka("p2p").code).bytes}}}catch(m){this.log.error("could not dial %p - %e",i,m),c=m.message}finally{h!=null&&await h.close()}}return{type:K.MessageType.DIAL_RESPONSE,dialResponse:{status:K.ResponseStatus.E_DIAL_ERROR,statusText:c,addr:l.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||o.multiaddr.toOptions().family===6&&(!e||!Ua(o.multiaddr))||ds(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:jo(),queue:new _n({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>i.toOptions().family===6),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %p to verify multiaddr %s",t.remotePeer,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=xs(i).pb(K),[,u]=await Promise.all([a.write({type:K.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(u.type!==K.MessageType.DIAL_RESPONSE||u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}let c=u.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,c),c!==K.ResponseStatus.OK&&c!==K.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,u.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),c===K.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else c===K.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===ql&&this.confirmAddress(o),o.failure===Hl&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};function Vl(r={}){return t=>new Cn(t,r)}return oc(jl);})();
|
|
2
|
+
"use strict";var Libp2PAutonat=(()=>{var Ca=Object.create;var hr=Object.defineProperty;var ka=Object.getOwnPropertyDescriptor;var Na=Object.getOwnPropertyNames;var Ua=Object.getPrototypeOf,Oa=Object.prototype.hasOwnProperty;var Ma=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),lt=(r,t)=>{for(var e in t)hr(r,e,{get:t[e],enumerable:!0})},fs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Na(t))!Oa.call(r,o)&&o!==e&&hr(r,o,{get:()=>t[o],enumerable:!(n=ka(t,o))||n.enumerable});return r};var Fa=(r,t,e)=>(e=r!=null?Ca(Ua(r)):{},fs(t||!r||!r.__esModule?hr(e,"default",{value:r,enumerable:!0}):e,r)),Ka=r=>fs(hr({},"__esModule",{value:!0}),r);var la=Ma(fr=>{(function(){var r,t,e,n,o,s,i,a;a=function(f){var c,l,u,h;return c=(f&255<<24)>>>24,l=(f&255<<16)>>>16,u=(f&65280)>>>8,h=f&255,[c,l,u,h].join(".")},i=function(f){var c,l,u,h,d,g;for(c=[],u=h=0;h<=3&&f.length!==0;u=++h){if(u>0){if(f[0]!==".")throw new Error("Invalid IP");f=f.substring(1)}g=t(f),d=g[0],l=g[1],f=f.substring(l),c.push(d)}if(f.length!==0)throw new Error("Invalid IP");switch(c.length){case 1:if(c[0]>4294967295)throw new Error("Invalid IP");return c[0]>>>0;case 2:if(c[0]>255||c[1]>16777215)throw new Error("Invalid IP");return(c[0]<<24|c[1])>>>0;case 3:if(c[0]>255||c[1]>255||c[2]>65535)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2])>>>0;case 4:if(c[0]>255||c[1]>255||c[2]>255||c[3]>255)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2]<<8|c[3])>>>0;default:throw new Error("Invalid IP")}},e=function(f){return f.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(f){var c,l,u,h,d;for(h=0,c=10,l="9",u=0,f.length>1&&f[u]==="0"&&(f[u+1]==="x"||f[u+1]==="X"?(u+=2,c=16):"0"<=f[u+1]&&f[u+1]<="9"&&(u++,c=8,l="7")),d=u;u<f.length;){if("0"<=f[u]&&f[u]<=l)h=h*c+(e(f[u])-n)>>>0;else if(c===16)if("a"<=f[u]&&f[u]<="f")h=h*c+(10+e(f[u])-s)>>>0;else if("A"<=f[u]&&f[u]<="F")h=h*c+(10+e(f[u])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");u++}if(u===d)throw new Error("empty octet");return[h,u]},r=function(){function f(c,l){var u,h,d,g;if(typeof c!="string")throw new Error("Missing `net' parameter");if(l||(g=c.split("/",2),c=g[0],l=g[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(w){throw u=w,new Error("Invalid mask: "+l)}for(h=d=32;d>=0;h=--d)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(l||l===0)this.bitmask=parseInt(l,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(c)&this.maskLong)>>>0}catch(w){throw u=w,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return f.prototype.contains=function(c){return typeof c=="string"&&(c.indexOf("/")>0||c.split(".").length!==4)&&(c=new f(c)),c instanceof f?this.contains(c.base)&&this.contains(c.broadcast||c.last):(i(c)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},f.prototype.next=function(c){return c==null&&(c=1),new f(a(this.netLong+this.size*c),this.mask)},f.prototype.forEach=function(c){var l,u,h;for(h=i(this.first),u=i(this.last),l=0;h<=u;)c(a(h),h,l),l++,h++},f.prototype.toString=function(){return this.base+"/"+this.bitmask},f}(),fr.ip2long=i,fr.long2ip=a,fr.Netmask=r}).call(fr)});var ol={};lt(ol,{autoNAT:()=>nl});var wn=Symbol.for("@libp2p/peer-id");var It=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Bt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},dr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var pr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Oe=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 e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ls=Symbol.for("@libp2p/service-capabilities"),hs=Symbol.for("@libp2p/service-dependencies");var An={};lt(An,{base58btc:()=>z,base58flickr:()=>$a});var Pl=new Uint8Array(0);function ds(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Lt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ps(r){return new TextEncoder().encode(r)}function ms(r){return new TextDecoder().decode(r)}function za(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,f=r.charAt(0),c=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,p=0,_=0,L=g.length;_!==L&&g[_]===0;)_++,w++;for(var v=(L-_)*l+1>>>0,R=new Uint8Array(v);_!==L;){for(var b=g[_],D=0,P=v-1;(b!==0||D<p)&&P!==-1;P--,D++)b+=256*R[P]>>>0,R[P]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");p=D,_++}for(var I=v-p;I!==v&&R[I]===0;)I++;for(var m=f.repeat(w);I<v;++I)m+=r.charAt(R[I]);return m}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var p=0,_=0;g[w]===f;)p++,w++;for(var L=(g.length-w)*c+1>>>0,v=new Uint8Array(L);g[w];){var R=e[g.charCodeAt(w)];if(R===255)return;for(var b=0,D=L-1;(R!==0||b<_)&&D!==-1;D--,b++)R+=a*v[D]>>>0,v[D]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");_=b,w++}if(g[w]!==" "){for(var P=L-_;P!==L&&v[P]===0;)P++;for(var I=new Uint8Array(p+(L-P)),m=p;P!==L;)I[m++]=v[P++];return I}}}function d(g){var w=h(g);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:h,decode:d}}var qa=za,Ha=qa,ys=Ha;var En=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Sn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return bs(this,t)}},_n=class{decoders;constructor(t){this.decoders=t}or(t){return bs(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function bs(r,t){return new _n({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var vn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new En(t,e,n),this.decoder=new Sn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function pe({name:r,prefix:t,encode:e,decode:n}){return new vn(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ys(e,r);return pe({prefix:t,name:r,encode:n,decode:s=>Lt(o(s))})}function Va(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let l=t[r[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ja(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let f=0;f<r.length;++f)for(a=a<<8|r[f],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ga(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function G({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Ga(n);return pe({prefix:t,name:r,encode(s){return ja(s,n,e)},decode(s){return Va(s,o,e,r)}})}var z=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$a=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var In={};lt(In,{base32:()=>Tt,base32hex:()=>Xa,base32hexpad:()=>Ja,base32hexpadupper:()=>tc,base32hexupper:()=>Qa,base32pad:()=>Wa,base32padupper:()=>Ya,base32upper:()=>Za,base32z:()=>ec});var Tt=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Za=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wa=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ya=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xa=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qa=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ja=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tc=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ec=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Bn={};lt(Bn,{base36:()=>Me,base36upper:()=>rc});var Me=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rc=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nc=Es,xs=128,oc=127,sc=~oc,ic=Math.pow(2,31);function Es(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ic;)t[e++]=r&255|xs,r/=128;for(;r≻)t[e++]=r&255|xs,r>>>=7;return t[e]=r|0,Es.bytes=e-n+1,t}var ac=Ln,cc=128,ws=127;function Ln(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ln.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ws)<<o:(i&ws)*Math.pow(2,o),o+=7}while(i>=cc);return Ln.bytes=s-n,e}var uc=Math.pow(2,7),fc=Math.pow(2,14),lc=Math.pow(2,21),hc=Math.pow(2,28),dc=Math.pow(2,35),pc=Math.pow(2,42),mc=Math.pow(2,49),gc=Math.pow(2,56),yc=Math.pow(2,63),bc=function(r){return r<uc?1:r<fc?2:r<lc?3:r<hc?4:r<dc?5:r<pc?6:r<mc?7:r<gc?8:r<yc?9:10},xc={encode:nc,decode:ac,encodingLength:bc},wc=xc,Fe=wc;function Ke(r,t=0){return[Fe.decode(r,t),Fe.decode.bytes]}function me(r,t,e=0){return Fe.encode(r,t,e),t}function ge(r){return Fe.encodingLength(r)}function Yt(r,t){let e=t.byteLength,n=ge(r),o=n+ge(e),s=new Uint8Array(o+e);return me(r,s,0),me(e,s,n),s.set(t,o),new ye(r,e,t,s)}function Pt(r){let t=Lt(r),[e,n]=Ke(t),[o,s]=Ke(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ye(e,o,i,t)}function Ss(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ds(r.bytes,e.bytes)}}var ye=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function _s(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Sc(e,Tn(r),t??z.encoder);default:return _c(e,Tn(r),t??Tt.encoder)}}var vs=new WeakMap;function Tn(r){let t=vs.get(r);if(t==null){let e=new Map;return vs.set(r,e),e}return t}var Q=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==vc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Yt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ss(t.multihash,n.multihash)}toString(t){return _s(this,t)}toJSON(){return{"/":_s(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??As(n,o,s.bytes))}else if(e[Ac]===!0){let{version:n,multihash:o,code:s}=e,i=Pt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=As(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ze,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Lt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ye(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,h]=Ke(t.subarray(e));return e+=h,u},o=n(),s=ze;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),f=n(),c=e+f,l=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:l,size:c}}static parse(t,e){let[n,o]=Ec(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Tn(s).set(n,t),s}};function Ec(r,t){switch(r[0]){case"Q":{let e=t??z;return[z.prefix,e.decode(`${z.prefix}${r}`)]}case z.prefix:{let e=t??z;return[z.prefix,e.decode(r)]}case Tt.prefix:{let e=t??Tt;return[Tt.prefix,e.decode(r)]}case Me.prefix:{let e=t??Me;return[Me.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Sc(r,t,e){let{prefix:n}=e;if(n!==z.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function _c(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var ze=112,vc=18;function As(r,t,e){let n=ge(r),o=n+ge(t),s=new Uint8Array(o+e.byteLength);return me(r,s,0),me(t,s,n),s.set(e,o),s}var Ac=Symbol.for("@ipld/js-cid/CID");var Pn={};lt(Pn,{identity:()=>gt});var Is=0,Ic="identity",Bs=Lt;function Bc(r){return Yt(Is,Bs(r))}var gt={code:Is,name:Ic,encode:Bs,digest:Bc};function at(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function yt(r=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function ht(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ts=Symbol.for("@achingbrain/uint8arraylist");function Ls(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function yr(r){return!!r?.[Ts]}var Y=class r{bufs;length;[Ts]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(yr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(yr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ls(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ls(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(yr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return ht(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ht(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,f=a+i.byteLength;if(o=f,t>=f)continue;let c=t>=a&&t<f,l=e>a&&e<=f;if(c&&l){if(t===a&&e===f){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(e-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===f){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!yr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,f=this.byteLength-n.byteLength,c=n.byteLength-1,l;for(let u=e;u<=f;u+=l){l=0;for(let h=c;h>=0;h--){let d=this.get(u+h);if(n[h]!==d){l=Math.max(1,h-a[d]);break}}if(l===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=yt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=yt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=yt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=yt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=yt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=yt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=yt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=yt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!at(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Dn={};lt(Dn,{base10:()=>Lc});var Lc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};lt(Rn,{base16:()=>Tc,base16upper:()=>Pc});var Tc=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pc=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Cn={};lt(Cn,{base2:()=>Dc});var Dc=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var kn={};lt(kn,{base256emoji:()=>Uc});var Ps=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}"),Rc=Ps.reduce((r,t,e)=>(r[e]=t,r),[]),Cc=Ps.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function kc(r){return r.reduce((t,e)=>(t+=Rc[e],t),"")}function Nc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Cc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Uc=pe({prefix:"\u{1F680}",name:"base256emoji",encode:kc,decode:Nc});var Nn={};lt(Nn,{base64:()=>Oc,base64pad:()=>Mc,base64url:()=>Fc,base64urlpad:()=>Kc});var Oc=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mc=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fc=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kc=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Un={};lt(Un,{base8:()=>zc});var zc=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var On={};lt(On,{identity:()=>qc});var qc=pe({prefix:"\0",name:"identity",encode:r=>ms(r),decode:r=>ps(r)});var dh=new TextEncoder,ph=new TextDecoder;var Kn={};lt(Kn,{sha256:()=>qe,sha512:()=>jc});function Fn({name:r,code:t,encode:e}){return new Mn(r,t,e)}var Mn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Yt(this.code,e):e.then(n=>Yt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Rs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var qe=Fn({name:"sha2-256",code:18,encode:Rs("SHA-256")}),jc=Fn({name:"sha2-512",code:19,encode:Rs("SHA-512")});var He={...On,...Cn,...Un,...Dn,...Rn,...In,...Bn,...An,...Nn,...kn},Ih={...Kn,...Pn};function ks(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Cs=ks("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),zn=ks("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Gc={utf8:Cs,"utf-8":Cs,hex:He.base16,latin1:zn,ascii:zn,binary:zn,...He},br=Gc;function $(r,t="utf8"){let e=br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function F(r,t="utf8"){let e=br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var $c=parseInt("11111",2),qn=parseInt("10000000",2),Zc=parseInt("01111111",2),Ns={0:Ve,1:Ve,2:Wc,3:Qc,4:Jc,5:Xc,6:Yc,16:Ve,22:Ve,48:Ve};function Hn(r,t={offset:0}){let e=r[t.offset]&$c;if(t.offset++,Ns[e]!=null)return Ns[e](r,t);throw new Error("No decoder for tag "+e)}function je(r,t){let e=0;if((r[t.offset]&qn)===qn){let n=r[t.offset]&Zc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Ve(r,t){je(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Hn(r,t);if(n===null)break;e.push(n)}return e}function Wc(r,t){let e=je(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Yc(r,t){let e=je(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,f=[];for(;t.offset<n;){let c=r[t.offset];if(t.offset++,f.push(c&127),c<128){f.reverse();let l=0;for(let u=0;u<f.length;u++)l+=f[u]<<u*7;a+=`.${l}`,f=[]}}return a}function Xc(r,t){return t.offset++,null}function Qc(r,t){let e=je(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Jc(r,t){let e=je(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function tu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new Y;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Vn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=tu(r.byteLength);return new Y(Uint8Array.from([t.byteLength|qn]),t)}function Us(r){let t=new Y,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new Y(Uint8Array.from([2]),Vn(t),t)}function Os(r){let t=Uint8Array.from([0]),e=new Y(t,r);return new Y(Uint8Array.from([3]),Vn(e),e)}function xr(r,t=48){let e=new Y;for(let n of r)e.append(n);return new Y(Uint8Array.from([t]),Vn(e),e)}async function Ms(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var eu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ru=Uint8Array.from([6,5,43,129,4,0,34]),nu=Uint8Array.from([6,5,43,129,4,0,35]),ou={ext:!0,kty:"EC",crv:"P-256"},su={ext:!0,kty:"EC",crv:"P-384"},iu={ext:!0,kty:"EC",crv:"P-521"},jn=32,Gn=48,$n=66;function Fs(r){let t=Hn(r);return Ks(t)}function Ks(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===jn*2+1)return n=F(t.subarray(e,e+jn),"base64url"),o=F(t.subarray(e+jn),"base64url"),new be({...ou,key_ops:["verify"],x:n,y:o});if(t.byteLength===Gn*2+1)return n=F(t.subarray(e,e+Gn),"base64url"),o=F(t.subarray(e+Gn),"base64url"),new be({...su,key_ops:["verify"],x:n,y:o});if(t.byteLength===$n*2+1)return n=F(t.subarray(e,e+$n),"base64url"),o=F(t.subarray(e+$n),"base64url"),new be({...iu,key_ops:["verify"],x:n,y:o});throw new Bt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function zs(r){return xr([Us(Uint8Array.from([1])),xr([au(r.crv)],160),xr([Os(new Y(Uint8Array.from([4]),$(r.x??"","base64url"),$(r.y??"","base64url")))],161)]).subarray()}function au(r){if(r==="P-256")return eu;if(r==="P-384")return ru;if(r==="P-521")return nu;throw new Bt(`Invalid curve ${r}`)}var be=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=zs(this.jwk)),this._raw}toMultihash(){return gt.digest(xe(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async verify(t,e,n){return Ms(this.jwk,e,t,n)}};var Xt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ee(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ge(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function rt(r,...t){if(!Ee(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Hs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ge(r.outputLen),Ge(r.blockLen)}function Se(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Vs(r,t){rt(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Ct(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function wr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function bt(r,t){return r<<32-t|r>>>t}var js=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",cu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function _t(r){if(rt(r),js)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=cu[r[e]];return t}var Rt={_0:48,_9:57,A:65,F:70,a:97,f:102};function qs(r){if(r>=Rt._0&&r<=Rt._9)return r-Rt._0;if(r>=Rt.A&&r<=Rt.F)return r-(Rt.A-10);if(r>=Rt.a&&r<=Rt.f)return r-(Rt.a-10)}function _e(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(js)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=qs(r.charCodeAt(s)),a=qs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let f=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+a}return n}function Gs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function $e(r){return typeof r=="string"&&(r=Gs(r)),rt(r),r}function dt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];rt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var we=class{};function Zn(r){let t=n=>r().update($e(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ze(r=32){if(Xt&&typeof Xt.getRandomValues=="function")return Xt.getRandomValues(new Uint8Array(r));if(Xt&&typeof Xt.randomBytes=="function")return Uint8Array.from(Xt.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function uu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),f=n?4:0,c=n?0:4;r.setUint32(t+f,i,n),r.setUint32(t+c,a,n)}function $s(r,t,e){return r&t^~r&e}function Zs(r,t,e){return r&t^r&e^t&e}var We=class extends we{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=wr(this.buffer)}update(t){Se(this),t=$e(t),rt(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=wr(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Se(this),Vs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Ct(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let u=i;u<o;u++)e[u]=0;uu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=wr(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let c=f/4,l=this.get();if(c>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<c;u++)a.setUint32(4*u,l[u],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},kt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var tt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Er=BigInt(4294967295),Ws=BigInt(32);function fu(r,t=!1){return t?{h:Number(r&Er),l:Number(r>>Ws&Er)}:{h:Number(r>>Ws&Er)|0,l:Number(r&Er)|0}}function Ys(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=fu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Wn=(r,t,e)=>r>>>e,Yn=(r,t,e)=>r<<32-e|t>>>e,Qt=(r,t,e)=>r>>>e|t<<32-e,Jt=(r,t,e)=>r<<32-e|t>>>e,Ye=(r,t,e)=>r<<64-e|t>>>e-32,Xe=(r,t,e)=>r>>>e-32|t<<64-e;function vt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Xs=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Qs=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Js=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ti=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ei=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ri=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var hu=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]),qt=new Uint32Array(64),Xn=class extends We{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:e,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[t,e,n,o,s,i,a,f]}set(t,e,n,o,s,i,a,f){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=f|0}process(t,e){for(let u=0;u<16;u++,e+=4)qt[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let h=qt[u-15],d=qt[u-2],g=bt(h,7)^bt(h,18)^h>>>3,w=bt(d,17)^bt(d,19)^d>>>10;qt[u]=w+qt[u-7]+g+qt[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:c,H:l}=this;for(let u=0;u<64;u++){let h=bt(a,6)^bt(a,11)^bt(a,25),d=l+h+$s(a,f,c)+hu[u]+qt[u]|0,w=(bt(n,2)^bt(n,13)^bt(n,22))+Zs(n,o,s)|0;l=c,c=f,f=a,a=i+d|0,i=s,s=o,o=n,n=d+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,f=f+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,f,c,l)}roundClean(){Ct(qt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ct(this.buffer)}};var ni=Ys(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),du=ni[0],pu=ni[1],Ht=new Uint32Array(80),Vt=new Uint32Array(80),Qn=class extends We{constructor(t=64){super(128,t,16,!1),this.Ah=tt[0]|0,this.Al=tt[1]|0,this.Bh=tt[2]|0,this.Bl=tt[3]|0,this.Ch=tt[4]|0,this.Cl=tt[5]|0,this.Dh=tt[6]|0,this.Dl=tt[7]|0,this.Eh=tt[8]|0,this.El=tt[9]|0,this.Fh=tt[10]|0,this.Fl=tt[11]|0,this.Gh=tt[12]|0,this.Gl=tt[13]|0,this.Hh=tt[14]|0,this.Hl=tt[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:c,El:l,Fh:u,Fl:h,Gh:d,Gl:g,Hh:w,Hl:p}=this;return[t,e,n,o,s,i,a,f,c,l,u,h,d,g,w,p]}set(t,e,n,o,s,i,a,f,c,l,u,h,d,g,w,p){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=f|0,this.Eh=c|0,this.El=l|0,this.Fh=u|0,this.Fl=h|0,this.Gh=d|0,this.Gl=g|0,this.Hh=w|0,this.Hl=p|0}process(t,e){for(let v=0;v<16;v++,e+=4)Ht[v]=t.getUint32(e),Vt[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let R=Ht[v-15]|0,b=Vt[v-15]|0,D=Qt(R,b,1)^Qt(R,b,8)^Wn(R,b,7),P=Jt(R,b,1)^Jt(R,b,8)^Yn(R,b,7),I=Ht[v-2]|0,m=Vt[v-2]|0,E=Qt(I,m,19)^Ye(I,m,61)^Wn(I,m,6),y=Jt(I,m,19)^Xe(I,m,61)^Yn(I,m,6),x=Js(P,y,Vt[v-7],Vt[v-16]),S=ti(x,D,E,Ht[v-7],Ht[v-16]);Ht[v]=S|0,Vt[v]=x|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:l,Eh:u,El:h,Fh:d,Fl:g,Gh:w,Gl:p,Hh:_,Hl:L}=this;for(let v=0;v<80;v++){let R=Qt(u,h,14)^Qt(u,h,18)^Ye(u,h,41),b=Jt(u,h,14)^Jt(u,h,18)^Xe(u,h,41),D=u&d^~u&w,P=h&g^~h&p,I=ei(L,b,P,pu[v],Vt[v]),m=ri(I,_,R,D,du[v],Ht[v]),E=I|0,y=Qt(n,o,28)^Ye(n,o,34)^Ye(n,o,39),x=Jt(n,o,28)^Xe(n,o,34)^Xe(n,o,39),S=n&s^n&a^s&a,B=o&i^o&f^i&f;_=w|0,L=p|0,w=d|0,p=g|0,d=u|0,g=h|0,{h:u,l:h}=vt(c|0,l|0,m|0,E|0),c=a|0,l=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let A=Xs(E,x,B);n=Qs(A,m,y,S),o=A|0}({h:n,l:o}=vt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=vt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=vt(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l}=vt(this.Dh|0,this.Dl|0,c|0,l|0),{h:u,l:h}=vt(this.Eh|0,this.El|0,u|0,h|0),{h:d,l:g}=vt(this.Fh|0,this.Fl|0,d|0,g|0),{h:w,l:p}=vt(this.Gh|0,this.Gl|0,w|0,p|0),{h:_,l:L}=vt(this.Hh|0,this.Hl|0,_|0,L|0),this.set(n,o,s,i,a,f,c,l,u,h,d,g,w,p,_,L)}roundClean(){Ct(Ht,Vt)}destroy(){Ct(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var oi=Zn(()=>new Xn);var si=Zn(()=>new Qn);var eo=BigInt(0),to=BigInt(1);function Nt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Qe(r){let t=r.toString(16);return t.length&1?"0"+t:t}function ii(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?eo:BigInt("0x"+r)}function ve(r){return ii(_t(r))}function te(r){return rt(r),ii(_t(Uint8Array.from(r).reverse()))}function Sr(r,t){return _e(r.toString(16).padStart(t*2,"0"))}function Ae(r,t){return Sr(r,t).reverse()}function H(r,t,e){let n;if(typeof t=="string")try{n=_e(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ee(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}var Jn=r=>typeof r=="bigint"&&eo<=r;function ai(r,t,e){return Jn(r)&&Jn(t)&&Jn(e)&&t<=r&&r<e}function jt(r,t,e,n){if(!ai(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ci(r){let t;for(t=0;r>eo;r>>=to,t+=1);return t}var ee=r=>(to<<BigInt(r))-to;function ui(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=d=>new Uint8Array(d),o=d=>Uint8Array.of(d),s=n(r),i=n(r),a=0,f=()=>{s.fill(1),i.fill(0),a=0},c=(...d)=>e(i,s,...d),l=(d=n(0))=>{i=c(o(0),d),s=c(),d.length!==0&&(i=c(o(1),d),s=c())},u=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,g=[];for(;d<t;){s=c();let w=s.slice();g.push(w),d+=s.length}return dt(...g)};return(d,g)=>{f(),l(d);let w;for(;!(w=g(u()));)l();return f(),w}}function Gt(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let f=typeof a;if(f!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${f}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function Ie(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var ct=BigInt(0),J=BigInt(1),re=BigInt(2),mu=BigInt(3),hi=BigInt(4),di=BigInt(5),pi=BigInt(8);function j(r,t){let e=r%t;return e>=ct?e:t+e}function V(r,t,e){let n=r;for(;t-- >ct;)n*=n,n%=e;return n}function fi(r,t){if(r===ct)throw new Error("invert: expected non-zero number");if(t<=ct)throw new Error("invert: expected positive modulus, got "+t);let e=j(r,t),n=t,o=ct,s=J,i=J,a=ct;for(;e!==ct;){let c=n/e,l=n%e,u=o-i*c,h=s-a*c;n=e,e=l,o=i,s=a,i=u,a=h}if(n!==J)throw new Error("invert: does not exist");return j(o,t)}function mi(r,t){let e=(r.ORDER+J)/hi,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function gu(r,t){let e=(r.ORDER-di)/pi,n=r.mul(t,re),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,re),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function yu(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-J,e=0;for(;t%re===ct;)t/=re,e++;let n=re,o=xt(r);for(;li(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return mi;let s=o.pow(n,t),i=(t+J)/re;return function(f,c){if(f.is0(c))return c;if(li(f,c)!==1)throw new Error("Cannot find square root");let l=e,u=f.mul(f.ONE,s),h=f.pow(c,t),d=f.pow(c,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let g=1,w=f.sqr(h);for(;!f.eql(w,f.ONE);)if(g++,w=f.sqr(w),g===l)throw new Error("Cannot find square root");let p=J<<BigInt(l-g-1),_=f.pow(u,p);l=g,u=f.sqr(_),h=f.mul(h,u),d=f.mul(d,_)}return d}}function bu(r){return r%hi===mu?mi:r%pi===di?gu:yu(r)}var gi=(r,t)=>(j(r,t)&J)===J,xu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ro(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=xu.reduce((n,o)=>(n[o]="function",n),t);return Gt(r,e),r}function wu(r,t,e){if(e<ct)throw new Error("invalid exponent, negatives unsupported");if(e===ct)return r.ONE;if(e===J)return t;let n=r.ONE,o=t;for(;e>ct;)e&J&&(n=r.mul(n,o)),o=r.sqr(o),e>>=J;return n}function Je(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,f)=>r.is0(a)?i:(n[f]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,f)=>r.is0(a)?i:(n[f]=r.mul(i,n[f]),r.mul(i,a)),s),n}function li(r,t){let e=(r.ORDER-J)/re,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function yi(r,t){t!==void 0&&Ge(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function xt(r,t,e=!1,n={}){if(r<=ct)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(o=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(e=l.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=yi(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,c=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ee(i),ZERO:ct,ONE:J,create:l=>j(l,r),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return ct<=l&&l<r},is0:l=>l===ct,isValidNot0:l=>!c.is0(l)&&c.isValid(l),isOdd:l=>(l&J)===J,neg:l=>j(-l,r),eql:(l,u)=>l===u,sqr:l=>j(l*l,r),add:(l,u)=>j(l+u,r),sub:(l,u)=>j(l-u,r),mul:(l,u)=>j(l*u,r),pow:(l,u)=>wu(c,l,u),div:(l,u)=>j(l*fi(u,r),r),sqrN:l=>l*l,addN:(l,u)=>l+u,subN:(l,u)=>l-u,mulN:(l,u)=>l*u,inv:l=>fi(l,r),sqrt:s||(l=>(f||(f=bu(r)),f(c,l))),toBytes:l=>e?Ae(l,a):Sr(l,a),fromBytes:l=>{if(l.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);return e?te(l):ve(l)},invertBatch:l=>Je(c,l),cmov:(l,u,h)=>h?u:l});return Object.freeze(c)}function bi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function no(r){let t=bi(r);return t+Math.ceil(t/2)}function xi(r,t,e=!1){let n=r.length,o=bi(t),s=no(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?te(r):ve(r),a=j(i,t-J)+J;return e?Ae(a,o):Sr(a,o)}var Le=BigInt(0),ne=BigInt(1);function Be(r,t){let e=t.negate();return r?e:t}function _r(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=Je(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}function _i(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function oo(r,t){_i(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ee(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function wi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),f=r>>i;a>n&&(a-=s,f+=ne);let c=t*n,l=c+Math.abs(a)-1,u=a===0,h=a<0,d=t%2!==0;return{nextN:f,offset:l,isZero:u,isNeg:h,isNegF:d,offsetF:c}}function Eu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Su(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var so=new WeakMap,vi=new WeakMap;function io(r){return vi.get(r)||1}function Ei(r){if(r!==Le)throw new Error("invalid wNAF")}function vr(r,t){return{constTimeNegate:Be,hasPrecomputes(e){return io(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Le;)n&ne&&(o=o.add(s)),s=s.double(),n>>=ne;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=oo(n,t),i=[],a=e,f=a;for(let c=0;c<o;c++){f=a,i.push(f);for(let l=1;l<s;l++)f=f.add(a),i.push(f);a=f.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=oo(e,t);for(let f=0;f<a.windows;f++){let{nextN:c,offset:l,isZero:u,isNeg:h,isNegF:d,offsetF:g}=wi(o,f,a);o=c,u?i=i.add(Be(d,n[g])):s=s.add(Be(h,n[l]))}return Ei(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=oo(e,t);for(let a=0;a<i.windows&&o!==Le;a++){let{nextN:f,offset:c,isZero:l,isNeg:u}=wi(o,a,i);if(o=f,!l){let h=n[c];s=s.add(u?h.negate():h)}}return Ei(o),s},getPrecomputes(e,n,o){let s=so.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),so.set(n,s))),s},wNAFCached(e,n,o){let s=io(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=io(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){_i(n,t),vi.set(e,n),so.delete(e)}}}function Ai(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Le||n>Le;)e&ne&&(s=s.add(o)),n&ne&&(i=i.add(o)),o=o.double(),e>>=ne,n>>=ne;return{p1:s,p2:i}}function Ar(r,t,e,n){Eu(e,r),Su(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=ci(BigInt(o)),f=1;a>12?f=a-3:a>4?f=a-2:a>0&&(f=2);let c=ee(f),l=new Array(Number(c)+1).fill(i),u=Math.floor((t.BITS-1)/f)*f,h=i;for(let d=u;d>=0;d-=f){l.fill(i);for(let w=0;w<s;w++){let p=n[w],_=Number(p>>BigInt(d)&c);l[_]=l[_].add(e[w])}let g=i;for(let w=l.length-1,p=i;w>0;w--)p=p.add(l[w]),g=g.add(p);if(h=h.add(g),d!==0)for(let w=0;w<f;w++)h=h.double()}return h}function Si(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ro(t),t}else return xt(r)}function Ir(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let f=t[a];if(!(typeof f=="bigint"&&f>Le))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Si(t.p,e.Fp),o=Si(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var At=BigInt(0),ut=BigInt(1),ao=BigInt(2),_u=BigInt(8),vu={zip215:!0};function Au(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Iu(r,t={}){let{Fp:e,Fn:n}=Ir("edwards",r,t),{h:o,n:s}=r;Gt(t,{},{uvRatio:"function"});let i=ao<<BigInt(n.BYTES*8)-ut,a=w=>e.create(w),f=t.uvRatio||((w,p)=>{try{return{isValid:!0,value:e.sqrt(e.div(w,p))}}catch{return{isValid:!1,value:At}}});if(!Au(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function c(w,p,_=!1){let L=_?ut:At;return jt("coordinate "+w,p,L,i),p}function l(w){if(!(w instanceof d))throw new Error("ExtendedPoint expected")}let u=Ie((w,p)=>{let{ex:_,ey:L,ez:v}=w,R=w.is0();p==null&&(p=R?_u:e.inv(v));let b=a(_*p),D=a(L*p),P=a(v*p);if(R)return{x:At,y:ut};if(P!==ut)throw new Error("invZ was invalid");return{x:b,y:D}}),h=Ie(w=>{let{a:p,d:_}=r;if(w.is0())throw new Error("bad point: ZERO");let{ex:L,ey:v,ez:R,et:b}=w,D=a(L*L),P=a(v*v),I=a(R*R),m=a(I*I),E=a(D*p),y=a(I*a(E+P)),x=a(m+a(_*a(D*P)));if(y!==x)throw new Error("bad point: equation left != right (1)");let S=a(L*v),B=a(R*b);if(S!==B)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(p,_,L,v){this.ex=c("x",p),this.ey=c("y",_),this.ez=c("z",L,!0),this.et=c("t",v),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof d)throw new Error("extended point not allowed");let{x:_,y:L}=p||{};return c("x",_),c("y",L),new d(_,L,ut,a(_*L))}static normalizeZ(p){return _r(d,"ez",p)}static msm(p,_){return Ar(d,n,p,_)}_setWindowSize(p){this.precompute(p)}precompute(p=8,_=!0){return g.setWindowSize(this,p),_||this.multiply(ao),this}assertValidity(){h(this)}equals(p){l(p);let{ex:_,ey:L,ez:v}=this,{ex:R,ey:b,ez:D}=p,P=a(_*D),I=a(R*v),m=a(L*D),E=a(b*v);return P===I&&m===E}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:p}=r,{ex:_,ey:L,ez:v}=this,R=a(_*_),b=a(L*L),D=a(ao*a(v*v)),P=a(p*R),I=_+L,m=a(a(I*I)-R-b),E=P+b,y=E-D,x=P-b,S=a(m*y),B=a(E*x),A=a(m*x),T=a(y*E);return new d(S,B,T,A)}add(p){l(p);let{a:_,d:L}=r,{ex:v,ey:R,ez:b,et:D}=this,{ex:P,ey:I,ez:m,et:E}=p,y=a(v*P),x=a(R*I),S=a(D*L*E),B=a(b*m),A=a((v+R)*(P+I)-y-x),T=B-S,k=B+S,C=a(x-_*y),Z=a(A*T),O=a(k*C),N=a(A*C),W=a(T*k);return new d(Z,O,W,N)}subtract(p){return this.add(p.negate())}multiply(p){let _=p;jt("scalar",_,ut,s);let{p:L,f:v}=g.wNAFCached(this,_,d.normalizeZ);return d.normalizeZ([L,v])[0]}multiplyUnsafe(p,_=d.ZERO){let L=p;return jt("scalar",L,At,s),L===At?d.ZERO:this.is0()||L===ut?this:g.wNAFCachedUnsafe(this,L,d.normalizeZ,_)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return g.wNAFCachedUnsafe(this,s).is0()}toAffine(p){return u(this,p)}clearCofactor(){return o===ut?this:this.multiplyUnsafe(o)}static fromBytes(p,_=!1){return rt(p),this.fromHex(p,_)}static fromHex(p,_=!1){let{d:L,a:v}=r,R=e.BYTES;p=H("pointHex",p,R),Nt("zip215",_);let b=p.slice(),D=p[R-1];b[R-1]=D&-129;let P=te(b),I=_?i:e.ORDER;jt("pointHex.y",P,At,I);let m=a(P*P),E=a(m-ut),y=a(L*m-v),{isValid:x,value:S}=f(E,y);if(!x)throw new Error("Point.fromHex: invalid y coordinate");let B=(S&ut)===ut,A=(D&128)!==0;if(!_&&S===At&&A)throw new Error("Point.fromHex: x=0 and x_0=1");return A!==B&&(S=a(-S)),d.fromAffine({x:S,y:P})}static fromPrivateScalar(p){return d.BASE.multiply(p)}toBytes(){let{x:p,y:_}=this.toAffine(),L=Ae(_,e.BYTES);return L[L.length-1]|=p&ut?128:0,L}toRawBytes(){return this.toBytes()}toHex(){return _t(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}d.BASE=new d(r.Gx,r.Gy,ut,a(r.Gx*r.Gy)),d.ZERO=new d(At,ut,ut,At),d.Fp=e,d.Fn=n;let g=vr(d,n.BYTES*8);return d}function Bu(r,t){Gt(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,f=t.randomBytes||Ze,c=t.adjustScalarBytes||(b=>b),l=t.domain||((b,D,P)=>{if(Nt("phflag",P),D.length||P)throw new Error("Contexts/pre-hash are not supported");return b});function u(b){return i.create(b)}function h(b){return u(te(b))}function d(b){let D=s.BYTES;b=H("private key",b,D);let P=H("hashed private key",n(b),2*D),I=c(P.slice(0,D)),m=P.slice(D,2*D),E=h(I);return{head:I,prefix:m,scalar:E}}function g(b){let{head:D,prefix:P,scalar:I}=d(b),m=o.multiply(I),E=m.toBytes();return{head:D,prefix:P,scalar:I,point:m,pointBytes:E}}function w(b){return g(b).pointBytes}function p(b=Uint8Array.of(),...D){let P=dt(...D);return h(n(l(P,H("context",b),!!e)))}function _(b,D,P={}){b=H("message",b),e&&(b=e(b));let{prefix:I,scalar:m,pointBytes:E}=g(D),y=p(P.context,I,b),x=o.multiply(y).toBytes(),S=p(P.context,x,E,b),B=u(y+S*m);jt("signature.s",B,At,a);let A=s.BYTES,T=dt(x,Ae(B,A));return H("result",T,A*2)}let L=vu;function v(b,D,P,I=L){let{context:m,zip215:E}=I,y=s.BYTES;b=H("signature",b,2*y),D=H("message",D),P=H("publicKey",P,y),E!==void 0&&Nt("zip215",E),e&&(D=e(D));let x=te(b.slice(y,2*y)),S,B,A;try{S=r.fromHex(P,E),B=r.fromHex(b.slice(0,y),E),A=o.multiplyUnsafe(x)}catch{return!1}if(!E&&S.isSmallOrder())return!1;let T=p(m,B.toBytes(),S.toBytes(),D);return B.add(S.multiplyUnsafe(T)).subtract(A).clearCofactor().is0()}return o.precompute(8),{getPublicKey:w,sign:_,verify:v,utils:{getExtendedPublicKey:g,randomPrivateKey:()=>f(s.BYTES),precompute(b=8,D=r.BASE){return D.precompute(b,!1)}},Point:r}}function Lu(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=xt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function Tu(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function Ii(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=Lu(r),o=Iu(t,e),s=Bu(o,n);return Tu(r,s)}var Dd=BigInt(0),Pu=BigInt(1),Bi=BigInt(2),Rd=BigInt(3),Du=BigInt(5),Ru=BigInt(8),Br={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ru,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Cu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Br.p,a=r*r%s*r%s,f=V(a,Bi,s)*a%s,c=V(f,Pu,s)*r%s,l=V(c,Du,s)*c%s,u=V(l,t,s)*l%s,h=V(u,e,s)*u%s,d=V(h,n,s)*h%s,g=V(d,o,s)*d%s,w=V(g,o,s)*d%s,p=V(w,t,s)*l%s;return{pow_p_5_8:V(p,Bi,s)*r%s,b2:a}}function ku(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Li=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Nu(r,t){let e=Br.p,n=j(t*t*t,e),o=j(n*n*t,e),s=Cu(r*o).pow_p_5_8,i=j(r*n*s,e),a=j(t*i*i,e),f=i,c=j(i*Li,e),l=a===r,u=a===j(-r,e),h=a===j(-r*Li,e);return l&&(i=f),(u||h)&&(i=c),gi(i,e)&&(i=j(-i,e)),{isValid:l||u,value:i}}var Uu=xt(Br.p,void 0,!0),Ou={...Br,Fp:Uu,hash:si,adjustScalarBytes:ku,uvRatio:Nu},Ti=Ii(Ou);var tr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Lr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Pi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Lr("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 Tr=Pi;var Pr=32;var co,Mu=(async()=>{try{return await Tr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Fu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Tr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Tr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ku(r,t,e){return Ti.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Di(r,t,e){return co==null&&(co=await Mu),co?Fu(r,t,e):Ku(r,t,e)}function Dr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Rr=class{type="Ed25519";raw;constructor(t){this.raw=uo(t,Pr)}toMultihash(){return gt.digest(xe(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Di(this.raw,e,t);return Dr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ci(r){return r=uo(r,Pr),new Rr(r)}function uo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Bt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var qu=Math.pow(2,7),Hu=Math.pow(2,14),Vu=Math.pow(2,21),fo=Math.pow(2,28),lo=Math.pow(2,35),ho=Math.pow(2,42),po=Math.pow(2,49),U=128,nt=127;function ot(r){if(r<qu)return 1;if(r<Hu)return 2;if(r<Vu)return 3;if(r<fo)return 4;if(r<lo)return 5;if(r<ho)return 6;if(r<po)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function mo(r,t,e=0){switch(ot(r)){case 8:t[e++]=r&255|U,r/=128;case 7:t[e++]=r&255|U,r/=128;case 6:t[e++]=r&255|U,r/=128;case 5:t[e++]=r&255|U,r/=128;case 4:t[e++]=r&255|U,r>>>=7;case 3:t[e++]=r&255|U,r>>>=7;case 2:t[e++]=r&255|U,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ju(r,t,e=0){switch(ot(r)){case 8:t.set(e++,r&255|U),r/=128;case 7:t.set(e++,r&255|U),r/=128;case 6:t.set(e++,r&255|U),r/=128;case 5:t.set(e++,r&255|U),r/=128;case 4:t.set(e++,r&255|U),r>>>=7;case 3:t.set(e++,r&255|U),r>>>=7;case 2:t.set(e++,r&255|U),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function go(r,t){let e=r[t],n=0;if(n+=e&nt,e<U||(e=r[t+1],n+=(e&nt)<<7,e<U)||(e=r[t+2],n+=(e&nt)<<14,e<U)||(e=r[t+3],n+=(e&nt)<<21,e<U)||(e=r[t+4],n+=(e&nt)*fo,e<U)||(e=r[t+5],n+=(e&nt)*lo,e<U)||(e=r[t+6],n+=(e&nt)*ho,e<U)||(e=r[t+7],n+=(e&nt)*po,e<U))return n;throw new RangeError("Could not decode varint")}function Gu(r,t){let e=r.get(t),n=0;if(n+=e&nt,e<U||(e=r.get(t+1),n+=(e&nt)<<7,e<U)||(e=r.get(t+2),n+=(e&nt)<<14,e<U)||(e=r.get(t+3),n+=(e&nt)<<21,e<U)||(e=r.get(t+4),n+=(e&nt)*fo,e<U)||(e=r.get(t+5),n+=(e&nt)*lo,e<U)||(e=r.get(t+6),n+=(e&nt)*ho,e<U)||(e=r.get(t+7),n+=(e&nt)*po,e<U))return n;throw new RangeError("Could not decode varint")}function $t(r,t,e=0){return t==null&&(t=ft(ot(r))),t instanceof Uint8Array?mo(r,t,e):ju(r,t,e)}function Ut(r,t=0){return r instanceof Uint8Array?go(r,t):Gu(r,t)}var bo=new Float32Array([-0]),Zt=new Uint8Array(bo.buffer);function ki(r,t,e){bo[0]=r,t[e]=Zt[0],t[e+1]=Zt[1],t[e+2]=Zt[2],t[e+3]=Zt[3]}function Ni(r,t){return Zt[0]=r[t],Zt[1]=r[t+1],Zt[2]=r[t+2],Zt[3]=r[t+3],bo[0]}var xo=new Float64Array([-0]),st=new Uint8Array(xo.buffer);function Ui(r,t,e){xo[0]=r,t[e]=st[0],t[e+1]=st[1],t[e+2]=st[2],t[e+3]=st[3],t[e+4]=st[4],t[e+5]=st[5],t[e+6]=st[6],t[e+7]=st[7]}function Oi(r,t){return st[0]=r[t],st[1]=r[t+1],st[2]=r[t+2],st[3]=r[t+3],st[4]=r[t+4],st[5]=r[t+5],st[6]=r[t+6],st[7]=r[t+7],xo[0]}var $u=BigInt(Number.MAX_SAFE_INTEGER),Zu=BigInt(Number.MIN_SAFE_INTEGER),pt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return oe;if(t<$u&&t>Zu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Mi&&(o=0n,++n>Mi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return oe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):oe}},oe=new pt(0,0);oe.toBigInt=function(){return 0n};oe.zzEncode=oe.zzDecode=function(){return this};oe.length=function(){return 1};var Mi=4294967296n;function Fi(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ki(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function wo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function wt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Cr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Eo=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,wt(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 wt(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw wt(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw wt(this,4);let t=Ni(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw wt(this,4);let t=Oi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw wt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ki(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw wt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw wt(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 pt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw wt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw wt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw wt(this,8);let t=Cr(this.buf,this.pos+=4),e=Cr(this.buf,this.pos+=4);return new pt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=go(this.buf,this.pos);return this.pos+=ot(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 So(r){return new Eo(r instanceof Uint8Array?r:r.subarray())}function Ot(r,t,e){let n=So(r);return t.decode(n,void 0,e)}function _o(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var se=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function vo(){}var Io=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Wu=_o();function Yu(r){return globalThis.Buffer!=null?ft(r):Wu(r)}var rr=class{len;head;tail;states;constructor(){this.len=0,this.head=new se(vo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new se(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Bo((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(kr,10,pt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=pt.fromBigInt(t);return this._push(kr,e.length(),e)}uint64Number(t){return this._push(mo,ot(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=pt.fromBigInt(t).zzEncode();return this._push(kr,e.length(),e)}sint64Number(t){let e=pt.fromNumber(t).zzEncode();return this._push(kr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ao,1,t?1:0)}fixed32(t){return this._push(er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=pt.fromBigInt(t);return this._push(er,4,e.lo)._push(er,4,e.hi)}fixed64Number(t){let e=pt.fromNumber(t);return this._push(er,4,e.lo)._push(er,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ki,4,t)}double(t){return this._push(Ui,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ao,1,0):this.uint32(e)._push(Qu,e,t)}string(t){let e=Fi(t);return e!==0?this.uint32(e)._push(wo,e,t):this._push(Ao,1,0)}fork(){return this.states=new Io(this),this.head=this.tail=new se(vo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new se(vo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Yu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ao(r,t,e){t[e]=r&255}function Xu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Bo=class extends se{next;constructor(t,e){super(Xu,t,e),this.next=void 0}};function kr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function er(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Qu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(rr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ju,t,r),this},rr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(tf,t,r),this});function Ju(r,t,e){t.set(r,e)}function tf(r,t,e){r.length<40?wo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function Lo(){return new rr}function Mt(r,t){let e=Lo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Te;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Te||(Te={}));function Nr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Pe(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Nr("enum",Te.VARINT,e,n)}function Ft(r,t){return Nr("message",Te.LENGTH_DELIMITED,r,t)}var Ur=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var mt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(mt||(mt={}));var To;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(To||(To={}));(function(r){r.codec=()=>Pe(To)})(mt||(mt={}));var nr;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),mt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=mt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Mt(e,r.codec()),r.decode=(e,n)=>Ot(e,r.codec(),n)})(nr||(nr={}));var Po;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),mt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=mt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Mt(e,r.codec()),r.decode=(e,n)=>Ot(e,r.codec(),n)})(Po||(Po={}));var Or=class extends we{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Hs(t);let n=$e(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Ct(s)}update(t){return Se(this),this.iHash.update(t),this}digestInto(t){Se(this),rt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Do=(r,t,e)=>new Or(r,t).update(e).digest();Do.create=(r,t)=>new Or(r,t);function qi(r){r.lowS!==void 0&&Nt("lowS",r.lowS),r.prehash!==void 0&&Nt("prehash",r.prehash)}var Ro=class extends Error{constructor(t=""){super(t)}},Kt={Err:Ro,_tlv:{encode:(r,t)=>{let{Err:e}=Kt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Qe(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Qe(o.length/2|128):"";return Qe(r)+s+o+t},decode(r,t){let{Err:e}=Kt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let f=o&127;if(!f)throw new e("tlv.decode(long): indefinite length not supported");if(f>4)throw new e("tlv.decode(long): byte length is too big");let c=t.subarray(n,n+f);if(c.length!==f)throw new e("tlv.decode: length bytes not complete");if(c[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of c)i=i<<8|l;if(n+=f,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Kt;if(r<or)throw new t("integer: negative integers are not allowed");let e=Qe(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Kt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ve(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Kt,o=H("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:f}=n.decode(2,s),{v:c,l}=n.decode(2,f);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(c)}},hexFromSig(r){let{_tlv:t,_int:e}=Kt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},or=BigInt(0),sr=BigInt(1),rf=BigInt(2),Mr=BigInt(3),nf=BigInt(4);function of(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function Hi(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=H("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let f=new Uint8Array(n);f.set(a,f.length-a.length),a=f}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function sf(r,t={}){let{Fp:e,Fn:n}=Ir("weierstrass",r,t),{h:o,n:s}=r;Gt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(I,m,E){let{x:y,y:x}=m.toAffine(),S=e.toBytes(y);if(Nt("isCompressed",E),E){a();let B=!e.isOdd(x);return dt(Vi(B),S)}else return dt(Uint8Array.of(4),S,e.toBytes(x))}function c(I){rt(I);let m=e.BYTES,E=m+1,y=2*m+1,x=I.length,S=I[0],B=I.subarray(1);if(x===E&&(S===2||S===3)){let A=e.fromBytes(B);if(!e.isValid(A))throw new Error("bad point: is not on curve, wrong x");let T=h(A),k;try{k=e.sqrt(T)}catch(O){let N=O instanceof Error?": "+O.message:"";throw new Error("bad point: is not on curve, sqrt error"+N)}a();let C=e.isOdd(k);return(S&1)===1!==C&&(k=e.neg(k)),{x:A,y:k}}else if(x===y&&S===4){let A=e.fromBytes(B.subarray(m*0,m*1)),T=e.fromBytes(B.subarray(m*1,m*2));if(!d(A,T))throw new Error("bad point: is not on curve");return{x:A,y:T}}else throw new Error(`bad point: got length ${x}, expected compressed=${E} or uncompressed=${y}`)}let l=t.toBytes||f,u=t.fromBytes||c,h=of(e,r.a,r.b);function d(I,m){let E=e.sqr(m),y=h(I);return e.eql(E,y)}if(!d(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let g=e.mul(e.pow(r.a,Mr),nf),w=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(g,w)))throw new Error("bad curve params: a or b");function p(I,m,E=!1){if(!e.isValid(m)||E&&e.is0(m))throw new Error(`bad point coordinate ${I}`);return m}function _(I){if(!(I instanceof b))throw new Error("ProjectivePoint expected")}let L=Ie((I,m)=>{let{px:E,py:y,pz:x}=I;if(e.eql(x,e.ONE))return{x:E,y};let S=I.is0();m==null&&(m=S?e.ONE:e.inv(x));let B=e.mul(E,m),A=e.mul(y,m),T=e.mul(x,m);if(S)return{x:e.ZERO,y:e.ZERO};if(!e.eql(T,e.ONE))throw new Error("invZ was invalid");return{x:B,y:A}}),v=Ie(I=>{if(I.is0()){if(t.allowInfinityPoint&&!e.is0(I.py))return;throw new Error("bad point: ZERO")}let{x:m,y:E}=I.toAffine();if(!e.isValid(m)||!e.isValid(E))throw new Error("bad point: x or y not field elements");if(!d(m,E))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(I,m,E,y,x){return E=new b(e.mul(E.px,I),E.py,E.pz),m=Be(y,m),E=Be(x,E),m.add(E)}class b{constructor(m,E,y){this.px=p("x",m),this.py=p("y",E,!0),this.pz=p("z",y),Object.freeze(this)}static fromAffine(m){let{x:E,y}=m||{};if(!m||!e.isValid(E)||!e.isValid(y))throw new Error("invalid affine point");if(m instanceof b)throw new Error("projective point not allowed");return e.is0(E)&&e.is0(y)?b.ZERO:new b(E,y,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){return _r(b,"pz",m)}static fromBytes(m){return rt(m),b.fromHex(m)}static fromHex(m){let E=b.fromAffine(u(H("pointHex",m)));return E.assertValidity(),E}static fromPrivateKey(m){let E=Hi(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return b.BASE.multiply(E(m))}static msm(m,E){return Ar(b,n,m,E)}precompute(m=8,E=!0){return P.setWindowSize(this,m),E||this.multiply(Mr),this}_setWindowSize(m){this.precompute(m)}assertValidity(){v(this)}hasEvenY(){let{y:m}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(m)}equals(m){_(m);let{px:E,py:y,pz:x}=this,{px:S,py:B,pz:A}=m,T=e.eql(e.mul(E,A),e.mul(S,x)),k=e.eql(e.mul(y,A),e.mul(B,x));return T&&k}negate(){return new b(this.px,e.neg(this.py),this.pz)}double(){let{a:m,b:E}=r,y=e.mul(E,Mr),{px:x,py:S,pz:B}=this,A=e.ZERO,T=e.ZERO,k=e.ZERO,C=e.mul(x,x),Z=e.mul(S,S),O=e.mul(B,B),N=e.mul(x,S);return N=e.add(N,N),k=e.mul(x,B),k=e.add(k,k),A=e.mul(m,k),T=e.mul(y,O),T=e.add(A,T),A=e.sub(Z,T),T=e.add(Z,T),T=e.mul(A,T),A=e.mul(N,A),k=e.mul(y,k),O=e.mul(m,O),N=e.sub(C,O),N=e.mul(m,N),N=e.add(N,k),k=e.add(C,C),C=e.add(k,C),C=e.add(C,O),C=e.mul(C,N),T=e.add(T,C),O=e.mul(S,B),O=e.add(O,O),C=e.mul(O,N),A=e.sub(A,C),k=e.mul(O,Z),k=e.add(k,k),k=e.add(k,k),new b(A,T,k)}add(m){_(m);let{px:E,py:y,pz:x}=this,{px:S,py:B,pz:A}=m,T=e.ZERO,k=e.ZERO,C=e.ZERO,Z=r.a,O=e.mul(r.b,Mr),N=e.mul(E,S),W=e.mul(y,B),X=e.mul(x,A),et=e.add(E,y),K=e.add(S,B);et=e.mul(et,K),K=e.add(N,W),et=e.sub(et,K),K=e.add(E,x);let it=e.add(S,A);return K=e.mul(K,it),it=e.add(N,X),K=e.sub(K,it),it=e.add(y,x),T=e.add(B,A),it=e.mul(it,T),T=e.add(W,X),it=e.sub(it,T),C=e.mul(Z,K),T=e.mul(O,X),C=e.add(T,C),T=e.sub(W,C),C=e.add(W,C),k=e.mul(T,C),W=e.add(N,N),W=e.add(W,N),X=e.mul(Z,X),K=e.mul(O,K),W=e.add(W,X),X=e.sub(N,X),X=e.mul(Z,X),K=e.add(K,X),N=e.mul(W,K),k=e.add(k,N),N=e.mul(it,K),T=e.mul(et,T),T=e.sub(T,N),N=e.mul(et,W),C=e.mul(it,C),C=e.add(C,N),new b(T,k,C)}subtract(m){return this.add(m.negate())}is0(){return this.equals(b.ZERO)}multiply(m){let{endo:E}=t;if(!n.isValidNot0(m))throw new Error("invalid scalar: out of range");let y,x,S=B=>P.wNAFCached(this,B,b.normalizeZ);if(E){let{k1neg:B,k1:A,k2neg:T,k2:k}=E.splitScalar(m),{p:C,f:Z}=S(A),{p:O,f:N}=S(k);x=Z.add(N),y=R(E.beta,C,O,B,T)}else{let{p:B,f:A}=S(m);y=B,x=A}return b.normalizeZ([y,x])[0]}multiplyUnsafe(m){let{endo:E}=t,y=this;if(!n.isValid(m))throw new Error("invalid scalar: out of range");if(m===or||y.is0())return b.ZERO;if(m===sr)return y;if(P.hasPrecomputes(this))return this.multiply(m);if(E){let{k1neg:x,k1:S,k2neg:B,k2:A}=E.splitScalar(m),{p1:T,p2:k}=Ai(b,y,S,A);return R(E.beta,T,k,x,B)}else return P.wNAFCachedUnsafe(y,m)}multiplyAndAddUnsafe(m,E,y){let x=this.multiplyUnsafe(E).add(m.multiplyUnsafe(y));return x.is0()?void 0:x}toAffine(m){return L(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return o===sr?!0:m?m(b,this):P.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:m}=t;return o===sr?this:m?m(b,this):this.multiplyUnsafe(o)}toBytes(m=!0){return Nt("isCompressed",m),this.assertValidity(),l(b,this,m)}toRawBytes(m=!0){return this.toBytes(m)}toHex(m=!0){return _t(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(r.Gx,r.Gy,e.ONE),b.ZERO=new b(e.ZERO,e.ONE,e.ZERO),b.Fp=e,b.Fn=n;let D=n.BITS,P=vr(b,t.endo?Math.ceil(D/2):D);return b}function Vi(r){return Uint8Array.of(r?2:3)}function af(r,t,e={}){Gt(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||Ze,o=t.hmac||((y,...x)=>Do(t.hash,y,dt(...x))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:f}=i;function c(y){let x=a>>sr;return y>x}function l(y){return c(y)?i.neg(y):y}function u(y,x){if(!i.isValidNot0(x))throw new Error(`invalid signature ${y}: out of range 1..CURVE.n`)}class h{constructor(x,S,B){u("r",x),u("s",S),this.r=x,this.s=S,B!=null&&(this.recovery=B),Object.freeze(this)}static fromCompact(x){let S=i.BYTES,B=H("compactSignature",x,S*2);return new h(i.fromBytes(B.subarray(0,S)),i.fromBytes(B.subarray(S,S*2)))}static fromDER(x){let{r:S,s:B}=Kt.toSig(H("DER",x));return new h(S,B)}assertValidity(){}addRecoveryBit(x){return new h(this.r,this.s,x)}recoverPublicKey(x){let S=s.ORDER,{r:B,s:A,recovery:T}=this;if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");if(a*rf<S&&T>1)throw new Error("recovery id is ambiguous for h>1 curve");let C=T===2||T===3?B+a:B;if(!s.isValid(C))throw new Error("recovery id 2 or 3 invalid");let Z=s.toBytes(C),O=r.fromHex(dt(Vi((T&1)===0),Z)),N=i.inv(C),W=v(H("msgHash",x)),X=i.create(-W*N),et=i.create(A*N),K=r.BASE.multiplyUnsafe(X).add(O.multiplyUnsafe(et));if(K.is0())throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return c(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i.neg(this.s),this.recovery):this}toBytes(x){if(x==="compact")return dt(i.toBytes(this.r),i.toBytes(this.s));if(x==="der")return _e(Kt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return _t(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return _t(this.toBytes("compact"))}}let d=Hi(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),g={isValidPrivateKey(y){try{return d(y),!0}catch{return!1}},normPrivateKeyToScalar:d,randomPrivateKey:()=>{let y=a;return xi(n(no(y)),y)},precompute(y=8,x=r.BASE){return x.precompute(y,!1)}};function w(y,x=!0){return r.fromPrivateKey(y).toBytes(x)}function p(y){if(typeof y=="bigint")return!1;if(y instanceof r)return!0;let S=H("key",y).length,B=s.BYTES,A=B+1,T=2*B+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===A))return S===A||S===T}function _(y,x,S=!0){if(p(y)===!0)throw new Error("first arg must be private key");if(p(x)===!1)throw new Error("second arg must be public key");return r.fromHex(x).multiply(d(y)).toBytes(S)}let L=t.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let x=ve(y),S=y.length*8-f;return S>0?x>>BigInt(S):x},v=t.bits2int_modN||function(y){return i.create(L(y))},R=ee(f);function b(y){return jt("num < 2^"+f,y,or,R),i.toBytes(y)}function D(y,x,S=P){if(["recovered","canonical"].some(et=>et in S))throw new Error("sign() legacy options not supported");let{hash:B}=t,{lowS:A,prehash:T,extraEntropy:k}=S;A==null&&(A=!0),y=H("msgHash",y),qi(S),T&&(y=H("prehashed msgHash",B(y)));let C=v(y),Z=d(x),O=[b(Z),b(C)];if(k!=null&&k!==!1){let et=k===!0?n(s.BYTES):k;O.push(H("extraEntropy",et))}let N=dt(...O),W=C;function X(et){let K=L(et);if(!i.isValidNot0(K))return;let it=i.inv(K),Ue=r.BASE.multiply(K).toAffine(),he=i.create(Ue.x);if(he===or)return;let Wt=i.create(it*i.create(W+he*Z));if(Wt===or)return;let xn=(Ue.x===he?0:2)|Number(Ue.y&sr),de=Wt;return A&&c(Wt)&&(de=l(Wt),xn^=1),new h(he,de,xn)}return{seed:N,k2sig:X}}let P={lowS:t.lowS,prehash:!1},I={lowS:t.lowS,prehash:!1};function m(y,x,S=P){let{seed:B,k2sig:A}=D(y,x,S);return ui(t.hash.outputLen,i.BYTES,o)(B,A)}r.BASE.precompute(8);function E(y,x,S,B=I){let A=y;x=H("msgHash",x),S=H("publicKey",S),qi(B);let{lowS:T,prehash:k,format:C}=B;if("strict"in B)throw new Error("options.strict was renamed to lowS");if(C!==void 0&&!["compact","der","js"].includes(C))throw new Error('format must be "compact", "der" or "js"');let Z=typeof A=="string"||Ee(A),O=!Z&&!C&&typeof A=="object"&&A!==null&&typeof A.r=="bigint"&&typeof A.s=="bigint";if(!Z&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let N,W;try{if(O)if(C===void 0||C==="js")N=new h(A.r,A.s);else throw new Error("invalid format");if(Z){try{C!=="compact"&&(N=h.fromDER(A))}catch(de){if(!(de instanceof Kt.Err))throw de}!N&&C!=="der"&&(N=h.fromCompact(A))}W=r.fromHex(S)}catch{return!1}if(!N||T&&N.hasHighS())return!1;k&&(x=t.hash(x));let{r:X,s:et}=N,K=v(x),it=i.inv(et),Ue=i.create(K*it),he=i.create(X*it),Wt=r.BASE.multiplyUnsafe(Ue).add(W.multiplyUnsafe(he));return Wt.is0()?!1:i.create(Wt.x)===X}return Object.freeze({getPublicKey:w,getSharedSecret:_,sign:m,verify:E,utils:g,Point:r,Signature:h})}function cf(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=xt(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function uf(r){let{CURVE:t,curveOpts:e}=cf(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function ff(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function ji(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=uf(r),o=sf(t,e),s=af(o,n,e);return ff(r,s)}function Gi(r,t){let e=n=>ji({...r,hash:n});return{...e(t),create:e}}var Fr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Xp=BigInt(0),lf=BigInt(1),Co=BigInt(2),$i=(r,t)=>(r+t/Co)/t;function hf(r){let t=Fr.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),f=BigInt(88),c=r*r*r%t,l=c*c*r%t,u=V(l,e,t)*l%t,h=V(u,e,t)*l%t,d=V(h,Co,t)*c%t,g=V(d,o,t)*d%t,w=V(g,s,t)*g%t,p=V(w,a,t)*w%t,_=V(p,f,t)*p%t,L=V(_,a,t)*w%t,v=V(L,e,t)*l%t,R=V(v,i,t)*g%t,b=V(R,n,t)*c%t,D=V(b,Co,t);if(!ko.eql(ko.sqr(D),r))throw new Error("Cannot find square root");return D}var ko=xt(Fr.p,void 0,void 0,{sqrt:hf}),De=Gi({...Fr,Fp:ko,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Fr.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-lf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=$i(s*r,t),f=$i(-n*r,t),c=j(r-a*e-f*o,t),l=j(-a*n-f*s,t),u=c>i,h=l>i;if(u&&(c=t-c),h&&(l=t-l),c>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:c,k2neg:h,k2:l}}}},oi);function Zi(r,t,e,n){let o=qe.digest(e instanceof Uint8Array?e:e.subarray());if(Dr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),De.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new tr(String(s))});try{return n?.signal?.throwIfAborted(),De.verify(t,o.digest,r)}catch(s){throw new tr(String(s))}}var Kr=class{type="secp256k1";raw;_key;constructor(t){this._key=Yi(t),this.raw=Wi(this._key)}toMultihash(){return gt.digest(xe(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){return Zi(this._key,e,t,n)}};function Xi(r){return new Kr(r)}function Wi(r){return De.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Yi(r){try{return De.ProjectivePoint.fromHex(r),r}catch(t){throw new dr(String(t))}}function Qi(r){let{Type:t,Data:e}=nr.decode(r.digest),n=e??new Uint8Array;switch(t){case mt.Ed25519:return Ci(n);case mt.secp256k1:return Xi(n);case mt.ECDSA:return Fs(n);default:throw new Oe}}function xe(r){return nr.encode({Type:mt[r.type],Data:r.raw})}var Ji=Symbol.for("nodejs.util.inspect.custom"),df=114,ir=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()})`}[wn]=!0;toString(){return this.string==null&&(this.string=z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Q.createV1(df,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return at(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return at(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ji](){return`PeerId(${this.toString()})`}},zr=class extends ir{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},qr=class extends ir{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Hr=class extends ir{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},pf=2336,Vr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=gt.digest($(this.url))}[Ji](){return`PeerId(${this.url})`}[wn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Q.createV1(pf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=F(t)),t.toString()===this.toString())}};function jr(r){if(gf(r))return new zr({multihash:r});if(mf(r))try{let t=Qi(r);if(t.type==="Ed25519")return new qr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Hr({multihash:r,publicKey:t})}catch{let e=F(r.digest);return new Vr(new URL(e))}throw new pr("Supplied PeerID Multihash is invalid")}function mf(r){return r.code===gt.code}function gf(r){return r.code===qe.code}function No(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Gr(r){let t=Pt(z.decode(`z${r}`));return jr(t)}var $r=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return No(this.set.entries(),t=>{let e=Gr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Gr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return No(this.set.values(),t=>Gr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Uo(){return new $r}var Oo={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},ea=new globalThis.TextEncoder;function yf(r,t){let e=Oo[t],n=ta[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function bf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Oo[t],o=ta[t],s=r;for(;s.length>0;){let i=ea.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function Mo(r,{size:t=32,utf8Buffer:e}={}){if(!Oo[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return bf(r,t,e);r=ea.encode(r)}return yf(r,t)}var ar={hash:r=>Number(Mo(r,{size:32})),hashV:(r,t)=>xf(ar.hash(r,t))};function xf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),$(t,"base16")}var Fo=64,Et=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Fo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=yt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?at(this.fp,t.fp):!1}};function ie(r,t){return Math.floor(Math.random()*(t-r))+r}var ae=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Et))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Et))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof Et))throw new TypeError("Invalid Fingerprint");let e=ie(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Et))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var wf=500,cr=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??ie(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=$(t));let e=new Et(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ae(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ae(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[ie(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ae(this.bucketSize));for(let a=0;a<wf;a++){let f=this.buckets[i].swap(e);if(f!=null&&(i=(i^f.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ae(this.bucketSize)),this.buckets[i].add(f)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=$(t));let e=new Et(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=$(t));let e=new Et(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Ef={1:.5,2:.84,4:.95,8:.98};function Sf(r=.001){return r>.002?2:r>1e-5?4:8}function ra(r,t=.001){let e=Sf(t),n=Ef[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Fo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Zr=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??ie(0,Math.pow(2,10)),this.filterSeries=[new cr({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 e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new cr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=$(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=$(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function Ko(r,t=.001,e){return new Zr({...ra(r,t),...e??{}})}var Wr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let f=a==="0",c=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let h=Number.parseInt(u,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(s*=t,s+=l,s>c||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&f&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var na=45,_f=15,Re=new Wr;function Yr(r){if(!(r.length>_f))return Re.new(r).parseWith(()=>Re.readIPv4Addr())}function Xr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>na))return Re.new(r).parseWith(()=>Re.readIPv6Addr())}function ce(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>na)return;let e=Re.new(r).parseWith(()=>Re.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function oa(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function sa(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function zo(r){switch(r.length){case ue:return r.join(".");case fe:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function ia(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function aa(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var ue=4,fe=16,Om=parseInt("0xFFFF",16),vf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function ur(r,t){t.length===fe&&r.length===ue&&oa(t,0,11)&&(t=t.slice(12)),t.length===ue&&r.length===fe&&sa(r,vf,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function ca(r,t){if(typeof t=="string"&&(t=ce(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function qo(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=ue,o=Yr(t);if(o==null&&(n=fe,o=Xr(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=Ho(s,8*n);return{network:ur(o,i),mask:i}}function Ho(r,t){if(t!==8*ue&&t!==8*fe)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var Ce=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=qo(t));else{let n=ce(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=ce(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ho(o,8*n.length);this.network=ur(n,this.mask)}}contains(t){return ca({network:this.network,mask:this.mask},t)}toString(){let t=ia(this.mask),e=t!==-1?String(t):aa(this.mask);return zo(this.network)+"/"+e}};function ua(r,t){return new Ce(r).contains(t)}var Af=41;function fa(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===Af)return ua("2000::/3",e)}catch{}return!1}function Qr(r){return!!Yr(r)}function Jr(r){return!!Xr(r)}function tn(r){return!!ce(r)}var ha=Fa(la(),1),If=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Bf=If.map(r=>new ha.Netmask(r));function Vo(r){for(let t of Bf)if(t.contains(r))return!0;return!1}function Lf(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Tf(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return Vo(o)}function Pf(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Df(r){let t=r.split(":"),e=t[t.length-1];return Vo(e)}function Rf(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function da(r){return Qr(r)?Vo(r):Lf(r)?Tf(r):Pf(r)?Df(r):Jr(r)?Rf(r):void 0}function pa(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function jo(r){try{if(!pa(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:da(t)??!1}catch{}return!0}function St(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var en=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}},ke=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new en(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new en(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Go=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ma(r={}){return Cf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Cf(r,t){t=t??{};let e=t.onEnd,n=new ke,o,s,i,a=St(),f=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,_)=>{s=L=>{s=null,n.push(L);try{p(r(n))}catch(v){_(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=St()})}},c=p=>s!=null?s(p):(n.push(p),o),l=p=>(n=new ke,s!=null?s({error:p}):(n.push({error:p}),o)),u=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:p})},h=p=>i?o:(i=!0,p!=null?l(p):c({done:!0})),d=()=>(n=new ke,h(),{done:!0}),g=p=>(h(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:d,throw:g,push:u,end:h,get readableLength(){return n.size},onEmpty:async p=>{let _=p?.signal;if(_?.throwIfAborted(),n.isEmpty())return;let L,v;_!=null&&(L=new Promise((R,b)=>{v=()=>{b(new Go)},_.addEventListener("abort",v)}));try{await Promise.race([a.promise,L])}finally{v!=null&&_!=null&&_?.removeEventListener("abort",v)}}},e==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(p){return w.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return w.return(),e!=null&&(e(),e=void 0),{done:!0}},push:u,end(p){return w.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return w.readableLength},onEmpty:p=>w.onEmpty(p)},o}var $o=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function rn(r,t,e,n){let o=new $o(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",l),r.removeEventListener(t,f),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,c)}let f=u=>{try{if(n?.filter?.(u)===!1)return}catch(h){a(),i(h);return}a(),s(u)},c=u=>{a(),i(u.detail)},l=()=>{a(),i(o)};e?.addEventListener("abort",l),r.addEventListener(t,f),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,c)})}function Zo(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var nn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var on=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function le(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new on(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new on(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var sn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=St(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new It)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function kf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var an=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=kf(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new It),this.cleanup())}async join(t={}){let e=new sn(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await le(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var cn=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=Zo(this.emitEmpty.bind(this),1),this.emitIdle=Zo(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new nn;let n=new an(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("error",{detail:o}),this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new It)}),this.clear()}async onEmpty(t){this.size!==0&&await rn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await rn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await rn(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=ma({objectMode:!0}),n=f=>{f!=null?this.abort():this.clear(),e.end(f)},o=f=>{f.detail!=null&&e.push(f.detail)},s=f=>{n(f.detail)},i=()=>{n()},a=()=>{n(new It("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var un=class extends cn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function fn(r){let t=new globalThis.AbortController;function e(){t.abort();for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}function ga(r,t,e){let n,o;function s(){let a={signal:o.signal};if(e?.timeout!=null){let f=fn([o.signal,AbortSignal.timeout(e.timeout)]);a.signal=f}Promise.resolve().then(async()=>{await r(a)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{setInterval:a=>{t!==a&&(t=a,n!=null&&(clearTimeout(n),n=setTimeout(s,t)))},setTimeout:a=>{e??={},e.timeout=a},start:()=>{i||(i=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),i=!1}}}var Wo=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ya(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Wo({name:t,metrics:e}):n=new Map,n}var ba=Qr,Nf=Jr,Yo=function(r){let t=0;if(r=r.toString().trim(),ba(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Nf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ba(e[n]),i;s&&(i=Yo(e[n]),e[n]=F(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,F(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},xa=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ne={},Xo={},Of=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Of.forEach(r=>{let t=Mf(...r);Xo[t.code]=t,Ne[t.name]=t});function Mf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function M(r){if(typeof r=="number"){if(Xo[r]!=null)return Xo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ne[r]!=null)return Ne[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var ey=M("ip4"),ry=M("ip6"),ny=M("ipcidr");function es(r,t){switch(M(r).code){case 4:case 41:return Kf(t);case 42:return ts(t);case 43:return F(t,"base10");case 6:case 273:case 33:case 132:return Sa(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ts(t);case 421:return Vf(t);case 444:return Ea(t);case 445:return Ea(t);case 466:return Hf(t);case 481:return globalThis.encodeURIComponent(ts(t));default:return F(t,"base16")}}function rs(r,t){switch(M(r).code){case 4:return wa(t);case 41:return wa(t);case 42:return Jo(t);case 43:return $(t,"base10");case 6:case 273:case 33:case 132:return ns(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Jo(t);case 421:return zf(t);case 444:return jf(t);case 445:return Gf(t);case 466:return qf(t);case 481:return Jo(globalThis.decodeURIComponent(t));default:return $(t,"base16")}}var Qo=Object.values(He).map(r=>r.decoder),Ff=function(){let r=Qo[0].or(Qo[1]);return Qo.slice(2).forEach(t=>r=r.or(t)),r}();function wa(r){if(!tn(r))throw new Error("invalid ip address");return Yo(r)}function Kf(r){let t=xa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!tn(t))throw new Error("invalid ip address");return t}function ns(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Sa(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Jo(r){let t=$(r),e=Uint8Array.from($t(t.length));return ht([e,t],e.length+t.length)}function ts(r){let t=Ut(r);if(r=r.slice(ot(t)),r.length!==t)throw new Error("inconsistent lengths");return F(r)}function zf(r){let t;r[0]==="Q"||r[0]==="1"?t=Pt(z.decode(`z${r}`)).bytes:t=Q.parse(r).multihash.bytes;let e=Uint8Array.from($t(t.length));return ht([e,t],e.length+t.length)}function qf(r){let t=Ff.decode(r),e=Uint8Array.from($t(t.length));return ht([e,t],e.length+t.length)}function Hf(r){let t=Ut(r),e=r.slice(ot(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+F(e,"base64url")}function Vf(r){let t=Ut(r),e=r.slice(ot(t));if(e.length!==t)throw new Error("inconsistent lengths");return F(e,"base58btc")}function jf(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Tt.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=ns(n);return ht([e,o],e.length+o.length)}function Gf(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Tt.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=ns(n);return ht([e,o],e.length+o.length)}function Ea(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=F(t,"base32"),o=Sa(e);return`${n}:${o}`}function _a(r){r=os(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=M(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new ln("invalid address: "+r);if(a.path===!0){n=os(o.slice(s).join("/")),t.push([a.code,rs(a.code,n)]),e.push([a.code,n]);break}let f=rs(a.code,o[s]);t.push([a.code,f]),e.push([a.code,es(a.code,f)])}return{string:va(e),bytes:hn(t),tuples:t,stringTuples:e,path:n}}function ss(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Ut(r,o),i=ot(s),a=M(s),f=$f(a,r.slice(o+i));if(f===0){t.push([s]),e.push([s]),o+=i;continue}let c=r.slice(o+i,o+i+f);if(o+=f+i,o>r.length)throw new ln("Invalid address Uint8Array: "+F(r,"base16"));t.push([s,c]);let l=es(s,c);if(e.push([s,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:va(e),tuples:t,stringTuples:e,path:n}}function va(r){let t=[];return r.map(e=>{let n=M(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),os(t.join("/"))}function hn(r){return ht(r.map(t=>{let e=M(t[0]),n=Uint8Array.from($t(e.code));return t.length>1&&t[1]!=null&&(n=ht([n,t[1]])),n}))}function $f(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Ut(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ot(e)}}function os(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var ln=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Zf=Symbol.for("nodejs.util.inspect.custom"),as=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Wf=[M("dns").code,M("dns4").code,M("dns6").code,M("dnsaddr").code],is=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},dn=class r{bytes;#t;#e;#r;#n;[as]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=ss(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=_a(t)}else if(Ia(t))e=ss(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=M("tcp"),a=M("udp"),f=M("ip4"),c=M("ip6"),l=M("dns6"),u=M("ip6zone");for(let[d,g]of this.stringTuples())d===u.code&&(s=`%${g??""}`),Wf.includes(d)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${g??""}${s}`,t=d===l.code?6:4),(d===i.code||d===a.code)&&(e=M(d).name==="tcp"?"tcp":"udp",o=parseInt(g??"")),(d===f.code||d===c.code)&&(e=M(d).name==="tcp"?"tcp":"udp",n=`${g??""}${s}`,t=d===c.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#e.map(([t])=>Object.assign({},M(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>M(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(hn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ne.p2p.code&&t.push([n,o]),n===Ne["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?F(z.decode(`z${n}`),"base58btc"):F(Q.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return at(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Aa.get(e.name);if(n==null)throw new is(`no available resolver for ${e.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(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Zf](){return`Multiaddr(${this.#t})`}};var Aa=new Map;function Ia(r){return!!r?.[as]}function lr(r){return new dn(r)}var cs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=St(),this.haveNext=St()}[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=St(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=St(),await le(this.readNext.promise,e?.signal,e)}};function Ba(){return new cs}var pn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function La(r,t){let e=Ba();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new Y;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:f,value:c}=await le(n.next(),i?.signal);return f===!0?null:c}for(;o.byteLength<i.bytes;){let{value:f,done:c}=await le(n.next(),i?.signal);if(c===!0)throw new pn("unexpected end of input");o.append(f)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var mn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},gn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},yn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ta(r,t={}){let e=La(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=ot(t.maxDataLength));let n=t?.lengthDecoder??Ut,o=t?.lengthEncoder??$t;return{read:async i=>{let a=-1,f=new Y;for(;;){f.append(await e.read({...i,bytes:1}));try{a=n(f)}catch(c){if(c instanceof RangeError)continue;throw c}if(a<0)throw new mn("Invalid message length");if(t?.maxLengthLength!=null&&f.byteLength>t.maxLengthLength)throw new yn("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new gn("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new Y(o(i.byteLength),i),a)},writeV:async(i,a)=>{let f=new Y(...i.flatMap(c=>[o(c.byteLength),c]));await e.write(f,a)},unwrap:()=>e.unwrap()}}function us(r,t){let e=Ta(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Pa="libp2p",Da="autonat",Ra="1.0.0";var q;(function(r){let t;(function(c){c.DIAL="DIAL",c.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(c){c[c.DIAL=0]="DIAL",c[c.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(c){c.codec=()=>Pe(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(c){c.OK="OK",c.E_DIAL_ERROR="E_DIAL_ERROR",c.E_DIAL_REFUSED="E_DIAL_REFUSED",c.E_BAD_REQUEST="E_BAD_REQUEST",c.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(c){c[c.OK=0]="OK",c[c.E_DIAL_ERROR=100]="E_DIAL_ERROR",c[c.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",c[c.E_BAD_REQUEST=200]="E_BAD_REQUEST",c[c.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(c){c.codec=()=>Pe(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(c){let l;c.codec=()=>(l==null&&(l=Ft((u,h,d={})=>{if(d.lengthDelimited!==!1&&h.fork(),u.id!=null&&(h.uint32(10),h.bytes(u.id)),u.addrs!=null)for(let g of u.addrs)h.uint32(18),h.bytes(g);d.lengthDelimited!==!1&&h.ldelim()},(u,h,d={})=>{let g={addrs:[]},w=h==null?u.len:u.pos+h;for(;u.pos<w;){let p=u.uint32();switch(p>>>3){case 1:{g.id=u.bytes();break}case 2:{if(d.limits?.addrs!=null&&g.addrs.length===d.limits.addrs)throw new Ur('Decode error - map field "addrs" had too many elements');g.addrs.push(u.bytes());break}default:{u.skipType(p&7);break}}}return g})),l),c.encode=u=>Mt(u,c.codec()),c.decode=(u,h)=>Ot(u,c.codec(),h)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(c){let l;c.codec=()=>(l==null&&(l=Ft((u,h,d={})=>{d.lengthDelimited!==!1&&h.fork(),u.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(u.peer,h)),d.lengthDelimited!==!1&&h.ldelim()},(u,h,d={})=>{let g={},w=h==null?u.len:u.pos+h;for(;u.pos<w;){let p=u.uint32();switch(p>>>3){case 1:{g.peer=r.PeerInfo.codec().decode(u,u.uint32(),{limits:d.limits?.peer});break}default:{u.skipType(p&7);break}}}return g})),l),c.encode=u=>Mt(u,c.codec()),c.decode=(u,h)=>Ot(u,c.codec(),h)})(i=r.Dial||(r.Dial={}));let a;(function(c){let l;c.codec=()=>(l==null&&(l=Ft((u,h,d={})=>{d.lengthDelimited!==!1&&h.fork(),u.status!=null&&(h.uint32(8),r.ResponseStatus.codec().encode(u.status,h)),u.statusText!=null&&(h.uint32(18),h.string(u.statusText)),u.addr!=null&&(h.uint32(26),h.bytes(u.addr)),d.lengthDelimited!==!1&&h.ldelim()},(u,h,d={})=>{let g={},w=h==null?u.len:u.pos+h;for(;u.pos<w;){let p=u.uint32();switch(p>>>3){case 1:{g.status=r.ResponseStatus.codec().decode(u);break}case 2:{g.statusText=u.string();break}case 3:{g.addr=u.bytes();break}default:{u.skipType(p&7);break}}}return g})),l),c.encode=u=>Mt(u,c.codec()),c.decode=(u,h)=>Ot(u,c.codec(),h)})(a=r.DialResponse||(r.DialResponse={}));let f;r.codec=()=>(f==null&&(f=Ft((c,l,u={})=>{u.lengthDelimited!==!1&&l.fork(),c.type!=null&&(l.uint32(8),r.MessageType.codec().encode(c.type,l)),c.dial!=null&&(l.uint32(18),r.Dial.codec().encode(c.dial,l)),c.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(c.dialResponse,l)),u.lengthDelimited!==!1&&l.ldelim()},(c,l,u={})=>{let h={},d=l==null?c.len:c.pos+l;for(;c.pos<d;){let g=c.uint32();switch(g>>>3){case 1:{h.type=r.MessageType.codec().decode(c);break}case 2:{h.dial=r.Dial.codec().decode(c,c.uint32(),{limits:u.limits?.dial});break}case 3:{h.dialResponse=r.DialResponse.codec().decode(c,c.uint32(),{limits:u.limits?.dialResponse});break}default:{c.skipType(g&7);break}}}return h})),f),r.encode=c=>Mt(c,r.codec()),r.decode=(c,l)=>Ot(c,r.codec(),l)})(q||(q={}));var el=4,rl=8,bn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${e.protocolPrefix??Pa}/${Da}/${Ra}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.connectionThreshold=e.connectionThreshold??80,this.maxMessageSize=e.maxMessageSize??8192,this.dialResults=ya({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=ga(this.findRandomPeers.bind(this),6e4),this.addressFilter=Ko(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ls]=["@libp2p/autonat"];get[hs](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream - %e",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=fn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t){let e=AbortSignal.timeout(this.timeout);let n=us(t.stream,{maxDataLength:this.maxMessageSize}).pb(q);try{let o=await n.read({signal:e}),s=await this.handleAutonatMessage(o,t.connection,{signal:e});await n.write(s,{signal:e}),await n.unwrap().unwrap().close({signal:e})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.stream.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(u=>u.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:q.MessageType.DIAL_RESPONSE,dialResponse:{status:q.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("PeerId missing from message"),{type:q.MessageType.DIAL_RESPONSE,dialResponse:{status:q.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let u=Pt(a.id);i=jr(u)}catch(u){return this.log.error("invalid PeerId - %e",u),{type:q.MessageType.DIAL_RESPONSE,dialResponse:{status:q.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:q.MessageType.DIAL_RESPONSE,dialResponse:{status:q.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let f=a.addrs.map(u=>lr(u)).filter(u=>{let h=u.toOptions();return jo(u)?!1:h.host!==e.remoteAddr.toOptions().host?(this.log.trace("not dialing %a - target host did not match remote host %a",u,e.remoteAddr),!1):o.includes(h.host)?!1:this.components.transportManager.dialTransportForMultiaddr(u)==null?(this.log.trace("not dialing %a - transport unsupported",u),!1):!0}).map(u=>(u.getPeerId()==null&&(u=u.encapsulate(`/p2p/${i.toString()}`)),u));if(f.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:q.MessageType.DIAL_RESPONSE,dialResponse:{status:q.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",f.map(u=>u.toString()).join(", "),i);let c="",l=f[0];for(let u of f){let h;l=u;try{if(h=await this.components.connectionManager.openConnection(u,n),!h.remoteAddr.equals(u))throw this.log.error("tried to dial %a but dialed %a",u,h.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,u),{type:q.MessageType.DIAL_RESPONSE,dialResponse:{status:q.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(M("p2p").code).bytes}}}catch(d){this.log.error("could not dial %p - %e",i,d),c=d.message}finally{h!=null&&await h.close()}}return{type:q.MessageType.DIAL_RESPONSE,dialResponse:{status:q.ResponseStatus.E_DIAL_ERROR,statusText:c,addr:l.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||o.multiaddr.toOptions().family===6&&(!e||!fa(o.multiaddr))||jo(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:Uo(),queue:new un({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>i.toOptions().family===6),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %p to verify multiaddr %s",t.remotePeer,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=us(i).pb(q),[,f]=await Promise.all([a.write({type:q.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(f.type!==q.MessageType.DIAL_RESPONSE||f.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,f);return}let c=f.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,c),c!==q.ResponseStatus.OK&&c!==q.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,f.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),c===q.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else c===q.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===el&&this.confirmAddress(o),o.failure===rl&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=t.toOptions();return e.family===4?e.host.split(".")[0].padStart(3,"0"):e.host.split(":")[0].padStart(4,"0")}};function nl(r={}){return t=>new bn(t,r)}return Ka(ol);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|