@libp2p/autonat 2.0.27 → 2.0.28-71267286
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/package.json +9 -9
- package/dist/typedoc-urls.json +0 -8
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PAutonat=(()=>{var la=Object.create;var or=Object.defineProperty;var ha=Object.getOwnPropertyDescriptor;var da=Object.getOwnPropertyNames;var pa=Object.getPrototypeOf,ma=Object.prototype.hasOwnProperty;var ga=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)or(r,e,{get:t[e],enumerable:!0})},is=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of da(t))!ma.call(r,o)&&o!==e&&or(r,o,{get:()=>t[o],enumerable:!(n=ha(t,o))||n.enumerable});return r};var ba=(r,t,e)=>(e=r!=null?la(pa(r)):{},is(t||!r||!r.__esModule?or(e,"default",{value:r,enumerable:!0}):e,r)),xa=r=>is(or({},"__esModule",{value:!0}),r);var Ci=ga(rr=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,l,f,h;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[u,l,f,h].join(".")},i=function(c){var u,l,f,h,g,b;for(u=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}b=t(c),g=b[0],l=b[1],c=c.substring(l),u.push(g)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var u,l,f,h,g;for(h=0,u=10,l="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,u=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,u=8,l="7")),g=f;f<c.length;){if("0"<=c[f]&&c[f]<=l)h=h*u+(e(c[f])-n)>>>0;else if(u===16)if("a"<=c[f]&&c[f]<="f")h=h*u+(10+e(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*u+(10+e(c[f])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===g)throw new Error("empty octet");return[h,f]},r=function(){function c(u,l){var f,h,g,b;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(b=u.split("/",2),u=b[0],l=b[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(x){throw f=x,new Error("Invalid mask: "+l)}for(h=g=32;g>=0;h=--g)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(u)&this.maskLong)>>>0}catch(x){throw f=x,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+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 c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,f,h;for(h=i(this.first),f=i(this.last),l=0;h<=f;)u(a(h),h,l),l++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),rr.ip2long=i,rr.long2ip=a,rr.Netmask=r}).call(rr)});var Kf={};dt(Kf,{autoNAT:()=>Hf});var hn=Symbol.for("@libp2p/peer-id");var Pt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Ce=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 ir=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 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 as=Symbol.for("@libp2p/service-capabilities"),cs=Symbol.for("@libp2p/service-dependencies");var bn={};dt(bn,{base58btc:()=>W,base58flickr:()=>_a});var bl=new Uint8Array(0);function us(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Nt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function fs(r){return new TextEncoder().encode(r)}function ls(r){return new TextDecoder().decode(r)}function ya(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),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 x=0,d=0,w=0,v=b.length;w!==v&&b[w]===0;)w++,x++;for(var m=(v-w)*l+1>>>0,A=new Uint8Array(m);w!==v;){for(var R=b[w],P=0,I=m-1;(R!==0||P<d)&&I!==-1;I--,P++)R+=256*A[I]>>>0,A[I]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");d=P,w++}for(var T=m-d;T!==m&&A[T]===0;)T++;for(var B=c.repeat(x);T<m;++T)B+=r.charAt(A[T]);return B}function h(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var x=0;if(b[x]!==" "){for(var d=0,w=0;b[x]===c;)d++,x++;for(var v=(b.length-x)*u+1>>>0,m=new Uint8Array(v);b[x];){var A=e[b.charCodeAt(x)];if(A===255)return;for(var R=0,P=v-1;(A!==0||R<w)&&P!==-1;P--,R++)A+=a*m[P]>>>0,m[P]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");w=R,x++}if(b[x]!==" "){for(var I=v-w;I!==v&&m[I]===0;)I++;for(var T=new Uint8Array(d+(v-I)),B=d;I!==v;)T[B++]=m[I++];return T}}}function g(b){var x=h(b);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:g}}var wa=ya,Ea=wa,ds=Ea;var dn=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 ps(this,t)}},mn=class{decoders;constructor(t){this.decoders=t}or(t){return ps(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 ps(r,t){return new mn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var gn=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 dn(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 we({name:r,prefix:t,encode:e,decode:n}){return new gn(r,t,e,n)}function $t({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ds(e,r);return we({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function va(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),a=0,c=0,u=0;for(let l=0;l<s;++l){let f=o[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,a+=e,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Sa(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return we({prefix:t,name:r,encode(o){return Sa(o,n,e)},decode(o){return va(o,n,e,r)}})}var W=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_a=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xn={};dt(xn,{base32:()=>Dt,base32hex:()=>La,base32hexpad:()=>Ra,base32hexpadupper:()=>Pa,base32hexupper:()=>Ta,base32pad:()=>Ia,base32padupper:()=>Ba,base32upper:()=>Aa,base32z:()=>Na});var Dt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Aa=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ia=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ba=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),La=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ta=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ra=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Pa=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Na=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yn={};dt(yn,{base36:()=>Fe,base36upper:()=>Da});var Fe=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Da=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ka=bs,ms=128,Ua=127,Ca=~Ua,Oa=Math.pow(2,31);function bs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Oa;)t[e++]=r&255|ms,r/=128;for(;r&Ca;)t[e++]=r&255|ms,r>>>=7;return t[e]=r|0,bs.bytes=e-n+1,t}var Fa=wn,Ma=128,gs=127;function wn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw wn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&gs)<<o:(i&gs)*Math.pow(2,o),o+=7}while(i>=Ma);return wn.bytes=s-n,e}var za=Math.pow(2,7),qa=Math.pow(2,14),Va=Math.pow(2,21),Ha=Math.pow(2,28),Ka=Math.pow(2,35),Ga=Math.pow(2,42),ja=Math.pow(2,49),Za=Math.pow(2,56),$a=Math.pow(2,63),Wa=function(r){return r<za?1:r<qa?2:r<Va?3:r<Ha?4:r<Ka?5:r<Ga?6:r<ja?7:r<Za?8:r<$a?9:10},Xa={encode:ka,decode:Fa,encodingLength:Wa},Ya=Xa,Me=Ya;function ze(r,t=0){return[Me.decode(r,t),Me.decode.bytes]}function Ee(r,t,e=0){return Me.encode(r,t,e),t}function ve(r){return Me.encodingLength(r)}function se(r,t){let e=t.byteLength,n=ve(r),o=n+ve(e),s=new Uint8Array(o+e);return Ee(r,s,0),Ee(e,s,n),s.set(t,o),new Se(r,e,t,s)}function kt(r){let t=Nt(r),[e,n]=ze(t),[o,s]=ze(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Se(e,o,i,t)}function xs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&us(r.bytes,e.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ys(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ja(e,En(r),t??W.encoder);default:return tc(e,En(r),t??Dt.encoder)}}var ws=new WeakMap;function En(r){let t=ws.get(r);if(t==null){let e=new Map;return ws.set(r,e),e}return t}var at=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!==qe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ec)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=se(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&&xs(t.multihash,n.multihash)}toString(t){return ys(this,t)}toJSON(){return{"/":ys(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??Es(n,o,s.bytes))}else if(e[rc]===!0){let{version:n,multihash:o,code:s}=e,i=kt(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!==qe)throw new Error(`Version 0 CID must use dag-pb (code: ${qe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Es(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,qe,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Nt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Se(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]=ze(t.subarray(e));return e+=h,f},o=n(),s=qe;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=Qa(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 En(s).set(n,t),s}};function Qa(r,t){switch(r[0]){case"Q":{let e=t??W;return[W.prefix,e.decode(`${W.prefix}${r}`)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}case Dt.prefix:{let e=t??Dt;return[Dt.prefix,e.decode(r)]}case Fe.prefix:{let e=t??Fe;return[Fe.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 Ja(r,t,e){let{prefix:n}=e;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function tc(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 qe=112,ec=18;function Es(r,t,e){let n=ve(r),o=n+ve(t),s=new Uint8Array(o+e.byteLength);return Ee(r,s,0),Ee(t,s,n),s.set(e,o),s}var rc=Symbol.for("@ipld/js-cid/CID");var vn={};dt(vn,{identity:()=>Ct});var vs=0,nc="identity",Ss=Nt;function oc(r){return se(vs,Ss(r))}var Ct={code:vs,name:nc,encode:Ss,digest:oc};function bt(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 _s(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function sc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function _e(r,...t){if(!sc(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 As(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");_s(r.outputLen),_s(r.blockLen)}function Ae(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 Is(r,t){_e(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ie=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ur(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Et(r,t){return r<<32-t|r>>>t}function Bs(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Ve(r){return typeof r=="string"&&(r=Bs(r)),_e(r),r}function Sn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];_e(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Ie=class{clone(){return this._cloneInto()}};function fr(r){let t=n=>r().update(Ve(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function lr(r=32){if(ie&&typeof ie.getRandomValues=="function")return ie.getRandomValues(new Uint8Array(r));if(ie&&typeof ie.randomBytes=="function")return ie.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function ic(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function Ls(r,t,e){return r&t^~r&e}function Ts(r,t,e){return r&t^r&e^t&e}var Be=class extends Ie{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=ur(this.buffer)}update(t){Ae(this);let{view:e,buffer:n,blockLen:o}=this;t=Ve(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=ur(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ae(this),Is(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;ic(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=ur(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;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.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var hr=BigInt(4294967295),_n=BigInt(32);function Rs(r,t=!1){return t?{h:Number(r&hr),l:Number(r>>_n&hr)}:{h:Number(r>>_n&hr)|0,l:Number(r&hr)|0}}function ac(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Rs(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var cc=(r,t)=>BigInt(r>>>0)<<_n|BigInt(t>>>0),uc=(r,t,e)=>r>>>e,fc=(r,t,e)=>r<<32-e|t>>>e,lc=(r,t,e)=>r>>>e|t<<32-e,hc=(r,t,e)=>r<<32-e|t>>>e,dc=(r,t,e)=>r<<64-e|t>>>e-32,pc=(r,t,e)=>r>>>e-32|t<<64-e,mc=(r,t)=>t,gc=(r,t)=>r,bc=(r,t,e)=>r<<e|t>>>32-e,xc=(r,t,e)=>t<<e|r>>>32-e,yc=(r,t,e)=>t<<e-32|r>>>64-e,wc=(r,t,e)=>r<<e-32|t>>>64-e;function Ec(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var vc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Sc=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,_c=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ac=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ic=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Bc=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Lc={fromBig:Rs,split:ac,toBig:cc,shrSH:uc,shrSL:fc,rotrSH:lc,rotrSL:hc,rotrBH:dc,rotrBL:pc,rotr32H:mc,rotr32L:gc,rotlSH:bc,rotlSL:xc,rotlBH:yc,rotlBL:wc,add:Ec,add3L:vc,add3H:Sc,add4L:_c,add4H:Ac,add5H:Bc,add5L:Ic},U=Lc;var[Tc,Rc]=U.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Wt=new Uint32Array(80),Xt=new Uint32Array(80),An=class extends Be{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:h,Gh:g,Gl:b,Hh:x,Hl:d}=this;return[t,e,n,o,s,i,a,c,u,l,f,h,g,b,x,d]}set(t,e,n,o,s,i,a,c,u,l,f,h,g,b,x,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=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=g|0,this.Gl=b|0,this.Hh=x|0,this.Hl=d|0}process(t,e){for(let m=0;m<16;m++,e+=4)Wt[m]=t.getUint32(e),Xt[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let A=Wt[m-15]|0,R=Xt[m-15]|0,P=U.rotrSH(A,R,1)^U.rotrSH(A,R,8)^U.shrSH(A,R,7),I=U.rotrSL(A,R,1)^U.rotrSL(A,R,8)^U.shrSL(A,R,7),T=Wt[m-2]|0,B=Xt[m-2]|0,j=U.rotrSH(T,B,19)^U.rotrBH(T,B,61)^U.shrSH(T,B,6),M=U.rotrSL(T,B,19)^U.rotrBL(T,B,61)^U.shrSL(T,B,6),O=U.add4L(I,M,Xt[m-7],Xt[m-16]),Q=U.add4H(O,P,j,Wt[m-7],Wt[m-16]);Wt[m]=Q|0,Xt[m]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:h,Fh:g,Fl:b,Gh:x,Gl:d,Hh:w,Hl:v}=this;for(let m=0;m<80;m++){let A=U.rotrSH(f,h,14)^U.rotrSH(f,h,18)^U.rotrBH(f,h,41),R=U.rotrSL(f,h,14)^U.rotrSL(f,h,18)^U.rotrBL(f,h,41),P=f&g^~f&x,I=h&b^~h&d,T=U.add5L(v,R,I,Rc[m],Xt[m]),B=U.add5H(T,w,A,P,Tc[m],Wt[m]),j=T|0,M=U.rotrSH(n,o,28)^U.rotrBH(n,o,34)^U.rotrBH(n,o,39),O=U.rotrSL(n,o,28)^U.rotrBL(n,o,34)^U.rotrBL(n,o,39),Q=n&s^n&a^s&a,S=o&i^o&c^i&c;w=x|0,v=d|0,x=g|0,d=b|0,g=f|0,b=h|0,{h:f,l:h}=U.add(u|0,l|0,B|0,j|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let L=U.add3L(j,O,S);n=U.add3H(L,B,M,Q),o=L|0}({h:n,l:o}=U.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=U.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=U.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=U.add(this.Eh|0,this.El|0,f|0,h|0),{h:g,l:b}=U.add(this.Fh|0,this.Fl|0,g|0,b|0),{h:x,l:d}=U.add(this.Gh|0,this.Gl|0,x|0,d|0),{h:w,l:v}=U.add(this.Hh|0,this.Hl|0,w|0,v|0),this.set(n,o,s,i,a,c,u,l,f,h,g,b,x,d,w,v)}roundClean(){Wt.fill(0),Xt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ps=fr(()=>new An);var mr={};dt(mr,{aInRange:()=>pt,abool:()=>vt,abytes:()=>Le,bitGet:()=>Cc,bitLen:()=>Tn,bitMask:()=>Ke,bitSet:()=>Oc,bytesToHex:()=>Ft,bytesToNumberBE:()=>Mt,bytesToNumberLE:()=>Qt,concatBytes:()=>zt,createHmacDrbg:()=>Rn,ensureBytes:()=>X,equalBytes:()=>kc,hexToBytes:()=>ce,hexToNumber:()=>Ln,inRange:()=>He,isBytes:()=>Yt,memoized:()=>fe,notImplemented:()=>Mc,numberToBytesBE:()=>Jt,numberToBytesLE:()=>ue,numberToHexUnpadded:()=>ae,numberToVarBytesBE:()=>Dc,utf8ToBytes:()=>Uc,validateObject:()=>Tt});var dr=BigInt(0),pr=BigInt(1),Pc=BigInt(2);function Yt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Le(r){if(!Yt(r))throw new Error("Uint8Array expected")}function vt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Nc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Ft(r){Le(r);let t="";for(let e=0;e<r.length;e++)t+=Nc[r[e]];return t}function ae(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Ln(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?dr:BigInt("0x"+r)}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ns(r){if(r>=Ot._0&&r<=Ot._9)return r-Ot._0;if(r>=Ot.A&&r<=Ot.F)return r-(Ot.A-10);if(r>=Ot.a&&r<=Ot.f)return r-(Ot.a-10)}function ce(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Ns(r.charCodeAt(s)),a=Ns(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Mt(r){return Ln(Ft(r))}function Qt(r){return Le(r),Ln(Ft(Uint8Array.from(r).reverse()))}function Jt(r,t){return ce(r.toString(16).padStart(t*2,"0"))}function ue(r,t){return Jt(r,t).reverse()}function Dc(r){return ce(ae(r))}function X(r,t,e){let n;if(typeof t=="string")try{n=ce(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Yt(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function zt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Le(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function kc(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Uc(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var In=r=>typeof r=="bigint"&&dr<=r;function He(r,t,e){return In(r)&&In(t)&&In(e)&&t<=r&&r<e}function pt(r,t,e,n){if(!He(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Tn(r){let t;for(t=0;r>dr;r>>=pr,t+=1);return t}function Cc(r,t){return r>>BigInt(t)&pr}function Oc(r,t,e){return r|(e?pr:dr)<<BigInt(t)}var Ke=r=>(Pc<<BigInt(r-1))-pr,Bn=r=>new Uint8Array(r),Ds=r=>Uint8Array.from(r);function Rn(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=Bn(r),o=Bn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=Bn())=>{o=a(Ds([0]),f),n=a(),f.length!==0&&(o=a(Ds([1]),f),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=a();let g=n.slice();h.push(g),f+=n.length}return zt(...h)};return(f,h)=>{i(),c(f);let g;for(;!(g=h(u()));)c();return i(),g}}var Fc={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Yt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Tt(r,t,e={}){let n=(o,s,i)=>{let a=Fc[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var Mc=()=>{throw new Error("not implemented")};function fe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var J=BigInt(0),Z=BigInt(1),le=BigInt(2),zc=BigInt(3),Pn=BigInt(4),ks=BigInt(5),Us=BigInt(8),qc=BigInt(9),Vc=BigInt(16);function H(r,t){let e=r%t;return e>=J?e:t+e}function Hc(r,t,e){if(t<J)throw new Error("invalid exponent, negatives unsupported");if(e<=J)throw new Error("invalid modulus");if(e===Z)return J;let n=Z;for(;t>J;)t&Z&&(n=n*r%e),r=r*r%e,t>>=Z;return n}function $(r,t,e){let n=r;for(;t-- >J;)n*=n,n%=e;return n}function gr(r,t){if(r===J)throw new Error("invert: expected non-zero number");if(t<=J)throw new Error("invert: expected positive modulus, got "+t);let e=H(r,t),n=t,o=J,s=Z,i=Z,a=J;for(;e!==J;){let u=n/e,l=n%e,f=o-i*u,h=s-a*u;n=e,e=l,o=i,s=a,i=f,a=h}if(n!==Z)throw new Error("invert: does not exist");return H(o,t)}function Kc(r){let t=(r-Z)/le,e,n,o;for(e=r-Z,n=0;e%le===J;e/=le,n++);for(o=le;o<r&&Hc(o,t,r)!==r-Z;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+Z)/Pn;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let s=(e+Z)/le;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,o),e),f=a.pow(c,s),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let g=1;for(let x=a.sqr(h);g<u&&!a.eql(x,a.ONE);g++)x=a.sqr(x);let b=a.pow(l,Z<<BigInt(u-g-1));l=a.sqr(b),f=a.mul(f,b),h=a.mul(h,l),u=g}return f}}function Gc(r){if(r%Pn===zc){let t=(r+Z)/Pn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%Us===ks){let t=(r-ks)/Us;return function(n,o){let s=n.mul(o,le),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,le),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%Vc,Kc(r)}var Cs=(r,t)=>(H(r,t)&Z)===Z,jc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Nn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=jc.reduce((n,o)=>(n[o]="function",n),t);return Tt(r,e)}function Zc(r,t,e){if(e<J)throw new Error("invalid exponent, negatives unsupported");if(e===J)return r.ONE;if(e===Z)return t;let n=r.ONE,o=t;for(;e>J;)e&Z&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Z;return n}function $c(r,t){let e=new Array(t.length),n=t.reduce((s,i,a)=>r.is0(i)?s:(e[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,a)=>r.is0(i)?s:(e[a]=r.mul(s,e[a]),r.mul(s,i)),o),e}function Dn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function te(r,t,e=!1,n={}){if(r<=J)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Dn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:Ke(o),ZERO:J,ONE:Z,create:c=>H(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return J<=c&&c<r},is0:c=>c===J,isOdd:c=>(c&Z)===Z,neg:c=>H(-c,r),eql:(c,u)=>c===u,sqr:c=>H(c*c,r),add:(c,u)=>H(c+u,r),sub:(c,u)=>H(c-u,r),mul:(c,u)=>H(c*u,r),pow:(c,u)=>Zc(a,c,u),div:(c,u)=>H(c*gr(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>gr(c,r),sqrt:n.sqrt||(c=>(i||(i=Gc(r)),i(a,c))),invertBatch:c=>$c(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>e?ue(c,s):Jt(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?Qt(c):Mt(c)}});return Object.freeze(a)}function Os(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 kn(r){let t=Os(r);return t+Math.ceil(t/2)}function Fs(r,t,e=!1){let n=r.length,o=Os(t),s=kn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Qt(r):Mt(r),a=H(i,t-Z)+Z;return e?ue(a,o):Jt(a,o)}var Ms=BigInt(0),br=BigInt(1);function Un(r,t){let e=t.negate();return r?e:t}function zs(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Cn(r,t){zs(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Wc(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 Xc(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 On=new WeakMap,qs=new WeakMap;function Fn(r){return qs.get(r)||1}function xr(r,t){return{constTimeNegate:Un,hasPrecomputes(e){return Fn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Ms;)n&br&&(o=o.add(s)),s=s.double(),n>>=br;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Cn(n,t),i=[],a=e,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let l=1;l<s;l++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=Cn(e,t),a=r.ZERO,c=r.BASE,u=BigInt(2**e-1),l=2**e,f=BigInt(e);for(let h=0;h<s;h++){let g=h*i,b=Number(o&u);o>>=f,b>i&&(b-=l,o+=br);let x=g,d=g+Math.abs(b)-1,w=h%2!==0,v=b<0;b===0?c=c.add(Un(w,n[x])):a=a.add(Un(v,n[d]))}return{p:a,f:c}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:a}=Cn(e,t),c=BigInt(2**e-1),u=2**e,l=BigInt(e);for(let f=0;f<i;f++){let h=f*a;if(o===Ms)break;let g=Number(o&c);if(o>>=l,g>a&&(g-=u,o+=br),g===0)continue;let b=n[h+Math.abs(g)-1];g<0&&(b=b.negate()),s=s.add(b)}return s},getPrecomputes(e,n,o){let s=On.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&On.set(n,o(s))),s},wNAFCached(e,n,o){let s=Fn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Fn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){zs(n,t),qs.set(e,n),On.delete(e)}}}function yr(r,t,e,n){if(Wc(e,r),Xc(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Tn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=(1<<i)-1,c=new Array(a+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,l=o;for(let f=u;f>=0;f-=i){c.fill(o);for(let g=0;g<n.length;g++){let b=n[g],x=Number(b>>BigInt(f)&BigInt(a));c[x]=c[x].add(e[g])}let h=o;for(let g=c.length-1,b=o;g>0;g--)b=b.add(c[g]),h=h.add(b);if(l=l.add(h),f!==0)for(let g=0;g<i;g++)l=l.double()}return l}function Ge(r){return Nn(r.Fp),Tt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Dn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var St=BigInt(0),mt=BigInt(1),wr=BigInt(2),Yc=BigInt(8),Qc={zip215:!0};function Jc(r){let t=Ge(r);return Tt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Vs(r){let t=Jc(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,u=wr<<BigInt(a*8)-mt,l=e.create,f=te(t.n,t.nBitLength),h=t.uvRatio||((y,p)=>{try{return{isValid:!0,value:e.sqrt(y*e.inv(p))}}catch{return{isValid:!1,value:St}}}),g=t.adjustScalarBytes||(y=>y),b=t.domain||((y,p,E)=>{if(vt("phflag",E),p.length||E)throw new Error("Contexts/pre-hash are not supported");return y});function x(y,p){pt("coordinate "+y,p,St,u)}function d(y){if(!(y instanceof m))throw new Error("ExtendedPoint expected")}let w=fe((y,p)=>{let{ex:E,ey:_,ez:N}=y,D=y.is0();p==null&&(p=D?Yc:e.inv(N));let C=l(E*p),F=l(_*p),k=l(N*p);if(D)return{x:St,y:mt};if(k!==mt)throw new Error("invZ was invalid");return{x:C,y:F}}),v=fe(y=>{let{a:p,d:E}=t;if(y.is0())throw new Error("bad point: ZERO");let{ex:_,ey:N,ez:D,et:C}=y,F=l(_*_),k=l(N*N),q=l(D*D),K=l(q*q),rt=l(F*p),nt=l(q*l(rt+k)),st=l(K+l(E*l(F*k)));if(nt!==st)throw new Error("bad point: equation left != right (1)");let it=l(_*N),ht=l(D*C);if(it!==ht)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,E,_,N){this.ex=p,this.ey=E,this.ez=_,this.et=N,x("x",p),x("y",E),x("z",_),x("t",N),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");let{x:E,y:_}=p||{};return x("x",E),x("y",_),new m(E,_,mt,l(E*_))}static normalizeZ(p){let E=e.invertBatch(p.map(_=>_.ez));return p.map((_,N)=>_.toAffine(E[N])).map(m.fromAffine)}static msm(p,E){return yr(m,f,p,E)}_setWindowSize(p){P.setWindowSize(this,p)}assertValidity(){v(this)}equals(p){d(p);let{ex:E,ey:_,ez:N}=this,{ex:D,ey:C,ez:F}=p,k=l(E*F),q=l(D*N),K=l(_*F),rt=l(C*N);return k===q&&K===rt}is0(){return this.equals(m.ZERO)}negate(){return new m(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:p}=t,{ex:E,ey:_,ez:N}=this,D=l(E*E),C=l(_*_),F=l(wr*l(N*N)),k=l(p*D),q=E+_,K=l(l(q*q)-D-C),rt=k+C,nt=rt-F,st=k-C,it=l(K*nt),ht=l(rt*st),lt=l(K*st),Lt=l(nt*rt);return new m(it,ht,Lt,lt)}add(p){d(p);let{a:E,d:_}=t,{ex:N,ey:D,ez:C,et:F}=this,{ex:k,ey:q,ez:K,et:rt}=p;if(E===BigInt(-1)){let Jo=l((D-N)*(q+k)),ts=l((D+N)*(q-k)),ln=l(ts-Jo);if(ln===St)return this.double();let es=l(C*wr*rt),rs=l(F*wr*K),ns=rs+es,os=ts+Jo,ss=rs-es,aa=l(ns*ln),ca=l(os*ss),ua=l(ns*ss),fa=l(ln*os);return new m(aa,ca,fa,ua)}let nt=l(N*k),st=l(D*q),it=l(F*_*rt),ht=l(C*K),lt=l((N+D)*(k+q)-nt-st),Lt=ht-it,Rt=ht+it,Ue=l(st-E*nt),na=l(lt*Lt),oa=l(Rt*Ue),sa=l(lt*Ue),ia=l(Lt*Rt);return new m(na,oa,ia,sa)}subtract(p){return this.add(p.negate())}wNAF(p){return P.wNAFCached(this,p,m.normalizeZ)}multiply(p){let E=p;pt("scalar",E,mt,n);let{p:_,f:N}=this.wNAF(E);return m.normalizeZ([_,N])[0]}multiplyUnsafe(p,E=m.ZERO){let _=p;return pt("scalar",_,St,n),_===St?R:this.is0()||_===mt?this:P.wNAFCachedUnsafe(this,_,m.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return P.unsafeLadder(this,n).is0()}toAffine(p){return w(this,p)}clearCofactor(){let{h:p}=t;return p===mt?this:this.multiplyUnsafe(p)}static fromHex(p,E=!1){let{d:_,a:N}=t,D=e.BYTES;p=X("pointHex",p,D),vt("zip215",E);let C=p.slice(),F=p[D-1];C[D-1]=F&-129;let k=Qt(C),q=E?u:e.ORDER;pt("pointHex.y",k,St,q);let K=l(k*k),rt=l(K-mt),nt=l(_*K-N),{isValid:st,value:it}=h(rt,nt);if(!st)throw new Error("Point.fromHex: invalid y coordinate");let ht=(it&mt)===mt,lt=(F&128)!==0;if(!E&&it===St&<)throw new Error("Point.fromHex: x=0 and x_0=1");return lt!==ht&&(it=l(-it)),m.fromAffine({x:it,y:k})}static fromPrivateKey(p){return B(p).point}toRawBytes(){let{x:p,y:E}=this.toAffine(),_=ue(E,e.BYTES);return _[_.length-1]|=p&mt?128:0,_}toHex(){return Ft(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,mt,l(t.Gx*t.Gy)),m.ZERO=new m(St,mt,mt,St);let{BASE:A,ZERO:R}=m,P=xr(m,a*8);function I(y){return H(y,n)}function T(y){return I(Qt(y))}function B(y){let p=e.BYTES;y=X("private key",y,p);let E=X("hashed private key",s(y),2*p),_=g(E.slice(0,p)),N=E.slice(p,2*p),D=T(_),C=A.multiply(D),F=C.toRawBytes();return{head:_,prefix:N,scalar:D,point:C,pointBytes:F}}function j(y){return B(y).pointBytes}function M(y=new Uint8Array,...p){let E=zt(...p);return T(s(b(E,X("context",y),!!o)))}function O(y,p,E={}){y=X("message",y),o&&(y=o(y));let{prefix:_,scalar:N,pointBytes:D}=B(p),C=M(E.context,_,y),F=A.multiply(C).toRawBytes(),k=M(E.context,F,D,y),q=I(C+k*N);pt("signature.s",q,St,n);let K=zt(F,ue(q,e.BYTES));return X("result",K,e.BYTES*2)}let Q=Qc;function S(y,p,E,_=Q){let{context:N,zip215:D}=_,C=e.BYTES;y=X("signature",y,2*C),p=X("message",p),E=X("publicKey",E,C),D!==void 0&&vt("zip215",D),o&&(p=o(p));let F=Qt(y.slice(C,2*C)),k,q,K;try{k=m.fromHex(E,D),q=m.fromHex(y.slice(0,C),D),K=A.multiplyUnsafe(F)}catch{return!1}if(!D&&k.isSmallOrder())return!1;let rt=M(N,q.toRawBytes(),k.toRawBytes(),p);return q.add(k.multiplyUnsafe(rt)).subtract(K).clearCofactor().equals(m.ZERO)}return A._setWindowSize(8),{CURVE:t,getPublicKey:j,sign:O,verify:S,ExtendedPoint:m,utils:{getExtendedPublicKey:B,randomPrivateKey:()=>i(e.BYTES),precompute(y=8,p=m.BASE){return p._setWindowSize(y),p.multiply(BigInt(3)),p}}}}var Mn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Hs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),uh=BigInt(0),tu=BigInt(1),Ks=BigInt(2),fh=BigInt(3),eu=BigInt(5),ru=BigInt(8);function nu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Mn,a=r*r%s*r%s,c=$(a,Ks,s)*a%s,u=$(c,tu,s)*r%s,l=$(u,eu,s)*u%s,f=$(l,t,s)*l%s,h=$(f,e,s)*f%s,g=$(h,n,s)*h%s,b=$(g,o,s)*g%s,x=$(b,o,s)*g%s,d=$(x,t,s)*l%s;return{pow_p_5_8:$(d,Ks,s)*r%s,b2:a}}function ou(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function su(r,t){let e=Mn,n=H(t*t*t,e),o=H(n*n*t,e),s=nu(r*o).pow_p_5_8,i=H(r*n*s,e),a=H(t*i*i,e),c=i,u=H(i*Hs,e),l=a===r,f=a===H(-r,e),h=a===H(-r*Hs,e);return l&&(i=c),(f||h)&&(i=u),Cs(i,e)&&(i=H(-i,e)),{isValid:l||f,value:i}}var iu=te(Mn,void 0,!0),au={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:iu,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:ru,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ps,randomBytes:lr,adjustScalarBytes:ou,uvRatio:su},Gs=Vs(au);var Er=32;function js(r,t,e){return Gs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var vr=class{type="Ed25519";raw;constructor(t){this.raw=zn(t,Er)}toMultihash(){return Ct.digest(Sr(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return js(this.raw,e,t)}};function $s(r){return r=zn(r,Er),new vr(r)}function zn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Ce(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function _t(r=0){return new Uint8Array(r)}function gt(r=0){return new Uint8Array(r)}var uu=Math.pow(2,7),fu=Math.pow(2,14),lu=Math.pow(2,21),qn=Math.pow(2,28),Vn=Math.pow(2,35),Hn=Math.pow(2,42),Kn=Math.pow(2,49),z=128,ct=127;function ut(r){if(r<uu)return 1;if(r<fu)return 2;if(r<lu)return 3;if(r<qn)return 4;if(r<Vn)return 5;if(r<Hn)return 6;if(r<Kn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Gn(r,t,e=0){switch(ut(r)){case 8:t[e++]=r&255|z,r/=128;case 7:t[e++]=r&255|z,r/=128;case 6:t[e++]=r&255|z,r/=128;case 5:t[e++]=r&255|z,r/=128;case 4:t[e++]=r&255|z,r>>>=7;case 3:t[e++]=r&255|z,r>>>=7;case 2:t[e++]=r&255|z,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function hu(r,t,e=0){switch(ut(r)){case 8:t.set(e++,r&255|z),r/=128;case 7:t.set(e++,r&255|z),r/=128;case 6:t.set(e++,r&255|z),r/=128;case 5:t.set(e++,r&255|z),r/=128;case 4:t.set(e++,r&255|z),r>>>=7;case 3:t.set(e++,r&255|z),r>>>=7;case 2:t.set(e++,r&255|z),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function jn(r,t){let e=r[t],n=0;if(n+=e&ct,e<z||(e=r[t+1],n+=(e&ct)<<7,e<z)||(e=r[t+2],n+=(e&ct)<<14,e<z)||(e=r[t+3],n+=(e&ct)<<21,e<z)||(e=r[t+4],n+=(e&ct)*qn,e<z)||(e=r[t+5],n+=(e&ct)*Vn,e<z)||(e=r[t+6],n+=(e&ct)*Hn,e<z)||(e=r[t+7],n+=(e&ct)*Kn,e<z))return n;throw new RangeError("Could not decode varint")}function du(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<z||(e=r.get(t+1),n+=(e&ct)<<7,e<z)||(e=r.get(t+2),n+=(e&ct)<<14,e<z)||(e=r.get(t+3),n+=(e&ct)<<21,e<z)||(e=r.get(t+4),n+=(e&ct)*qn,e<z)||(e=r.get(t+5),n+=(e&ct)*Vn,e<z)||(e=r.get(t+6),n+=(e&ct)*Hn,e<z)||(e=r.get(t+7),n+=(e&ct)*Kn,e<z))return n;throw new RangeError("Could not decode varint")}function ee(r,t,e=0){return t==null&&(t=gt(ut(r))),t instanceof Uint8Array?Gn(r,t,e):hu(r,t,e)}function qt(r,t=0){return r instanceof Uint8Array?jn(r,t):du(r,t)}var $n=new Float32Array([-0]),re=new Uint8Array($n.buffer);function Ws(r,t,e){$n[0]=r,t[e]=re[0],t[e+1]=re[1],t[e+2]=re[2],t[e+3]=re[3]}function Xs(r,t){return re[0]=r[t],re[1]=r[t+1],re[2]=r[t+2],re[3]=r[t+3],$n[0]}var Wn=new Float64Array([-0]),ft=new Uint8Array(Wn.buffer);function Ys(r,t,e){Wn[0]=r,t[e]=ft[0],t[e+1]=ft[1],t[e+2]=ft[2],t[e+3]=ft[3],t[e+4]=ft[4],t[e+5]=ft[5],t[e+6]=ft[6],t[e+7]=ft[7]}function Qs(r,t){return ft[0]=r[t],ft[1]=r[t+1],ft[2]=r[t+2],ft[3]=r[t+3],ft[4]=r[t+4],ft[5]=r[t+5],ft[6]=r[t+6],ft[7]=r[t+7],Wn[0]}var pu=BigInt(Number.MAX_SAFE_INTEGER),mu=BigInt(Number.MIN_SAFE_INTEGER),xt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return he;if(t<pu&&t>mu)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>Js&&(o=0n,++n>Js&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return he;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):he}},he=new xt(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var Js=4294967296n;function ti(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 ei(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 Xn(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function At(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function _r(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Yn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,At(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw At(this,4);return _r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return _r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=Xs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=Qs(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw At(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ei(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw At(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw At(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw At(this,8);let t=_r(this.buf,this.pos+=4),e=_r(this.buf,this.pos+=4);return new xt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=jn(this.buf,this.pos);return this.pos+=ut(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 Qn(r){return new Yn(r instanceof Uint8Array?r:r.subarray())}function Vt(r,t,e){let n=Qn(r);return t.decode(n,void 0,e)}var Jn={};dt(Jn,{base10:()=>gu});var gu=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var to={};dt(to,{base16:()=>bu,base16upper:()=>xu});var bu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),xu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var eo={};dt(eo,{base2:()=>yu});var yu=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ro={};dt(ro,{base256emoji:()=>_u});var ni=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),wu=ni.reduce((r,t,e)=>(r[e]=t,r),[]),Eu=ni.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function vu(r){return r.reduce((t,e)=>(t+=wu[e],t),"")}function Su(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Eu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var _u=we({prefix:"\u{1F680}",name:"base256emoji",encode:vu,decode:Su});var no={};dt(no,{base64:()=>Au,base64pad:()=>Iu,base64url:()=>Bu,base64urlpad:()=>Lu});var Au=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Iu=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Bu=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Lu=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oo={};dt(oo,{base8:()=>Tu});var Tu=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var so={};dt(so,{identity:()=>Ru});var Ru=we({prefix:"\0",name:"identity",encode:r=>ls(r),decode:r=>fs(r)});var jh=new TextEncoder,Zh=new TextDecoder;var co={};dt(co,{sha256:()=>je,sha512:()=>Du});function ao({name:r,code:t,encode:e}){return new io(r,t,e)}var io=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?se(this.code,e):e.then(n=>se(this.code,n))}else throw Error("Unknown type, must be binary type")}};function si(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var je=ao({name:"sha2-256",code:18,encode:si("SHA-256")}),Du=ao({name:"sha2-512",code:19,encode:si("SHA-512")});var Ze={...so,...eo,...oo,...Jn,...to,...xn,...yn,...bn,...no,...ro},sd={...co,...vn};function ai(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ii=ai("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),uo=ai("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=gt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ku={utf8:ii,"utf-8":ii,hex:Ze.base16,latin1:uo,ascii:uo,binary:uo,...Ze},Ar=ku;function tt(r,t="utf8"){let e=Ar[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function fo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var de=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function lo(){}var po=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Uu=fo();function Cu(r){return globalThis.Buffer!=null?gt(r):Uu(r)}var We=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(lo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new de(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new mo((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(Ir,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(Ir,e.length(),e)}uint64Number(t){return this._push(Gn,ut(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=xt.fromBigInt(t).zzEncode();return this._push(Ir,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(Ir,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ho,1,t?1:0)}fixed32(t){return this._push($e,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push($e,4,e.lo)._push($e,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push($e,4,e.lo)._push($e,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(Ws,4,t)}double(t){return this._push(Ys,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ho,1,0):this.uint32(e)._push(Fu,e,t)}string(t){let e=ti(t);return e!==0?this.uint32(e)._push(Xn,e,t):this._push(ho,1,0)}fork(){return this.states=new po(this),this.head=this.tail=new de(lo,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 de(lo,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=Cu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ho(r,t,e){t[e]=r&255}function Ou(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var mo=class extends de{next;constructor(t,e){super(Ou,t,e),this.next=void 0}};function Ir(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 $e(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 Fu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(We.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Mu,t,r),this},We.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(zu,t,r),this});function Mu(r,t,e){t.set(r,e)}function zu(r,t,e){r.length<40?Xn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(tt(r),e)}function go(){return new We}function Ht(r,t){let e=go();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 Br(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 Br("enum",Te.VARINT,e,n)}function Kt(r,t){return Br("message",Te.LENGTH_DELIMITED,r,t)}var Lr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var wt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(wt||(wt={}));var bo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(bo||(bo={}));(function(r){r.codec=()=>Re(bo)})(wt||(wt={}));var Xe;(function(r){let t;r.codec=()=>(t==null&&(t=Kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),wt.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=wt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Ht(e,r.codec()),r.decode=(e,n)=>Vt(e,r.codec(),n)})(Xe||(Xe={}));var xo;(function(r){let t;r.codec=()=>(t==null&&(t=Kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),wt.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=wt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Ht(e,r.codec()),r.decode=(e,n)=>Vt(e,r.codec(),n)})(xo||(xo={}));var Vu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ne=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),oe=new Uint32Array(64),yo=class extends Be{constructor(){super(64,32,8,!1),this.A=ne[0]|0,this.B=ne[1]|0,this.C=ne[2]|0,this.D=ne[3]|0,this.E=ne[4]|0,this.F=ne[5]|0,this.G=ne[6]|0,this.H=ne[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)oe[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=oe[f-15],g=oe[f-2],b=Et(h,7)^Et(h,18)^h>>>3,x=Et(g,17)^Et(g,19)^g>>>10;oe[f]=x+oe[f-7]+b+oe[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Et(a,6)^Et(a,11)^Et(a,25),g=l+h+Ls(a,c,u)+Vu[f]+oe[f]|0,x=(Et(n,2)^Et(n,13)^Et(n,22))+Ts(n,o,s)|0;l=u,u=c,c=a,a=i+g|0,i=s,s=o,o=n,n=g+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){oe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ci=fr(()=>new yo);function et(r,t="utf8"){let e=Ar[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}function yt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=gt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var fi=Symbol.for("@achingbrain/uint8arraylist");function ui(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 Tr(r){return!!r?.[fi]}var Gt=class r{bufs;length;[fi]=!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(Tr(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(Tr(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=ui(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ui(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(Tr(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 yt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:yt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Tr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let h=u;h>=0;h--){let g=this.get(f+h);if(n[h]!==g){l=Math.max(1,h-a[g]);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=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=_t(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=_t(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=_t(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=_t(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=_t(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=_t(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=_t(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=_t(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!bt(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 Ye=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Rr=class extends Ie{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,As(t);let n=Ve(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return Ae(this),this.iHash.update(t),this}digestInto(t){Ae(this),_e(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},wo=(r,t,e)=>new Rr(r,t).update(e).digest();wo.create=(r,t)=>new Rr(r,t);function li(r){r.lowS!==void 0&&vt("lowS",r.lowS),r.prehash!==void 0&&vt("prehash",r.prehash)}function Hu(r){let t=Ge(r);Tt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Ku,hexToBytes:Gu}=mr,Eo=class extends Error{constructor(t=""){super(t)}},jt={Err:Eo,_tlv:{encode:(r,t)=>{let{Err:e}=jt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ae(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ae(o.length/2|128):"";return ae(r)+s+o+t},decode(r,t){let{Err:e}=jt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=jt;if(r<Zt)throw new t("integer: negative integers are not allowed");let e=ae(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=jt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ku(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=jt,o=typeof r=="string"?Gu(r):r;Le(o);let{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=jt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Zt=BigInt(0),ot=BigInt(1),n0=BigInt(2),hi=BigInt(3),o0=BigInt(4);function ju(r){let t=Hu(r),{Fp:e}=t,n=te(t.n,t.nBitLength),o=t.toBytes||((x,d,w)=>{let v=d.toAffine();return zt(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(x=>{let d=x.subarray(1),w=e.fromBytes(d.subarray(0,e.BYTES)),v=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:w,y:v}});function i(x){let{a:d,b:w}=t,v=e.sqr(x),m=e.mul(v,x);return e.add(e.add(m,e.mul(x,d)),w)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(x){return He(x,ot,t.n)}function c(x){let{allowedPrivateKeyLengths:d,nByteLength:w,wrapPrivateKey:v,n:m}=t;if(d&&typeof x!="bigint"){if(Yt(x)&&(x=Ft(x)),typeof x!="string"||!d.includes(x.length))throw new Error("invalid private key");x=x.padStart(w*2,"0")}let A;try{A=typeof x=="bigint"?x:Mt(X("private key",x,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof x)}return v&&(A=H(A,m)),pt("private key",A,ot,m),A}function u(x){if(!(x instanceof h))throw new Error("ProjectivePoint expected")}let l=fe((x,d)=>{let{px:w,py:v,pz:m}=x;if(e.eql(m,e.ONE))return{x:w,y:v};let A=x.is0();d==null&&(d=A?e.ONE:e.inv(m));let R=e.mul(w,d),P=e.mul(v,d),I=e.mul(m,d);if(A)return{x:e.ZERO,y:e.ZERO};if(!e.eql(I,e.ONE))throw new Error("invZ was invalid");return{x:R,y:P}}),f=fe(x=>{if(x.is0()){if(t.allowInfinityPoint&&!e.is0(x.py))return;throw new Error("bad point: ZERO")}let{x:d,y:w}=x.toAffine();if(!e.isValid(d)||!e.isValid(w))throw new Error("bad point: x or y not FE");let v=e.sqr(w),m=i(d);if(!e.eql(v,m))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,w,v){if(this.px=d,this.py=w,this.pz=v,d==null||!e.isValid(d))throw new Error("x required");if(w==null||!e.isValid(w))throw new Error("y required");if(v==null||!e.isValid(v))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:w,y:v}=d||{};if(!d||!e.isValid(w)||!e.isValid(v))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let m=A=>e.eql(A,e.ZERO);return m(w)&&m(v)?h.ZERO:new h(w,v,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let w=e.invertBatch(d.map(v=>v.pz));return d.map((v,m)=>v.toAffine(w[m])).map(h.fromAffine)}static fromHex(d){let w=h.fromAffine(s(X("pointHex",d)));return w.assertValidity(),w}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,w){return yr(h,n,d,w)}_setWindowSize(d){b.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){u(d);let{px:w,py:v,pz:m}=this,{px:A,py:R,pz:P}=d,I=e.eql(e.mul(w,P),e.mul(A,m)),T=e.eql(e.mul(v,P),e.mul(R,m));return I&&T}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:w}=t,v=e.mul(w,hi),{px:m,py:A,pz:R}=this,P=e.ZERO,I=e.ZERO,T=e.ZERO,B=e.mul(m,m),j=e.mul(A,A),M=e.mul(R,R),O=e.mul(m,A);return O=e.add(O,O),T=e.mul(m,R),T=e.add(T,T),P=e.mul(d,T),I=e.mul(v,M),I=e.add(P,I),P=e.sub(j,I),I=e.add(j,I),I=e.mul(P,I),P=e.mul(O,P),T=e.mul(v,T),M=e.mul(d,M),O=e.sub(B,M),O=e.mul(d,O),O=e.add(O,T),T=e.add(B,B),B=e.add(T,B),B=e.add(B,M),B=e.mul(B,O),I=e.add(I,B),M=e.mul(A,R),M=e.add(M,M),B=e.mul(M,O),P=e.sub(P,B),T=e.mul(M,j),T=e.add(T,T),T=e.add(T,T),new h(P,I,T)}add(d){u(d);let{px:w,py:v,pz:m}=this,{px:A,py:R,pz:P}=d,I=e.ZERO,T=e.ZERO,B=e.ZERO,j=t.a,M=e.mul(t.b,hi),O=e.mul(w,A),Q=e.mul(v,R),S=e.mul(m,P),L=e.add(w,v),y=e.add(A,R);L=e.mul(L,y),y=e.add(O,Q),L=e.sub(L,y),y=e.add(w,m);let p=e.add(A,P);return y=e.mul(y,p),p=e.add(O,S),y=e.sub(y,p),p=e.add(v,m),I=e.add(R,P),p=e.mul(p,I),I=e.add(Q,S),p=e.sub(p,I),B=e.mul(j,y),I=e.mul(M,S),B=e.add(I,B),I=e.sub(Q,B),B=e.add(Q,B),T=e.mul(I,B),Q=e.add(O,O),Q=e.add(Q,O),S=e.mul(j,S),y=e.mul(M,y),Q=e.add(Q,S),S=e.sub(O,S),S=e.mul(j,S),y=e.add(y,S),O=e.mul(Q,y),T=e.add(T,O),O=e.mul(p,y),I=e.mul(L,I),I=e.sub(I,O),O=e.mul(L,Q),B=e.mul(p,B),B=e.add(B,O),new h(I,T,B)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return b.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:w,n:v}=t;pt("scalar",d,Zt,v);let m=h.ZERO;if(d===Zt)return m;if(this.is0()||d===ot)return this;if(!w||b.hasPrecomputes(this))return b.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:A,k1:R,k2neg:P,k2:I}=w.splitScalar(d),T=m,B=m,j=this;for(;R>Zt||I>Zt;)R&ot&&(T=T.add(j)),I&ot&&(B=B.add(j)),j=j.double(),R>>=ot,I>>=ot;return A&&(T=T.negate()),P&&(B=B.negate()),B=new h(e.mul(B.px,w.beta),B.py,B.pz),T.add(B)}multiply(d){let{endo:w,n:v}=t;pt("scalar",d,ot,v);let m,A;if(w){let{k1neg:R,k1:P,k2neg:I,k2:T}=w.splitScalar(d),{p:B,f:j}=this.wNAF(P),{p:M,f:O}=this.wNAF(T);B=b.constTimeNegate(R,B),M=b.constTimeNegate(I,M),M=new h(e.mul(M.px,w.beta),M.py,M.pz),m=B.add(M),A=j.add(O)}else{let{p:R,f:P}=this.wNAF(d);m=R,A=P}return h.normalizeZ([m,A])[0]}multiplyAndAddUnsafe(d,w,v){let m=h.BASE,A=(P,I)=>I===Zt||I===ot||!P.equals(m)?P.multiplyUnsafe(I):P.multiply(I),R=A(this,w).add(A(d,v));return R.is0()?void 0:R}toAffine(d){return l(this,d)}isTorsionFree(){let{h:d,isTorsionFree:w}=t;if(d===ot)return!0;if(w)return w(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:w}=t;return d===ot?this:w?w(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return vt("isCompressed",d),this.assertValidity(),o(h,this,d)}toHex(d=!0){return vt("isCompressed",d),Ft(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,b=xr(h,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function Zu(r){let t=Ge(r);return Tt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function di(r){let t=Zu(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(S){return H(S,n)}function a(S){return gr(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=ju({...t,toBytes(S,L,y){let p=L.toAffine(),E=e.toBytes(p.x),_=zt;return vt("isCompressed",y),y?_(Uint8Array.from([L.hasEvenY()?2:3]),E):_(Uint8Array.from([4]),E,e.toBytes(p.y))},fromBytes(S){let L=S.length,y=S[0],p=S.subarray(1);if(L===o&&(y===2||y===3)){let E=Mt(p);if(!He(E,ot,e.ORDER))throw new Error("Point is not on curve");let _=l(E),N;try{N=e.sqrt(_)}catch(F){let k=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+k)}let D=(N&ot)===ot;return(y&1)===1!==D&&(N=e.neg(N)),{x:E,y:N}}else if(L===s&&y===4){let E=e.fromBytes(p.subarray(0,e.BYTES)),_=e.fromBytes(p.subarray(e.BYTES,2*e.BYTES));return{x:E,y:_}}else{let E=o,_=s;throw new Error("invalid Point, expected length of "+E+", or uncompressed "+_+", got "+L)}}}),h=S=>Ft(Jt(S,t.nByteLength));function g(S){let L=n>>ot;return S>L}function b(S){return g(S)?i(-S):S}let x=(S,L,y)=>Mt(S.slice(L,y));class d{constructor(L,y,p){this.r=L,this.s=y,this.recovery=p,this.assertValidity()}static fromCompact(L){let y=t.nByteLength;return L=X("compactSignature",L,y*2),new d(x(L,0,y),x(L,y,2*y))}static fromDER(L){let{r:y,s:p}=jt.toSig(X("DER",L));return new d(y,p)}assertValidity(){pt("r",this.r,ot,n),pt("s",this.s,ot,n)}addRecoveryBit(L){return new d(this.r,this.s,L)}recoverPublicKey(L){let{r:y,s:p,recovery:E}=this,_=P(X("msgHash",L));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");let N=E===2||E===3?y+t.n:y;if(N>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(E&1)===0?"02":"03",C=c.fromHex(D+h(N)),F=a(N),k=i(-_*F),q=i(p*F),K=c.BASE.multiplyAndAddUnsafe(C,k,q);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return ce(this.toDERHex())}toDERHex(){return jt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ce(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let w={isValidPrivateKey(S){try{return u(S),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let S=kn(t.n);return Fs(t.randomBytes(S),t.n)},precompute(S=8,L=c.BASE){return L._setWindowSize(S),L.multiply(BigInt(3)),L}};function v(S,L=!0){return c.fromPrivateKey(S).toRawBytes(L)}function m(S){let L=Yt(S),y=typeof S=="string",p=(L||y)&&S.length;return L?p===o||p===s:y?p===2*o||p===2*s:S instanceof c}function A(S,L,y=!0){if(m(S))throw new Error("first arg must be private key");if(!m(L))throw new Error("second arg must be public key");return c.fromHex(L).multiply(u(S)).toRawBytes(y)}let R=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let L=Mt(S),y=S.length*8-t.nBitLength;return y>0?L>>BigInt(y):L},P=t.bits2int_modN||function(S){return i(R(S))},I=Ke(t.nBitLength);function T(S){return pt("num < 2^"+t.nBitLength,S,Zt,I),Jt(S,t.nByteLength)}function B(S,L,y=j){if(["recovered","canonical"].some(nt=>nt in y))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:E}=t,{lowS:_,prehash:N,extraEntropy:D}=y;_==null&&(_=!0),S=X("msgHash",S),li(y),N&&(S=X("prehashed msgHash",p(S)));let C=P(S),F=u(L),k=[T(F),T(C)];if(D!=null&&D!==!1){let nt=D===!0?E(e.BYTES):D;k.push(X("extraEntropy",nt))}let q=zt(...k),K=C;function rt(nt){let st=R(nt);if(!f(st))return;let it=a(st),ht=c.BASE.multiply(st).toAffine(),lt=i(ht.x);if(lt===Zt)return;let Lt=i(it*i(K+lt*F));if(Lt===Zt)return;let Rt=(ht.x===lt?0:2)|Number(ht.y&ot),Ue=Lt;return _&&g(Lt)&&(Ue=b(Lt),Rt^=1),new d(lt,Ue,Rt)}return{seed:q,k2sig:rt}}let j={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function O(S,L,y=j){let{seed:p,k2sig:E}=B(S,L,y),_=t;return Rn(_.hash.outputLen,_.nByteLength,_.hmac)(p,E)}c.BASE._setWindowSize(8);function Q(S,L,y,p=M){let E=S;L=X("msgHash",L),y=X("publicKey",y);let{lowS:_,prehash:N,format:D}=p;if(li(p),"strict"in p)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let C=typeof E=="string"||Yt(E),F=!C&&!D&&typeof E=="object"&&E!==null&&typeof E.r=="bigint"&&typeof E.s=="bigint";if(!C&&!F)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let k,q;try{if(F&&(k=new d(E.r,E.s)),C){try{D!=="compact"&&(k=d.fromDER(E))}catch(Rt){if(!(Rt instanceof jt.Err))throw Rt}!k&&D!=="der"&&(k=d.fromCompact(E))}q=c.fromHex(y)}catch{return!1}if(!k||_&&k.hasHighS())return!1;N&&(L=t.hash(L));let{r:K,s:rt}=k,nt=P(L),st=a(rt),it=i(nt*st),ht=i(K*st),lt=c.BASE.multiplyAndAddUnsafe(q,it,ht)?.toAffine();return lt?i(lt.x)===K:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:A,sign:O,verify:Q,ProjectivePoint:c,Signature:d,utils:w}}function $u(r){return{hash:r,hmac:(t,...e)=>wo(r,t,Sn(...e)),randomBytes:lr}}function pi(r,t){let e=n=>di({...r,...$u(n)});return{...e(t),create:e}}var bi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),mi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Wu=BigInt(1),vo=BigInt(2),gi=(r,t)=>(r+t/vo)/t;function Xu(r){let t=bi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=$(l,e,t)*l%t,h=$(f,e,t)*l%t,g=$(h,vo,t)*u%t,b=$(g,o,t)*g%t,x=$(b,s,t)*b%t,d=$(x,a,t)*x%t,w=$(d,c,t)*d%t,v=$(w,a,t)*x%t,m=$(v,e,t)*l%t,A=$(m,i,t)*b%t,R=$(A,n,t)*u%t,P=$(R,vo,t);if(!So.eql(So.sqr(P),r))throw new Error("Cannot find square root");return P}var So=te(bi,void 0,void 0,{sqrt:Xu}),pe=pi({a:BigInt(0),b:BigInt(7),Fp:So,n:mi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=mi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Wu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=gi(s*r,t),c=gi(-n*r,t),u=H(r-a*e-c*o,t),l=H(-a*n-c*s,t),f=u>i,h=l>i;if(f&&(u=t-u),h&&(l=t-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},ci),d0=BigInt(0);var p0=pe.ProjectivePoint;function xi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function yi(r,t,e){let n=je.digest(e instanceof Uint8Array?e:e.subarray());if(xi(n))return n.then(({digest:o})=>pe.verify(t,o,r)).catch(o=>{throw new Ye(String(o))});try{return pe.verify(t,n.digest,r)}catch(o){throw new Ye(String(o))}}var Pr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ei(t),this.raw=wi(this._key)}toMultihash(){return Ct.digest(Sr(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return yi(this._key,e,t)}};function vi(r){return new Pr(r)}function wi(r){return pe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Ei(r){try{return pe.ProjectivePoint.fromHex(r),r}catch(t){throw new sr(String(t))}}function Si(r){let{Type:t,Data:e}=Xe.decode(r.digest),n=e??new Uint8Array;switch(t){case wt.Ed25519:return $s(n);case wt.secp256k1:return vi(n);default:throw new Oe}}function Sr(r){return Xe.encode({Type:wt[r.type],Data:r.raw})}var _i=Symbol.for("nodejs.util.inspect.custom"),Yu=114,Qe=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()})`}[hn]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Yu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[_i](){return`PeerId(${this.toString()})`}},Nr=class extends Qe{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dr=class extends Qe{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},kr=class extends Qe{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Qu=2336,Ur=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ct.digest(tt(this.url))}[_i](){return`PeerId(${this.url})`}[hn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Qu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};function Cr(r){if(tf(r))return new Nr({multihash:r});if(Ju(r))try{let t=Si(r);if(t.type==="Ed25519")return new Dr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new kr({multihash:r,publicKey:t})}catch{let e=et(r.digest);return new Ur(new URL(e))}throw new ir("Supplied PeerID Multihash is invalid")}function Ju(r){return r.code===Ct.code}function tf(r){return r.code===je.code}function _o(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 Or(r){let t=kt(W.decode(`z${r}`));return Cr(t)}var Fr=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 _o(this.set.entries(),t=>{let e=Or(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Or(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return _o(this.set.values(),t=>Or(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 Ao(){return new Fr}var Io={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ai={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ii=new globalThis.TextEncoder;function ef(r,t){let e=Io[t],n=Ai[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function rf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Io[t],o=Ai[t],s=r;for(;s.length>0;){let i=Ii.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 Bo(r,{size:t=32,utf8Buffer:e}={}){if(!Io[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 rf(r,t,e);r=Ii.encode(r)}return ef(r,t)}var Je={hash:r=>Number(Bo(r,{size:32})),hashV:(r,t)=>nf(Je.hash(r,t))};function nf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),tt(t,"base16")}var Lo=64,It=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Lo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=_t(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?bt(this.fp,t.fp):!1}};function me(r,t){return Math.floor(Math.random()*(t-r))+r}var ge=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");let e=me(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var of=500,tr=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??Je,this.seed=t.seed??me(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=tt(t));let e=new It(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ge(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ge(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[me(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ge(this.bucketSize));for(let a=0;a<of;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ge(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=tt(t));let e=new It(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=tt(t));let e=new It(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},sf={1:.5,2:.84,4:.95,8:.98};function af(r=.001){return r>.002?2:r>1e-5?4:8}function Bi(r,t=.001){let e=af(t),n=sf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Lo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Mr=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??Je,this.seed=t.seed??me(0,Math.pow(2,10)),this.filterSeries=[new tr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=tt(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new tr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=tt(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=tt(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function To(r,t=.001,e){return new Mr({...Bi(r,t),...e??{}})}var zr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let 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>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Li=45,cf=15,Pe=new zr;function qr(r){if(!(r.length>cf))return Pe.new(r).parseWith(()=>Pe.readIPv4Addr())}function Vr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Li))return Pe.new(r).parseWith(()=>Pe.readIPv6Addr())}function be(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Li)return;let e=Pe.new(r).parseWith(()=>Pe.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 Ti(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 Ri(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 Ro(r){switch(r.length){case xe:return r.join(".");case ye:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Pi(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 Ni(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var xe=4,ye=16,Jp=parseInt("0xFFFF",16),uf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function er(r,t){t.length===ye&&r.length===xe&&Ti(t,0,11)&&(t=t.slice(12)),t.length===xe&&r.length===ye&&Ri(r,uf,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 Di(r,t){if(typeof t=="string"&&(t=be(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Po(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=xe,o=qr(t);if(o==null&&(n=ye,o=Vr(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=No(s,8*n);return{network:er(o,i),mask:i}}function No(r,t){if(t!==8*xe&&t!==8*ye)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var Ne=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Po(t));else{let n=be(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=be(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=No(o,8*n.length);this.network=er(n,this.mask)}}contains(t){return Di({network:this.network,mask:this.mask},t)}toString(){let t=Pi(this.mask),e=t!==-1?String(t):Ni(this.mask);return Ro(this.network)+"/"+e}};function ki(r,t){return new Ne(r).contains(t)}var ff=41;function Ui(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===ff)return ki("2000::/3",e)}catch{}return!1}function Hr(r){return!!qr(r)}function Kr(r){return!!Vr(r)}function Gr(r){return!!be(r)}var Oi=ba(Ci(),1),lf=["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"],hf=lf.map(r=>new Oi.Netmask(r));function Do(r){for(let t of hf)if(t.contains(r))return!0;return!1}function df(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function pf(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 Do(o)}function mf(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function gf(r){let t=r.split(":"),e=t[t.length-1];return Do(e)}function bf(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 Fi(r){return Hr(r)?Do(r):df(r)?pf(r):mf(r)?gf(r):Kr(r)?bf(r):void 0}function Mi(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function ko(r){try{if(!Mi(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:Fi(t)??!1}catch{}return!0}function Bt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var jr=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}},De=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new jr(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 jr(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 Uo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function zi(r={}){return xf(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 xf(r,t){t=t??{};let e=t.onEnd,n=new De,o,s,i,a=Bt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,w)=>{s=v=>{s=null,n.push(v);try{d(r(n))}catch(m){w(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Bt()})}},u=d=>s!=null?s(d):(n.push(d),o),l=d=>(n=new De,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 u({done:!1,value:d})},h=d=>i?o:(i=!0,d!=null?l(d):u({done:!0})),g=()=>(n=new De,h(),{done:!0}),b=d=>(h(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:b,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let w=d?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let v,m;w!=null&&(v=new Promise((A,R)=>{m=()=>{R(new Uo)},w.addEventListener("abort",m)}));try{await Promise.race([a.promise,v])}finally{m!=null&&w!=null&&w?.removeEventListener("abort",m)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(d){return x.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return x.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:d=>x.onEmpty(d)},o}var Co=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 Zr(r,t,e,n){let o=new Co(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",l),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),i(h);return}a(),s(f)},u=f=>{a(),i(f.detail)},l=()=>{a(),i(o)};e?.addEventListener("abort",l),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}var $r=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Wr=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 Xr(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Wr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Wr(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 Yr=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Bt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Pt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function wf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Qr=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=wf(),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 Pt),this.cleanup())}async join(t={}){let e=new Yr(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 Xr(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 Jr=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=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new $r;let n=new Qr(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 Pt)}),this.clear()}async onEmpty(t){this.size!==0&&await Zr(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await Zr(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Zr(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=zi({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail)},i=()=>{n()},a=()=>{n(new Pt("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 tn=class extends Jr{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function en(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 qi(r,t,e){let n,o;function s(){let a={signal:o.signal};if(e?.timeout!=null){let c=en([o.signal,AbortSignal.timeout(e.timeout)]);a.signal=c}Promise.resolve().then(async()=>{await r(a)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{setInterval:a=>{t=a,n!=null&&(clearTimeout(n),n=setTimeout(s,t))},setTimeout:a=>{e==null&&(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 Vi=Hr,Ef=Kr,Oo=function(r){let t=0;if(r=r.toString().trim(),Vi(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Ef(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Vi(e[n]),i;s&&(i=Oo(e[n]),e[n]=et(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,et(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},Hi=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 ke={},Fo={},Sf=[[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"]];Sf.forEach(r=>{let t=_f(...r);Fo[t.code]=t,ke[t.name]=t});function _f(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function V(r){if(typeof r=="number"){if(Fo[r]!=null)return Fo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ke[r]!=null)return ke[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var dg=V("ip4"),pg=V("ip6"),mg=V("ipcidr");function Vo(r,t){switch(V(r).code){case 4:case 41:return If(t);case 42:return qo(t);case 43:return et(t,"base10");case 6:case 273:case 33:case 132:return ji(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return qo(t);case 421:return Rf(t);case 444:return Gi(t);case 445:return Gi(t);case 466:return Tf(t);case 481:return globalThis.encodeURIComponent(qo(t));default:return et(t,"base16")}}function Ho(r,t){switch(V(r).code){case 4:return Ki(t);case 41:return Ki(t);case 42:return zo(t);case 43:return tt(t,"base10");case 6:case 273:case 33:case 132:return Ko(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return zo(t);case 421:return Bf(t);case 444:return Pf(t);case 445:return Nf(t);case 466:return Lf(t);case 481:return zo(globalThis.decodeURIComponent(t));default:return tt(t,"base16")}}var Mo=Object.values(Ze).map(r=>r.decoder),Af=function(){let r=Mo[0].or(Mo[1]);return Mo.slice(2).forEach(t=>r=r.or(t)),r}();function Ki(r){if(!Gr(r))throw new Error("invalid ip address");return Oo(r)}function If(r){let t=Hi(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Gr(t))throw new Error("invalid ip address");return t}function Ko(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ji(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function zo(r){let t=tt(r),e=Uint8Array.from(ee(t.length));return yt([e,t],e.length+t.length)}function qo(r){let t=qt(r);if(r=r.slice(ut(t)),r.length!==t)throw new Error("inconsistent lengths");return et(r)}function Bf(r){let t;r[0]==="Q"||r[0]==="1"?t=kt(W.decode(`z${r}`)).bytes:t=at.parse(r).multihash.bytes;let e=Uint8Array.from(ee(t.length));return yt([e,t],e.length+t.length)}function Lf(r){let t=Af.decode(r),e=Uint8Array.from(ee(t.length));return yt([e,t],e.length+t.length)}function Tf(r){let t=qt(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+et(e,"base64url")}function Rf(r){let t=qt(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return et(e,"base58btc")}function Pf(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=Dt.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=Ko(n);return yt([e,o],e.length+o.length)}function Nf(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=Dt.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=Ko(n);return yt([e,o],e.length+o.length)}function Gi(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=et(t,"base32"),o=ji(e);return`${n}:${o}`}function Zi(r){r=Go(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=V(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new rn("invalid address: "+r);if(a.path===!0){n=Go(o.slice(s).join("/")),t.push([a.code,Ho(a.code,n)]),e.push([a.code,n]);break}let c=Ho(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Vo(a.code,c)])}return{string:$i(e),bytes:nn(t),tuples:t,stringTuples:e,path:n}}function jo(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=qt(r,o),i=ut(s),a=V(s),c=Df(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let u=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw new rn("Invalid address Uint8Array: "+et(r,"base16"));t.push([s,u]);let l=Vo(s,u);if(e.push([s,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:$i(e),tuples:t,stringTuples:e,path:n}}function $i(r){let t=[];return r.map(e=>{let n=V(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Go(t.join("/"))}function nn(r){return yt(r.map(t=>{let e=V(t[0]),n=Uint8Array.from(ee(e.code));return t.length>1&&t[1]!=null&&(n=yt([n,t[1]])),n}))}function Df(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=qt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ut(e)}}function Go(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var rn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var kf=Symbol.for("nodejs.util.inspect.custom"),$o=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Uf=[V("dns").code,V("dns4").code,V("dns6").code,V("dnsaddr").code],Zo=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},on=class r{bytes;#t;#e;#r;#n;[$o]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=jo(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Zi(t)}else if(Xi(t))e=jo(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=V("tcp"),a=V("udp"),c=V("ip4"),u=V("ip6"),l=V("dns6"),f=V("ip6zone");for(let[g,b]of this.stringTuples())g===f.code&&(s=`%${b??""}`),Uf.includes(g)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${b??""}${s}`,t=g===l.code?6:4),(g===i.code||g===a.code)&&(e=V(g).name==="tcp"?"tcp":"udp",o=parseInt(b??"")),(g===c.code||g===u.code)&&(e=V(g).name==="tcp"?"tcp":"udp",n=`${b??""}${s}`,t=g===u.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({},V(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>V(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(nn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===ke.p2p.code&&t.push([n,o]),n===ke["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?et(W.decode(`z${n}`),"base58btc"):et(at.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Wi.get(e.name);if(n==null)throw new Zo(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>nr(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)}[kf](){return`Multiaddr(${this.#t})`}};var Wi=new Map;function Xi(r){return!!r?.[$o]}function nr(r){return new on(r)}var Wo=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Bt(),this.haveNext=Bt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Bt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return 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 new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Bt(),await Xr(this.readNext.promise,e?.signal,e)}};function Yi(){return new Wo}var sn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Xo=class extends Error{code;constructor(t,e){super(t),this.code=e}},Yo=class extends Xo{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Qi(r,t){let e=Yi();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 Gt;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new Yo("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:h}=await Promise.race([n.next(),u]);return f===!0?new Gt:h}for(;o.byteLength<i;){let{value:f,done:h}=await Promise.race([n.next(),u]);if(h===!0)throw new sn("unexpected end of input");o.append(f)}let l=o.sublist(0,i);return o.consume(i),l}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var an=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},cn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},un=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ji(r,t={}){let e=Qi(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=ut(t.maxDataLength));let n=t?.lengthDecoder??qt,o=t?.lengthEncoder??ee;return{read:async i=>{let a=-1,c=new Gt;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new an("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new un("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new cn("message length too long");return e.read(a,i)},write:async(i,a)=>{await e.write(new Gt(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new Gt(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function Qo(r,t){let e=Ji(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 ta="libp2p",ea="autonat",ra="1.0.0";var G;(function(r){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(u){u.codec=()=>Re(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(u){u.codec=()=>Re(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,h,g={})=>{if(g.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);g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let b={addrs:[]},x=h==null?f.len:f.pos+h;for(;f.pos<x;){let d=f.uint32();switch(d>>>3){case 1:{b.id=f.bytes();break}case 2:{if(g.limits?.addrs!=null&&b.addrs.length===g.limits.addrs)throw new Lr('Decode error - map field "addrs" had too many elements');b.addrs.push(f.bytes());break}default:{f.skipType(d&7);break}}}return b})),l),u.encode=f=>Ht(f,u.codec()),u.decode=(f,h)=>Vt(f,u.codec(),h)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,h,g={})=>{g.lengthDelimited!==!1&&h.fork(),f.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(f.peer,h)),g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let b={},x=h==null?f.len:f.pos+h;for(;f.pos<x;){let d=f.uint32();switch(d>>>3){case 1:{b.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:g.limits?.peer});break}default:{f.skipType(d&7);break}}}return b})),l),u.encode=f=>Ht(f,u.codec()),u.decode=(f,h)=>Vt(f,u.codec(),h)})(i=r.Dial||(r.Dial={}));let a;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,h,g={})=>{g.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)),g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let b={},x=h==null?f.len:f.pos+h;for(;f.pos<x;){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),u.encode=f=>Ht(f,u.codec()),u.decode=(f,h)=>Vt(f,u.codec(),h)})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=Kt((u,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),u.type!=null&&(l.uint32(8),r.MessageType.codec().encode(u.type,l)),u.dial!=null&&(l.uint32(18),r.Dial.codec().encode(u.dial,l)),u.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(u.dialResponse,l)),f.lengthDelimited!==!1&&l.ldelim()},(u,l,f={})=>{let h={},g=l==null?u.len:u.pos+l;for(;u.pos<g;){let b=u.uint32();switch(b>>>3){case 1:{h.type=r.MessageType.codec().decode(u);break}case 2:{h.dial=r.Dial.codec().decode(u,u.uint32(),{limits:f.limits?.dial});break}case 3:{h.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:f.limits?.dialResponse});break}default:{u.skipType(b&7);break}}}return h})),c),r.encode=u=>Ht(u,r.codec()),r.decode=(u,l)=>Vt(u,r.codec(),l)})(G||(G={}));var qf=4,Vf=8,fn=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??ta}/${ea}/${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=new Map,this.findPeers=qi(this.findRandomPeers.bind(this),6e4),this.addressFilter=To(1024)}[Symbol.toStringTag]="@libp2p/autonat";[as]=["@libp2p/autonat"];get[cs](){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=en([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=Qo(t.stream,{maxDataLength:this.maxMessageSize}).pb(G);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:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.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:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=kt(a.id);i=Cr(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.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:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(f=>nr(f)).filter(f=>{let h=f.toOptions();return ko(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(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(f=>f.toString()).join(", "),i);let u="",l=c[0];for await(let f of c){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:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(V("p2p").code).bytes}}}catch(g){this.log.error("could not dial %p - %e",i,g),u=g.message}finally{h!=null&&await h.close()}}return{type:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.E_DIAL_ERROR,statusText:u,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||!Ui(o.multiaddr))||ko(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:Ao(),queue:new tn({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=Qo(i).pb(G),[,c]=await Promise.all([a.write({type:G.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==G.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let u=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==G.ResponseStatus.OK&&u!==G.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),u===G.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===G.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===qf&&this.confirmAddress(o),o.failure===Vf&&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 Hf(r={}){return t=>new fn(t,r)}return xa(Kf);})();
|
|
2
|
+
"use strict";var Libp2PAutonat=(()=>{var ua=Object.create;var sr=Object.defineProperty;var fa=Object.getOwnPropertyDescriptor;var la=Object.getOwnPropertyNames;var ha=Object.getPrototypeOf,da=Object.prototype.hasOwnProperty;var pa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)sr(r,e,{get:t[e],enumerable:!0})},os=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of la(t))!da.call(r,o)&&o!==e&&sr(r,o,{get:()=>t[o],enumerable:!(n=fa(t,o))||n.enumerable});return r};var ma=(r,t,e)=>(e=r!=null?ua(ha(r)):{},os(t||!r||!r.__esModule?sr(e,"default",{value:r,enumerable:!0}):e,r)),ga=r=>os(sr({},"__esModule",{value:!0}),r);var ki=pa(nr=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,l,f,h;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[u,l,f,h].join(".")},i=function(c){var u,l,f,h,g,b;for(u=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}b=t(c),g=b[0],l=b[1],c=c.substring(l),u.push(g)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var u,l,f,h,g;for(h=0,u=10,l="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,u=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,u=8,l="7")),g=f;f<c.length;){if("0"<=c[f]&&c[f]<=l)h=h*u+(e(c[f])-n)>>>0;else if(u===16)if("a"<=c[f]&&c[f]<="f")h=h*u+(10+e(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*u+(10+e(c[f])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===g)throw new Error("empty octet");return[h,f]},r=function(){function c(u,l){var f,h,g,b;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(b=u.split("/",2),u=b[0],l=b[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(x){throw f=x,new Error("Invalid mask: "+l)}for(h=g=32;g>=0;h=--g)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(u)&this.maskLong)>>>0}catch(x){throw f=x,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+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 c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,f,h;for(h=i(this.first),f=i(this.last),l=0;h<=f;)u(a(h),h,l),l++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),nr.ip2long=i,nr.long2ip=a,nr.Netmask=r}).call(nr)});var Vf={};dt(Vf,{autoNAT:()=>qf});var hn=Symbol.for("@libp2p/peer-id");var Pt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Oe=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ir=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var ar=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Fe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var cr=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 ss=Symbol.for("@libp2p/service-capabilities"),is=Symbol.for("@libp2p/service-dependencies");var bn={};dt(bn,{base58btc:()=>W,base58flickr:()=>Sa});var ml=new Uint8Array(0);function as(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Nt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return 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 cs(r){return new TextEncoder().encode(r)}function us(r){return new TextDecoder().decode(r)}function ba(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),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 x=0,d=0,w=0,S=b.length;w!==S&&b[w]===0;)w++,x++;for(var m=(S-w)*l+1>>>0,A=new Uint8Array(m);w!==S;){for(var R=b[w],P=0,I=m-1;(R!==0||P<d)&&I!==-1;I--,P++)R+=256*A[I]>>>0,A[I]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");d=P,w++}for(var T=m-d;T!==m&&A[T]===0;)T++;for(var B=c.repeat(x);T<m;++T)B+=r.charAt(A[T]);return B}function h(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var x=0;if(b[x]!==" "){for(var d=0,w=0;b[x]===c;)d++,x++;for(var S=(b.length-x)*u+1>>>0,m=new Uint8Array(S);b[x];){var A=e[b.charCodeAt(x)];if(A===255)return;for(var R=0,P=S-1;(A!==0||R<w)&&P!==-1;P--,R++)A+=a*m[P]>>>0,m[P]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");w=R,x++}if(b[x]!==" "){for(var I=S-w;I!==S&&m[I]===0;)I++;for(var T=new Uint8Array(d+(S-I)),B=d;I!==S;)T[B++]=m[I++];return T}}}function g(b){var x=h(b);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:g}}var xa=ba,ya=xa,ls=ya;var dn=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 hs(this,t)}},mn=class{decoders;constructor(t){this.decoders=t}or(t){return hs(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 hs(r,t){return new mn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var gn=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 dn(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 Ee({name:r,prefix:t,encode:e,decode:n}){return new gn(r,t,e,n)}function Zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ls(e,r);return Ee({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function wa(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),a=0,c=0,u=0;for(let l=0;l<s;++l){let f=o[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,a+=e,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ea(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ee({prefix:t,name:r,encode(o){return Ea(o,n,e)},decode(o){return wa(o,n,e,r)}})}var W=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Sa=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xn={};dt(xn,{base32:()=>Dt,base32hex:()=>Ia,base32hexpad:()=>La,base32hexpadupper:()=>Ta,base32hexupper:()=>Ba,base32pad:()=>_a,base32padupper:()=>Aa,base32upper:()=>va,base32z:()=>Ra});var Dt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),va=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),_a=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Aa=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ia=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ba=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),La=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ta=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ra=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yn={};dt(yn,{base36:()=>Me,base36upper:()=>Pa});var Me=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Pa=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Na=ms,ds=128,Da=127,ka=~Da,Ua=Math.pow(2,31);function ms(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ua;)t[e++]=r&255|ds,r/=128;for(;r&ka;)t[e++]=r&255|ds,r>>>=7;return t[e]=r|0,ms.bytes=e-n+1,t}var Ca=wn,Oa=128,ps=127;function wn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw wn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ps)<<o:(i&ps)*Math.pow(2,o),o+=7}while(i>=Oa);return wn.bytes=s-n,e}var Fa=Math.pow(2,7),Ma=Math.pow(2,14),za=Math.pow(2,21),qa=Math.pow(2,28),Va=Math.pow(2,35),Ha=Math.pow(2,42),Ka=Math.pow(2,49),Ga=Math.pow(2,56),ja=Math.pow(2,63),Za=function(r){return r<Fa?1:r<Ma?2:r<za?3:r<qa?4:r<Va?5:r<Ha?6:r<Ka?7:r<Ga?8:r<ja?9:10},$a={encode:Na,decode:Ca,encodingLength:Za},Wa=$a,ze=Wa;function qe(r,t=0){return[ze.decode(r,t),ze.decode.bytes]}function Se(r,t,e=0){return ze.encode(r,t,e),t}function ve(r){return ze.encodingLength(r)}function se(r,t){let e=t.byteLength,n=ve(r),o=n+ve(e),s=new Uint8Array(o+e);return Se(r,s,0),Se(e,s,n),s.set(t,o),new _e(r,e,t,s)}function kt(r){let t=Nt(r),[e,n]=qe(t),[o,s]=qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new _e(e,o,i,t)}function gs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&as(r.bytes,e.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function bs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ya(e,En(r),t??W.encoder);default:return Qa(e,En(r),t??Dt.encoder)}}var xs=new WeakMap;function En(r){let t=xs.get(r);if(t==null){let e=new Map;return xs.set(r,e),e}return t}var at=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ja)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=se(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&&gs(t.multihash,n.multihash)}toString(t){return bs(this,t)}toJSON(){return{"/":bs(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??ys(n,o,s.bytes))}else if(e[tc]===!0){let{version:n,multihash:o,code:s}=e,i=kt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Ve)throw new Error(`Version 0 CID must use dag-pb (code: ${Ve}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ys(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ve,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Nt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new _e(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,h]=qe(t.subarray(e));return e+=h,f},o=n(),s=Ve;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=Xa(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 En(s).set(n,t),s}};function Xa(r,t){switch(r[0]){case"Q":{let e=t??W;return[W.prefix,e.decode(`${W.prefix}${r}`)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}case Dt.prefix:{let e=t??Dt;return[Dt.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 Ya(r,t,e){let{prefix:n}=e;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Qa(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ve=112,Ja=18;function ys(r,t,e){let n=ve(r),o=n+ve(t),s=new Uint8Array(o+e.byteLength);return Se(r,s,0),Se(t,s,n),s.set(e,o),s}var tc=Symbol.for("@ipld/js-cid/CID");var Sn={};dt(Sn,{identity:()=>Ct});var ws=0,ec="identity",Es=Nt;function rc(r){return se(ws,Es(r))}var Ct={code:ws,name:ec,encode:Es,digest:rc};function bt(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 Ss(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function nc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ae(r,...t){if(!nc(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 vs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ss(r.outputLen),Ss(r.blockLen)}function Ie(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function _s(r,t){Ae(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ie=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function fr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Et(r,t){return r<<32-t|r>>>t}function As(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function He(r){return typeof r=="string"&&(r=As(r)),Ae(r),r}function vn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ae(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Be=class{clone(){return this._cloneInto()}};function lr(r){let t=n=>r().update(He(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function hr(r=32){if(ie&&typeof ie.getRandomValues=="function")return ie.getRandomValues(new Uint8Array(r));if(ie&&typeof ie.randomBytes=="function")return ie.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function oc(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function Is(r,t,e){return r&t^~r&e}function Bs(r,t,e){return r&t^r&e^t&e}var Le=class extends Be{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=fr(this.buffer)}update(t){Ie(this);let{view:e,buffer:n,blockLen:o}=this;t=He(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=fr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ie(this),_s(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;oc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=fr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;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.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var dr=BigInt(4294967295),_n=BigInt(32);function Ls(r,t=!1){return t?{h:Number(r&dr),l:Number(r>>_n&dr)}:{h:Number(r>>_n&dr)|0,l:Number(r&dr)|0}}function sc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Ls(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var ic=(r,t)=>BigInt(r>>>0)<<_n|BigInt(t>>>0),ac=(r,t,e)=>r>>>e,cc=(r,t,e)=>r<<32-e|t>>>e,uc=(r,t,e)=>r>>>e|t<<32-e,fc=(r,t,e)=>r<<32-e|t>>>e,lc=(r,t,e)=>r<<64-e|t>>>e-32,hc=(r,t,e)=>r>>>e-32|t<<64-e,dc=(r,t)=>t,pc=(r,t)=>r,mc=(r,t,e)=>r<<e|t>>>32-e,gc=(r,t,e)=>t<<e|r>>>32-e,bc=(r,t,e)=>t<<e-32|r>>>64-e,xc=(r,t,e)=>r<<e-32|t>>>64-e;function yc(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var wc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ec=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Sc=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),vc=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,_c=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ac=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Ic={fromBig:Ls,split:sc,toBig:ic,shrSH:ac,shrSL:cc,rotrSH:uc,rotrSL:fc,rotrBH:lc,rotrBL:hc,rotr32H:dc,rotr32L:pc,rotlSH:mc,rotlSL:gc,rotlBH:bc,rotlBL:xc,add:yc,add3L:wc,add3H:Ec,add4L:Sc,add4H:vc,add5H:Ac,add5L:_c},U=Ic;var[Bc,Lc]=U.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),$t=new Uint32Array(80),Wt=new Uint32Array(80),An=class extends Le{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:h,Gh:g,Gl:b,Hh:x,Hl:d}=this;return[t,e,n,o,s,i,a,c,u,l,f,h,g,b,x,d]}set(t,e,n,o,s,i,a,c,u,l,f,h,g,b,x,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=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=g|0,this.Gl=b|0,this.Hh=x|0,this.Hl=d|0}process(t,e){for(let m=0;m<16;m++,e+=4)$t[m]=t.getUint32(e),Wt[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let A=$t[m-15]|0,R=Wt[m-15]|0,P=U.rotrSH(A,R,1)^U.rotrSH(A,R,8)^U.shrSH(A,R,7),I=U.rotrSL(A,R,1)^U.rotrSL(A,R,8)^U.shrSL(A,R,7),T=$t[m-2]|0,B=Wt[m-2]|0,j=U.rotrSH(T,B,19)^U.rotrBH(T,B,61)^U.shrSH(T,B,6),M=U.rotrSL(T,B,19)^U.rotrBL(T,B,61)^U.shrSL(T,B,6),O=U.add4L(I,M,Wt[m-7],Wt[m-16]),Q=U.add4H(O,P,j,$t[m-7],$t[m-16]);$t[m]=Q|0,Wt[m]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:h,Fh:g,Fl:b,Gh:x,Gl:d,Hh:w,Hl:S}=this;for(let m=0;m<80;m++){let A=U.rotrSH(f,h,14)^U.rotrSH(f,h,18)^U.rotrBH(f,h,41),R=U.rotrSL(f,h,14)^U.rotrSL(f,h,18)^U.rotrBL(f,h,41),P=f&g^~f&x,I=h&b^~h&d,T=U.add5L(S,R,I,Lc[m],Wt[m]),B=U.add5H(T,w,A,P,Bc[m],$t[m]),j=T|0,M=U.rotrSH(n,o,28)^U.rotrBH(n,o,34)^U.rotrBH(n,o,39),O=U.rotrSL(n,o,28)^U.rotrBL(n,o,34)^U.rotrBL(n,o,39),Q=n&s^n&a^s&a,v=o&i^o&c^i&c;w=x|0,S=d|0,x=g|0,d=b|0,g=f|0,b=h|0,{h:f,l:h}=U.add(u|0,l|0,B|0,j|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let L=U.add3L(j,O,v);n=U.add3H(L,B,M,Q),o=L|0}({h:n,l:o}=U.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=U.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=U.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=U.add(this.Eh|0,this.El|0,f|0,h|0),{h:g,l:b}=U.add(this.Fh|0,this.Fl|0,g|0,b|0),{h:x,l:d}=U.add(this.Gh|0,this.Gl|0,x|0,d|0),{h:w,l:S}=U.add(this.Hh|0,this.Hl|0,w|0,S|0),this.set(n,o,s,i,a,c,u,l,f,h,g,b,x,d,w,S)}roundClean(){$t.fill(0),Wt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ts=lr(()=>new An);var gr={};dt(gr,{aInRange:()=>pt,abool:()=>St,abytes:()=>Te,bitGet:()=>kc,bitLen:()=>Tn,bitMask:()=>Ge,bitSet:()=>Uc,bytesToHex:()=>Ft,bytesToNumberBE:()=>Mt,bytesToNumberLE:()=>Yt,concatBytes:()=>zt,createHmacDrbg:()=>Rn,ensureBytes:()=>X,equalBytes:()=>Nc,hexToBytes:()=>ce,hexToNumber:()=>Ln,inRange:()=>Ke,isBytes:()=>Xt,memoized:()=>fe,notImplemented:()=>Oc,numberToBytesBE:()=>Qt,numberToBytesLE:()=>ue,numberToHexUnpadded:()=>ae,numberToVarBytesBE:()=>Pc,utf8ToBytes:()=>Dc,validateObject:()=>Tt});var pr=BigInt(0),mr=BigInt(1),Tc=BigInt(2);function Xt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Te(r){if(!Xt(r))throw new Error("Uint8Array expected")}function St(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Rc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Ft(r){Te(r);let t="";for(let e=0;e<r.length;e++)t+=Rc[r[e]];return t}function ae(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Ln(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?pr:BigInt("0x"+r)}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function Rs(r){if(r>=Ot._0&&r<=Ot._9)return r-Ot._0;if(r>=Ot.A&&r<=Ot.F)return r-(Ot.A-10);if(r>=Ot.a&&r<=Ot.f)return r-(Ot.a-10)}function ce(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Rs(r.charCodeAt(s)),a=Rs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Mt(r){return Ln(Ft(r))}function Yt(r){return Te(r),Ln(Ft(Uint8Array.from(r).reverse()))}function Qt(r,t){return ce(r.toString(16).padStart(t*2,"0"))}function ue(r,t){return Qt(r,t).reverse()}function Pc(r){return ce(ae(r))}function X(r,t,e){let n;if(typeof t=="string")try{n=ce(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Xt(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function zt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Te(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Nc(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Dc(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var In=r=>typeof r=="bigint"&&pr<=r;function Ke(r,t,e){return In(r)&&In(t)&&In(e)&&t<=r&&r<e}function pt(r,t,e,n){if(!Ke(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Tn(r){let t;for(t=0;r>pr;r>>=mr,t+=1);return t}function kc(r,t){return r>>BigInt(t)&mr}function Uc(r,t,e){return r|(e?mr:pr)<<BigInt(t)}var Ge=r=>(Tc<<BigInt(r-1))-mr,Bn=r=>new Uint8Array(r),Ps=r=>Uint8Array.from(r);function Rn(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=Bn(r),o=Bn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=Bn())=>{o=a(Ps([0]),f),n=a(),f.length!==0&&(o=a(Ps([1]),f),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=a();let g=n.slice();h.push(g),f+=n.length}return zt(...h)};return(f,h)=>{i(),c(f);let g;for(;!(g=h(u()));)c();return i(),g}}var Cc={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Xt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Tt(r,t,e={}){let n=(o,s,i)=>{let a=Cc[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var Oc=()=>{throw new Error("not implemented")};function fe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var J=BigInt(0),Z=BigInt(1),le=BigInt(2),Fc=BigInt(3),Pn=BigInt(4),Ns=BigInt(5),Ds=BigInt(8),Mc=BigInt(9),zc=BigInt(16);function H(r,t){let e=r%t;return e>=J?e:t+e}function qc(r,t,e){if(t<J)throw new Error("invalid exponent, negatives unsupported");if(e<=J)throw new Error("invalid modulus");if(e===Z)return J;let n=Z;for(;t>J;)t&Z&&(n=n*r%e),r=r*r%e,t>>=Z;return n}function $(r,t,e){let n=r;for(;t-- >J;)n*=n,n%=e;return n}function br(r,t){if(r===J)throw new Error("invert: expected non-zero number");if(t<=J)throw new Error("invert: expected positive modulus, got "+t);let e=H(r,t),n=t,o=J,s=Z,i=Z,a=J;for(;e!==J;){let u=n/e,l=n%e,f=o-i*u,h=s-a*u;n=e,e=l,o=i,s=a,i=f,a=h}if(n!==Z)throw new Error("invert: does not exist");return H(o,t)}function Vc(r){let t=(r-Z)/le,e,n,o;for(e=r-Z,n=0;e%le===J;e/=le,n++);for(o=le;o<r&&qc(o,t,r)!==r-Z;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+Z)/Pn;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let s=(e+Z)/le;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,o),e),f=a.pow(c,s),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let g=1;for(let x=a.sqr(h);g<u&&!a.eql(x,a.ONE);g++)x=a.sqr(x);let b=a.pow(l,Z<<BigInt(u-g-1));l=a.sqr(b),f=a.mul(f,b),h=a.mul(h,l),u=g}return f}}function Hc(r){if(r%Pn===Fc){let t=(r+Z)/Pn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%Ds===Ns){let t=(r-Ns)/Ds;return function(n,o){let s=n.mul(o,le),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,le),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%zc,Vc(r)}var ks=(r,t)=>(H(r,t)&Z)===Z,Kc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Nn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Kc.reduce((n,o)=>(n[o]="function",n),t);return Tt(r,e)}function Gc(r,t,e){if(e<J)throw new Error("invalid exponent, negatives unsupported");if(e===J)return r.ONE;if(e===Z)return t;let n=r.ONE,o=t;for(;e>J;)e&Z&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Z;return n}function jc(r,t){let e=new Array(t.length),n=t.reduce((s,i,a)=>r.is0(i)?s:(e[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,a)=>r.is0(i)?s:(e[a]=r.mul(s,e[a]),r.mul(s,i)),o),e}function Dn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Jt(r,t,e=!1,n={}){if(r<=J)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Dn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:Ge(o),ZERO:J,ONE:Z,create:c=>H(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return J<=c&&c<r},is0:c=>c===J,isOdd:c=>(c&Z)===Z,neg:c=>H(-c,r),eql:(c,u)=>c===u,sqr:c=>H(c*c,r),add:(c,u)=>H(c+u,r),sub:(c,u)=>H(c-u,r),mul:(c,u)=>H(c*u,r),pow:(c,u)=>Gc(a,c,u),div:(c,u)=>H(c*br(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>br(c,r),sqrt:n.sqrt||(c=>(i||(i=Hc(r)),i(a,c))),invertBatch:c=>jc(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>e?ue(c,s):Qt(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?Yt(c):Mt(c)}});return Object.freeze(a)}function Us(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 kn(r){let t=Us(r);return t+Math.ceil(t/2)}function Cs(r,t,e=!1){let n=r.length,o=Us(t),s=kn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Yt(r):Mt(r),a=H(i,t-Z)+Z;return e?ue(a,o):Qt(a,o)}var Os=BigInt(0),xr=BigInt(1);function Un(r,t){let e=t.negate();return r?e:t}function Fs(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Cn(r,t){Fs(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Zc(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 $c(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 On=new WeakMap,Ms=new WeakMap;function Fn(r){return Ms.get(r)||1}function yr(r,t){return{constTimeNegate:Un,hasPrecomputes(e){return Fn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Os;)n&xr&&(o=o.add(s)),s=s.double(),n>>=xr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Cn(n,t),i=[],a=e,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let l=1;l<s;l++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=Cn(e,t),a=r.ZERO,c=r.BASE,u=BigInt(2**e-1),l=2**e,f=BigInt(e);for(let h=0;h<s;h++){let g=h*i,b=Number(o&u);o>>=f,b>i&&(b-=l,o+=xr);let x=g,d=g+Math.abs(b)-1,w=h%2!==0,S=b<0;b===0?c=c.add(Un(w,n[x])):a=a.add(Un(S,n[d]))}return{p:a,f:c}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:a}=Cn(e,t),c=BigInt(2**e-1),u=2**e,l=BigInt(e);for(let f=0;f<i;f++){let h=f*a;if(o===Os)break;let g=Number(o&c);if(o>>=l,g>a&&(g-=u,o+=xr),g===0)continue;let b=n[h+Math.abs(g)-1];g<0&&(b=b.negate()),s=s.add(b)}return s},getPrecomputes(e,n,o){let s=On.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&On.set(n,o(s))),s},wNAFCached(e,n,o){let s=Fn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Fn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Fs(n,t),Ms.set(e,n),On.delete(e)}}}function wr(r,t,e,n){if(Zc(e,r),$c(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Tn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=(1<<i)-1,c=new Array(a+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,l=o;for(let f=u;f>=0;f-=i){c.fill(o);for(let g=0;g<n.length;g++){let b=n[g],x=Number(b>>BigInt(f)&BigInt(a));c[x]=c[x].add(e[g])}let h=o;for(let g=c.length-1,b=o;g>0;g--)b=b.add(c[g]),h=h.add(b);if(l=l.add(h),f!==0)for(let g=0;g<i;g++)l=l.double()}return l}function je(r){return Nn(r.Fp),Tt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Dn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var vt=BigInt(0),mt=BigInt(1),Er=BigInt(2),Wc=BigInt(8),Xc={zip215:!0};function Yc(r){let t=je(r);return Tt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function zs(r){let t=Yc(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,u=Er<<BigInt(a*8)-mt,l=e.create,f=Jt(t.n,t.nBitLength),h=t.uvRatio||((y,p)=>{try{return{isValid:!0,value:e.sqrt(y*e.inv(p))}}catch{return{isValid:!1,value:vt}}}),g=t.adjustScalarBytes||(y=>y),b=t.domain||((y,p,E)=>{if(St("phflag",E),p.length||E)throw new Error("Contexts/pre-hash are not supported");return y});function x(y,p){pt("coordinate "+y,p,vt,u)}function d(y){if(!(y instanceof m))throw new Error("ExtendedPoint expected")}let w=fe((y,p)=>{let{ex:E,ey:_,ez:N}=y,D=y.is0();p==null&&(p=D?Wc:e.inv(N));let C=l(E*p),F=l(_*p),k=l(N*p);if(D)return{x:vt,y:mt};if(k!==mt)throw new Error("invZ was invalid");return{x:C,y:F}}),S=fe(y=>{let{a:p,d:E}=t;if(y.is0())throw new Error("bad point: ZERO");let{ex:_,ey:N,ez:D,et:C}=y,F=l(_*_),k=l(N*N),q=l(D*D),K=l(q*q),rt=l(F*p),nt=l(q*l(rt+k)),st=l(K+l(E*l(F*k)));if(nt!==st)throw new Error("bad point: equation left != right (1)");let it=l(_*N),ht=l(D*C);if(it!==ht)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,E,_,N){this.ex=p,this.ey=E,this.ez=_,this.et=N,x("x",p),x("y",E),x("z",_),x("t",N),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");let{x:E,y:_}=p||{};return x("x",E),x("y",_),new m(E,_,mt,l(E*_))}static normalizeZ(p){let E=e.invertBatch(p.map(_=>_.ez));return p.map((_,N)=>_.toAffine(E[N])).map(m.fromAffine)}static msm(p,E){return wr(m,f,p,E)}_setWindowSize(p){P.setWindowSize(this,p)}assertValidity(){S(this)}equals(p){d(p);let{ex:E,ey:_,ez:N}=this,{ex:D,ey:C,ez:F}=p,k=l(E*F),q=l(D*N),K=l(_*F),rt=l(C*N);return k===q&&K===rt}is0(){return this.equals(m.ZERO)}negate(){return new m(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:p}=t,{ex:E,ey:_,ez:N}=this,D=l(E*E),C=l(_*_),F=l(Er*l(N*N)),k=l(p*D),q=E+_,K=l(l(q*q)-D-C),rt=k+C,nt=rt-F,st=k-C,it=l(K*nt),ht=l(rt*st),lt=l(K*st),Lt=l(nt*rt);return new m(it,ht,Lt,lt)}add(p){d(p);let{a:E,d:_}=t,{ex:N,ey:D,ez:C,et:F}=this,{ex:k,ey:q,ez:K,et:rt}=p;if(E===BigInt(-1)){let Yo=l((D-N)*(q+k)),Qo=l((D+N)*(q-k)),ln=l(Qo-Yo);if(ln===vt)return this.double();let Jo=l(C*Er*rt),ts=l(F*Er*K),es=ts+Jo,rs=Qo+Yo,ns=ts-Jo,sa=l(es*ln),ia=l(rs*ns),aa=l(es*ns),ca=l(ln*rs);return new m(sa,ia,ca,aa)}let nt=l(N*k),st=l(D*q),it=l(F*_*rt),ht=l(C*K),lt=l((N+D)*(k+q)-nt-st),Lt=ht-it,Rt=ht+it,Ce=l(st-E*nt),ea=l(lt*Lt),ra=l(Rt*Ce),na=l(lt*Ce),oa=l(Lt*Rt);return new m(ea,ra,oa,na)}subtract(p){return this.add(p.negate())}wNAF(p){return P.wNAFCached(this,p,m.normalizeZ)}multiply(p){let E=p;pt("scalar",E,mt,n);let{p:_,f:N}=this.wNAF(E);return m.normalizeZ([_,N])[0]}multiplyUnsafe(p,E=m.ZERO){let _=p;return pt("scalar",_,vt,n),_===vt?R:this.is0()||_===mt?this:P.wNAFCachedUnsafe(this,_,m.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return P.unsafeLadder(this,n).is0()}toAffine(p){return w(this,p)}clearCofactor(){let{h:p}=t;return p===mt?this:this.multiplyUnsafe(p)}static fromHex(p,E=!1){let{d:_,a:N}=t,D=e.BYTES;p=X("pointHex",p,D),St("zip215",E);let C=p.slice(),F=p[D-1];C[D-1]=F&-129;let k=Yt(C),q=E?u:e.ORDER;pt("pointHex.y",k,vt,q);let K=l(k*k),rt=l(K-mt),nt=l(_*K-N),{isValid:st,value:it}=h(rt,nt);if(!st)throw new Error("Point.fromHex: invalid y coordinate");let ht=(it&mt)===mt,lt=(F&128)!==0;if(!E&&it===vt&<)throw new Error("Point.fromHex: x=0 and x_0=1");return lt!==ht&&(it=l(-it)),m.fromAffine({x:it,y:k})}static fromPrivateKey(p){return B(p).point}toRawBytes(){let{x:p,y:E}=this.toAffine(),_=ue(E,e.BYTES);return _[_.length-1]|=p&mt?128:0,_}toHex(){return Ft(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,mt,l(t.Gx*t.Gy)),m.ZERO=new m(vt,mt,mt,vt);let{BASE:A,ZERO:R}=m,P=yr(m,a*8);function I(y){return H(y,n)}function T(y){return I(Yt(y))}function B(y){let p=e.BYTES;y=X("private key",y,p);let E=X("hashed private key",s(y),2*p),_=g(E.slice(0,p)),N=E.slice(p,2*p),D=T(_),C=A.multiply(D),F=C.toRawBytes();return{head:_,prefix:N,scalar:D,point:C,pointBytes:F}}function j(y){return B(y).pointBytes}function M(y=new Uint8Array,...p){let E=zt(...p);return T(s(b(E,X("context",y),!!o)))}function O(y,p,E={}){y=X("message",y),o&&(y=o(y));let{prefix:_,scalar:N,pointBytes:D}=B(p),C=M(E.context,_,y),F=A.multiply(C).toRawBytes(),k=M(E.context,F,D,y),q=I(C+k*N);pt("signature.s",q,vt,n);let K=zt(F,ue(q,e.BYTES));return X("result",K,e.BYTES*2)}let Q=Xc;function v(y,p,E,_=Q){let{context:N,zip215:D}=_,C=e.BYTES;y=X("signature",y,2*C),p=X("message",p),E=X("publicKey",E,C),D!==void 0&&St("zip215",D),o&&(p=o(p));let F=Yt(y.slice(C,2*C)),k,q,K;try{k=m.fromHex(E,D),q=m.fromHex(y.slice(0,C),D),K=A.multiplyUnsafe(F)}catch{return!1}if(!D&&k.isSmallOrder())return!1;let rt=M(N,q.toRawBytes(),k.toRawBytes(),p);return q.add(k.multiplyUnsafe(rt)).subtract(K).clearCofactor().equals(m.ZERO)}return A._setWindowSize(8),{CURVE:t,getPublicKey:j,sign:O,verify:v,ExtendedPoint:m,utils:{getExtendedPublicKey:B,randomPrivateKey:()=>i(e.BYTES),precompute(y=8,p=m.BASE){return p._setWindowSize(y),p.multiply(BigInt(3)),p}}}}var Mn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),qs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),ah=BigInt(0),Qc=BigInt(1),Vs=BigInt(2),ch=BigInt(3),Jc=BigInt(5),tu=BigInt(8);function eu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Mn,a=r*r%s*r%s,c=$(a,Vs,s)*a%s,u=$(c,Qc,s)*r%s,l=$(u,Jc,s)*u%s,f=$(l,t,s)*l%s,h=$(f,e,s)*f%s,g=$(h,n,s)*h%s,b=$(g,o,s)*g%s,x=$(b,o,s)*g%s,d=$(x,t,s)*l%s;return{pow_p_5_8:$(d,Vs,s)*r%s,b2:a}}function ru(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function nu(r,t){let e=Mn,n=H(t*t*t,e),o=H(n*n*t,e),s=eu(r*o).pow_p_5_8,i=H(r*n*s,e),a=H(t*i*i,e),c=i,u=H(i*qs,e),l=a===r,f=a===H(-r,e),h=a===H(-r*qs,e);return l&&(i=c),(f||h)&&(i=u),ks(i,e)&&(i=H(-i,e)),{isValid:l||f,value:i}}var ou=Jt(Mn,void 0,!0),su={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ou,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:tu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ts,randomBytes:hr,adjustScalarBytes:ru,uvRatio:nu},Hs=zs(su);var Sr=32;function Ks(r,t,e){return Hs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var vr=class{type="Ed25519";raw;constructor(t){this.raw=zn(t,Sr)}toMultihash(){return Ct.digest(_r(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return Ks(this.raw,e,t)}};function js(r){return r=zn(r,Sr),new vr(r)}function zn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Oe(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function _t(r=0){return new Uint8Array(r)}function gt(r=0){return new Uint8Array(r)}var au=Math.pow(2,7),cu=Math.pow(2,14),uu=Math.pow(2,21),qn=Math.pow(2,28),Vn=Math.pow(2,35),Hn=Math.pow(2,42),Kn=Math.pow(2,49),z=128,ct=127;function ut(r){if(r<au)return 1;if(r<cu)return 2;if(r<uu)return 3;if(r<qn)return 4;if(r<Vn)return 5;if(r<Hn)return 6;if(r<Kn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Gn(r,t,e=0){switch(ut(r)){case 8:t[e++]=r&255|z,r/=128;case 7:t[e++]=r&255|z,r/=128;case 6:t[e++]=r&255|z,r/=128;case 5:t[e++]=r&255|z,r/=128;case 4:t[e++]=r&255|z,r>>>=7;case 3:t[e++]=r&255|z,r>>>=7;case 2:t[e++]=r&255|z,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function fu(r,t,e=0){switch(ut(r)){case 8:t.set(e++,r&255|z),r/=128;case 7:t.set(e++,r&255|z),r/=128;case 6:t.set(e++,r&255|z),r/=128;case 5:t.set(e++,r&255|z),r/=128;case 4:t.set(e++,r&255|z),r>>>=7;case 3:t.set(e++,r&255|z),r>>>=7;case 2:t.set(e++,r&255|z),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function jn(r,t){let e=r[t],n=0;if(n+=e&ct,e<z||(e=r[t+1],n+=(e&ct)<<7,e<z)||(e=r[t+2],n+=(e&ct)<<14,e<z)||(e=r[t+3],n+=(e&ct)<<21,e<z)||(e=r[t+4],n+=(e&ct)*qn,e<z)||(e=r[t+5],n+=(e&ct)*Vn,e<z)||(e=r[t+6],n+=(e&ct)*Hn,e<z)||(e=r[t+7],n+=(e&ct)*Kn,e<z))return n;throw new RangeError("Could not decode varint")}function lu(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<z||(e=r.get(t+1),n+=(e&ct)<<7,e<z)||(e=r.get(t+2),n+=(e&ct)<<14,e<z)||(e=r.get(t+3),n+=(e&ct)<<21,e<z)||(e=r.get(t+4),n+=(e&ct)*qn,e<z)||(e=r.get(t+5),n+=(e&ct)*Vn,e<z)||(e=r.get(t+6),n+=(e&ct)*Hn,e<z)||(e=r.get(t+7),n+=(e&ct)*Kn,e<z))return n;throw new RangeError("Could not decode varint")}function te(r,t,e=0){return t==null&&(t=gt(ut(r))),t instanceof Uint8Array?Gn(r,t,e):fu(r,t,e)}function qt(r,t=0){return r instanceof Uint8Array?jn(r,t):lu(r,t)}var $n=new Float32Array([-0]),ee=new Uint8Array($n.buffer);function Zs(r,t,e){$n[0]=r,t[e]=ee[0],t[e+1]=ee[1],t[e+2]=ee[2],t[e+3]=ee[3]}function $s(r,t){return ee[0]=r[t],ee[1]=r[t+1],ee[2]=r[t+2],ee[3]=r[t+3],$n[0]}var Wn=new Float64Array([-0]),ft=new Uint8Array(Wn.buffer);function Ws(r,t,e){Wn[0]=r,t[e]=ft[0],t[e+1]=ft[1],t[e+2]=ft[2],t[e+3]=ft[3],t[e+4]=ft[4],t[e+5]=ft[5],t[e+6]=ft[6],t[e+7]=ft[7]}function Xs(r,t){return ft[0]=r[t],ft[1]=r[t+1],ft[2]=r[t+2],ft[3]=r[t+3],ft[4]=r[t+4],ft[5]=r[t+5],ft[6]=r[t+6],ft[7]=r[t+7],Wn[0]}var hu=BigInt(Number.MAX_SAFE_INTEGER),du=BigInt(Number.MIN_SAFE_INTEGER),xt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return he;if(t<hu&&t>du)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>Ys&&(o=0n,++n>Ys&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return he;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):he}},he=new xt(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var Ys=4294967296n;function Qs(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 Js(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 Xn(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function At(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Ar(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Yn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,At(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw At(this,4);return Ar(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return Ar(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=$s(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=Xs(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw At(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Js(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw At(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw At(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw At(this,8);let t=Ar(this.buf,this.pos+=4),e=Ar(this.buf,this.pos+=4);return new xt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=jn(this.buf,this.pos);return this.pos+=ut(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 Qn(r){return new Yn(r instanceof Uint8Array?r:r.subarray())}function Vt(r,t,e){let n=Qn(r);return t.decode(n,void 0,e)}var Jn={};dt(Jn,{base10:()=>pu});var pu=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var to={};dt(to,{base16:()=>mu,base16upper:()=>gu});var mu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var eo={};dt(eo,{base2:()=>bu});var bu=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ro={};dt(ro,{base256emoji:()=>Su});var ei=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),xu=ei.reduce((r,t,e)=>(r[e]=t,r),[]),yu=ei.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function wu(r){return r.reduce((t,e)=>(t+=xu[e],t),"")}function Eu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=yu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Su=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:wu,decode:Eu});var no={};dt(no,{base64:()=>vu,base64pad:()=>_u,base64url:()=>Au,base64urlpad:()=>Iu});var vu=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_u=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Au=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Iu=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oo={};dt(oo,{base8:()=>Bu});var Bu=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var so={};dt(so,{identity:()=>Lu});var Lu=Ee({prefix:"\0",name:"identity",encode:r=>us(r),decode:r=>cs(r)});var Kh=new TextEncoder,Gh=new TextDecoder;var co={};dt(co,{sha256:()=>Ze,sha512:()=>Pu});function ao({name:r,code:t,encode:e}){return new io(r,t,e)}var io=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?se(this.code,e):e.then(n=>se(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ni(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ze=ao({name:"sha2-256",code:18,encode:ni("SHA-256")}),Pu=ao({name:"sha2-512",code:19,encode:ni("SHA-512")});var $e={...so,...eo,...oo,...Jn,...to,...xn,...yn,...bn,...no,...ro},nd={...co,...Sn};function si(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var oi=si("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),uo=si("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=gt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Nu={utf8:oi,"utf-8":oi,hex:$e.base16,latin1:uo,ascii:uo,binary:uo,...$e},Ir=Nu;function tt(r,t="utf8"){let e=Ir[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function fo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var de=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function lo(){}var po=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Du=fo();function ku(r){return globalThis.Buffer!=null?gt(r):Du(r)}var Xe=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(lo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new de(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new mo((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(Br,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(Br,e.length(),e)}uint64Number(t){return this._push(Gn,ut(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=xt.fromBigInt(t).zzEncode();return this._push(Br,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(Br,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ho,1,t?1:0)}fixed32(t){return this._push(We,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(We,4,e.lo)._push(We,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push(We,4,e.lo)._push(We,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(Zs,4,t)}double(t){return this._push(Ws,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ho,1,0):this.uint32(e)._push(Cu,e,t)}string(t){let e=Qs(t);return e!==0?this.uint32(e)._push(Xn,e,t):this._push(ho,1,0)}fork(){return this.states=new po(this),this.head=this.tail=new de(lo,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 de(lo,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=ku(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ho(r,t,e){t[e]=r&255}function Uu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var mo=class extends de{next;constructor(t,e){super(Uu,t,e),this.next=void 0}};function Br(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 We(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 Cu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Xe.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ou,t,r),this},Xe.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Fu,t,r),this});function Ou(r,t,e){t.set(r,e)}function Fu(r,t,e){r.length<40?Xn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(tt(r),e)}function go(){return new Xe}function Ht(r,t){let e=go();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Re;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Re||(Re={}));function Lr(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 Lr("enum",Re.VARINT,e,n)}function Kt(r,t){return Lr("message",Re.LENGTH_DELIMITED,r,t)}var Tr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var wt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(wt||(wt={}));var bo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(bo||(bo={}));(function(r){r.codec=()=>Pe(bo)})(wt||(wt={}));var Ye;(function(r){let t;r.codec=()=>(t==null&&(t=Kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),wt.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=wt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Ht(e,r.codec()),r.decode=(e,n)=>Vt(e,r.codec(),n)})(Ye||(Ye={}));var xo;(function(r){let t;r.codec=()=>(t==null&&(t=Kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),wt.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=wt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Ht(e,r.codec()),r.decode=(e,n)=>Vt(e,r.codec(),n)})(xo||(xo={}));var zu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),re=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ne=new Uint32Array(64),yo=class extends Le{constructor(){super(64,32,8,!1),this.A=re[0]|0,this.B=re[1]|0,this.C=re[2]|0,this.D=re[3]|0,this.E=re[4]|0,this.F=re[5]|0,this.G=re[6]|0,this.H=re[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)ne[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=ne[f-15],g=ne[f-2],b=Et(h,7)^Et(h,18)^h>>>3,x=Et(g,17)^Et(g,19)^g>>>10;ne[f]=x+ne[f-7]+b+ne[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Et(a,6)^Et(a,11)^Et(a,25),g=l+h+Is(a,c,u)+zu[f]+ne[f]|0,x=(Et(n,2)^Et(n,13)^Et(n,22))+Bs(n,o,s)|0;l=u,u=c,c=a,a=i+g|0,i=s,s=o,o=n,n=g+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){ne.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ii=lr(()=>new yo);function et(r,t="utf8"){let e=Ir[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}function yt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=gt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ci=Symbol.for("@achingbrain/uint8arraylist");function ai(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Rr(r){return!!r?.[ci]}var oe=class r{bufs;length;[ci]=!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(Rr(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(Rr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ai(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ai(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Rr(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 yt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:yt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Rr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let h=u;h>=0;h--){let g=this.get(f+h);if(n[h]!==g){l=Math.max(1,h-a[g]);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=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=_t(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=_t(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=_t(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=_t(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=_t(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=_t(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=_t(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=_t(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!bt(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 Qe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Pr=class extends Be{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,vs(t);let n=He(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(this),Ae(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},wo=(r,t,e)=>new Pr(r,t).update(e).digest();wo.create=(r,t)=>new Pr(r,t);function ui(r){r.lowS!==void 0&&St("lowS",r.lowS),r.prehash!==void 0&&St("prehash",r.prehash)}function qu(r){let t=je(r);Tt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Vu,hexToBytes:Hu}=gr,Eo=class extends Error{constructor(t=""){super(t)}},Gt={Err:Eo,_tlv:{encode:(r,t)=>{let{Err:e}=Gt;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=ae(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ae(o.length/2|128):"";return ae(r)+s+o+t},decode(r,t){let{Err:e}=Gt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Gt;if(r<jt)throw new t("integer: negative integers are not allowed");let e=ae(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}=Gt;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 Vu(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Gt,o=typeof r=="string"?Hu(r):r;Te(o);let{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=Gt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},jt=BigInt(0),ot=BigInt(1),e0=BigInt(2),fi=BigInt(3),r0=BigInt(4);function Ku(r){let t=qu(r),{Fp:e}=t,n=Jt(t.n,t.nBitLength),o=t.toBytes||((x,d,w)=>{let S=d.toAffine();return zt(Uint8Array.from([4]),e.toBytes(S.x),e.toBytes(S.y))}),s=t.fromBytes||(x=>{let d=x.subarray(1),w=e.fromBytes(d.subarray(0,e.BYTES)),S=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:w,y:S}});function i(x){let{a:d,b:w}=t,S=e.sqr(x),m=e.mul(S,x);return e.add(e.add(m,e.mul(x,d)),w)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(x){return Ke(x,ot,t.n)}function c(x){let{allowedPrivateKeyLengths:d,nByteLength:w,wrapPrivateKey:S,n:m}=t;if(d&&typeof x!="bigint"){if(Xt(x)&&(x=Ft(x)),typeof x!="string"||!d.includes(x.length))throw new Error("invalid private key");x=x.padStart(w*2,"0")}let A;try{A=typeof x=="bigint"?x:Mt(X("private key",x,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof x)}return S&&(A=H(A,m)),pt("private key",A,ot,m),A}function u(x){if(!(x instanceof h))throw new Error("ProjectivePoint expected")}let l=fe((x,d)=>{let{px:w,py:S,pz:m}=x;if(e.eql(m,e.ONE))return{x:w,y:S};let A=x.is0();d==null&&(d=A?e.ONE:e.inv(m));let R=e.mul(w,d),P=e.mul(S,d),I=e.mul(m,d);if(A)return{x:e.ZERO,y:e.ZERO};if(!e.eql(I,e.ONE))throw new Error("invZ was invalid");return{x:R,y:P}}),f=fe(x=>{if(x.is0()){if(t.allowInfinityPoint&&!e.is0(x.py))return;throw new Error("bad point: ZERO")}let{x:d,y:w}=x.toAffine();if(!e.isValid(d)||!e.isValid(w))throw new Error("bad point: x or y not FE");let S=e.sqr(w),m=i(d);if(!e.eql(S,m))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,w,S){if(this.px=d,this.py=w,this.pz=S,d==null||!e.isValid(d))throw new Error("x required");if(w==null||!e.isValid(w))throw new Error("y required");if(S==null||!e.isValid(S))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:w,y:S}=d||{};if(!d||!e.isValid(w)||!e.isValid(S))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let m=A=>e.eql(A,e.ZERO);return m(w)&&m(S)?h.ZERO:new h(w,S,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let w=e.invertBatch(d.map(S=>S.pz));return d.map((S,m)=>S.toAffine(w[m])).map(h.fromAffine)}static fromHex(d){let w=h.fromAffine(s(X("pointHex",d)));return w.assertValidity(),w}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,w){return wr(h,n,d,w)}_setWindowSize(d){b.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){u(d);let{px:w,py:S,pz:m}=this,{px:A,py:R,pz:P}=d,I=e.eql(e.mul(w,P),e.mul(A,m)),T=e.eql(e.mul(S,P),e.mul(R,m));return I&&T}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:w}=t,S=e.mul(w,fi),{px:m,py:A,pz:R}=this,P=e.ZERO,I=e.ZERO,T=e.ZERO,B=e.mul(m,m),j=e.mul(A,A),M=e.mul(R,R),O=e.mul(m,A);return O=e.add(O,O),T=e.mul(m,R),T=e.add(T,T),P=e.mul(d,T),I=e.mul(S,M),I=e.add(P,I),P=e.sub(j,I),I=e.add(j,I),I=e.mul(P,I),P=e.mul(O,P),T=e.mul(S,T),M=e.mul(d,M),O=e.sub(B,M),O=e.mul(d,O),O=e.add(O,T),T=e.add(B,B),B=e.add(T,B),B=e.add(B,M),B=e.mul(B,O),I=e.add(I,B),M=e.mul(A,R),M=e.add(M,M),B=e.mul(M,O),P=e.sub(P,B),T=e.mul(M,j),T=e.add(T,T),T=e.add(T,T),new h(P,I,T)}add(d){u(d);let{px:w,py:S,pz:m}=this,{px:A,py:R,pz:P}=d,I=e.ZERO,T=e.ZERO,B=e.ZERO,j=t.a,M=e.mul(t.b,fi),O=e.mul(w,A),Q=e.mul(S,R),v=e.mul(m,P),L=e.add(w,S),y=e.add(A,R);L=e.mul(L,y),y=e.add(O,Q),L=e.sub(L,y),y=e.add(w,m);let p=e.add(A,P);return y=e.mul(y,p),p=e.add(O,v),y=e.sub(y,p),p=e.add(S,m),I=e.add(R,P),p=e.mul(p,I),I=e.add(Q,v),p=e.sub(p,I),B=e.mul(j,y),I=e.mul(M,v),B=e.add(I,B),I=e.sub(Q,B),B=e.add(Q,B),T=e.mul(I,B),Q=e.add(O,O),Q=e.add(Q,O),v=e.mul(j,v),y=e.mul(M,y),Q=e.add(Q,v),v=e.sub(O,v),v=e.mul(j,v),y=e.add(y,v),O=e.mul(Q,y),T=e.add(T,O),O=e.mul(p,y),I=e.mul(L,I),I=e.sub(I,O),O=e.mul(L,Q),B=e.mul(p,B),B=e.add(B,O),new h(I,T,B)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return b.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:w,n:S}=t;pt("scalar",d,jt,S);let m=h.ZERO;if(d===jt)return m;if(this.is0()||d===ot)return this;if(!w||b.hasPrecomputes(this))return b.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:A,k1:R,k2neg:P,k2:I}=w.splitScalar(d),T=m,B=m,j=this;for(;R>jt||I>jt;)R&ot&&(T=T.add(j)),I&ot&&(B=B.add(j)),j=j.double(),R>>=ot,I>>=ot;return A&&(T=T.negate()),P&&(B=B.negate()),B=new h(e.mul(B.px,w.beta),B.py,B.pz),T.add(B)}multiply(d){let{endo:w,n:S}=t;pt("scalar",d,ot,S);let m,A;if(w){let{k1neg:R,k1:P,k2neg:I,k2:T}=w.splitScalar(d),{p:B,f:j}=this.wNAF(P),{p:M,f:O}=this.wNAF(T);B=b.constTimeNegate(R,B),M=b.constTimeNegate(I,M),M=new h(e.mul(M.px,w.beta),M.py,M.pz),m=B.add(M),A=j.add(O)}else{let{p:R,f:P}=this.wNAF(d);m=R,A=P}return h.normalizeZ([m,A])[0]}multiplyAndAddUnsafe(d,w,S){let m=h.BASE,A=(P,I)=>I===jt||I===ot||!P.equals(m)?P.multiplyUnsafe(I):P.multiply(I),R=A(this,w).add(A(d,S));return R.is0()?void 0:R}toAffine(d){return l(this,d)}isTorsionFree(){let{h:d,isTorsionFree:w}=t;if(d===ot)return!0;if(w)return w(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:w}=t;return d===ot?this:w?w(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return St("isCompressed",d),this.assertValidity(),o(h,this,d)}toHex(d=!0){return St("isCompressed",d),Ft(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,b=yr(h,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function Gu(r){let t=je(r);return Tt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function li(r){let t=Gu(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(v){return H(v,n)}function a(v){return br(v,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=Ku({...t,toBytes(v,L,y){let p=L.toAffine(),E=e.toBytes(p.x),_=zt;return St("isCompressed",y),y?_(Uint8Array.from([L.hasEvenY()?2:3]),E):_(Uint8Array.from([4]),E,e.toBytes(p.y))},fromBytes(v){let L=v.length,y=v[0],p=v.subarray(1);if(L===o&&(y===2||y===3)){let E=Mt(p);if(!Ke(E,ot,e.ORDER))throw new Error("Point is not on curve");let _=l(E),N;try{N=e.sqrt(_)}catch(F){let k=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+k)}let D=(N&ot)===ot;return(y&1)===1!==D&&(N=e.neg(N)),{x:E,y:N}}else if(L===s&&y===4){let E=e.fromBytes(p.subarray(0,e.BYTES)),_=e.fromBytes(p.subarray(e.BYTES,2*e.BYTES));return{x:E,y:_}}else{let E=o,_=s;throw new Error("invalid Point, expected length of "+E+", or uncompressed "+_+", got "+L)}}}),h=v=>Ft(Qt(v,t.nByteLength));function g(v){let L=n>>ot;return v>L}function b(v){return g(v)?i(-v):v}let x=(v,L,y)=>Mt(v.slice(L,y));class d{constructor(L,y,p){this.r=L,this.s=y,this.recovery=p,this.assertValidity()}static fromCompact(L){let y=t.nByteLength;return L=X("compactSignature",L,y*2),new d(x(L,0,y),x(L,y,2*y))}static fromDER(L){let{r:y,s:p}=Gt.toSig(X("DER",L));return new d(y,p)}assertValidity(){pt("r",this.r,ot,n),pt("s",this.s,ot,n)}addRecoveryBit(L){return new d(this.r,this.s,L)}recoverPublicKey(L){let{r:y,s:p,recovery:E}=this,_=P(X("msgHash",L));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");let N=E===2||E===3?y+t.n:y;if(N>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(E&1)===0?"02":"03",C=c.fromHex(D+h(N)),F=a(N),k=i(-_*F),q=i(p*F),K=c.BASE.multiplyAndAddUnsafe(C,k,q);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return ce(this.toDERHex())}toDERHex(){return Gt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ce(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let w={isValidPrivateKey(v){try{return u(v),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let v=kn(t.n);return Cs(t.randomBytes(v),t.n)},precompute(v=8,L=c.BASE){return L._setWindowSize(v),L.multiply(BigInt(3)),L}};function S(v,L=!0){return c.fromPrivateKey(v).toRawBytes(L)}function m(v){let L=Xt(v),y=typeof v=="string",p=(L||y)&&v.length;return L?p===o||p===s:y?p===2*o||p===2*s:v instanceof c}function A(v,L,y=!0){if(m(v))throw new Error("first arg must be private key");if(!m(L))throw new Error("second arg must be public key");return c.fromHex(L).multiply(u(v)).toRawBytes(y)}let R=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let L=Mt(v),y=v.length*8-t.nBitLength;return y>0?L>>BigInt(y):L},P=t.bits2int_modN||function(v){return i(R(v))},I=Ge(t.nBitLength);function T(v){return pt("num < 2^"+t.nBitLength,v,jt,I),Qt(v,t.nByteLength)}function B(v,L,y=j){if(["recovered","canonical"].some(nt=>nt in y))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:E}=t,{lowS:_,prehash:N,extraEntropy:D}=y;_==null&&(_=!0),v=X("msgHash",v),ui(y),N&&(v=X("prehashed msgHash",p(v)));let C=P(v),F=u(L),k=[T(F),T(C)];if(D!=null&&D!==!1){let nt=D===!0?E(e.BYTES):D;k.push(X("extraEntropy",nt))}let q=zt(...k),K=C;function rt(nt){let st=R(nt);if(!f(st))return;let it=a(st),ht=c.BASE.multiply(st).toAffine(),lt=i(ht.x);if(lt===jt)return;let Lt=i(it*i(K+lt*F));if(Lt===jt)return;let Rt=(ht.x===lt?0:2)|Number(ht.y&ot),Ce=Lt;return _&&g(Lt)&&(Ce=b(Lt),Rt^=1),new d(lt,Ce,Rt)}return{seed:q,k2sig:rt}}let j={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function O(v,L,y=j){let{seed:p,k2sig:E}=B(v,L,y),_=t;return Rn(_.hash.outputLen,_.nByteLength,_.hmac)(p,E)}c.BASE._setWindowSize(8);function Q(v,L,y,p=M){let E=v;L=X("msgHash",L),y=X("publicKey",y);let{lowS:_,prehash:N,format:D}=p;if(ui(p),"strict"in p)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let C=typeof E=="string"||Xt(E),F=!C&&!D&&typeof E=="object"&&E!==null&&typeof E.r=="bigint"&&typeof E.s=="bigint";if(!C&&!F)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let k,q;try{if(F&&(k=new d(E.r,E.s)),C){try{D!=="compact"&&(k=d.fromDER(E))}catch(Rt){if(!(Rt instanceof Gt.Err))throw Rt}!k&&D!=="der"&&(k=d.fromCompact(E))}q=c.fromHex(y)}catch{return!1}if(!k||_&&k.hasHighS())return!1;N&&(L=t.hash(L));let{r:K,s:rt}=k,nt=P(L),st=a(rt),it=i(nt*st),ht=i(K*st),lt=c.BASE.multiplyAndAddUnsafe(q,it,ht)?.toAffine();return lt?i(lt.x)===K:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:A,sign:O,verify:Q,ProjectivePoint:c,Signature:d,utils:w}}function ju(r){return{hash:r,hmac:(t,...e)=>wo(r,t,vn(...e)),randomBytes:hr}}function hi(r,t){let e=n=>li({...r,...ju(n)});return{...e(t),create:e}}var mi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),di=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Zu=BigInt(1),So=BigInt(2),pi=(r,t)=>(r+t/So)/t;function $u(r){let t=mi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=$(l,e,t)*l%t,h=$(f,e,t)*l%t,g=$(h,So,t)*u%t,b=$(g,o,t)*g%t,x=$(b,s,t)*b%t,d=$(x,a,t)*x%t,w=$(d,c,t)*d%t,S=$(w,a,t)*x%t,m=$(S,e,t)*l%t,A=$(m,i,t)*b%t,R=$(A,n,t)*u%t,P=$(R,So,t);if(!vo.eql(vo.sqr(P),r))throw new Error("Cannot find square root");return P}var vo=Jt(mi,void 0,void 0,{sqrt:$u}),pe=hi({a:BigInt(0),b:BigInt(7),Fp:vo,n:di,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=di,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Zu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=pi(s*r,t),c=pi(-n*r,t),u=H(r-a*e-c*o,t),l=H(-a*n-c*s,t),f=u>i,h=l>i;if(f&&(u=t-u),h&&(l=t-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},ii),l0=BigInt(0);var h0=pe.ProjectivePoint;function gi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function bi(r,t,e){let n=Ze.digest(e instanceof Uint8Array?e:e.subarray());if(gi(n))return n.then(({digest:o})=>pe.verify(t,o,r)).catch(o=>{throw new Qe(String(o))});try{return pe.verify(t,n.digest,r)}catch(o){throw new Qe(String(o))}}var Nr=class{type="secp256k1";raw;_key;constructor(t){this._key=yi(t),this.raw=xi(this._key)}toMultihash(){return Ct.digest(_r(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return bi(this._key,e,t)}};function wi(r){return new Nr(r)}function xi(r){return pe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function yi(r){try{return pe.ProjectivePoint.fromHex(r),r}catch(t){throw new ir(String(t))}}function Ei(r){let{Type:t,Data:e}=Ye.decode(r.digest),n=e??new Uint8Array;switch(t){case wt.Ed25519:return js(n);case wt.secp256k1:return wi(n);default:throw new Fe}}function _r(r){return Ye.encode({Type:wt[r.type],Data:r.raw})}var Si=Symbol.for("nodejs.util.inspect.custom"),Wu=114,Je=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[hn]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Wu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Si](){return`PeerId(${this.toString()})`}},Dr=class extends Je{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},kr=class extends Je{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Ur=class extends Je{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Xu=2336,Cr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ct.digest(tt(this.url))}[Si](){return`PeerId(${this.url})`}[hn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Xu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};function Or(r){if(Qu(r))return new Dr({multihash:r});if(Yu(r))try{let t=Ei(r);if(t.type==="Ed25519")return new kr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Ur({multihash:r,publicKey:t})}catch{let e=et(r.digest);return new Cr(new URL(e))}throw new ar("Supplied PeerID Multihash is invalid")}function Yu(r){return r.code===Ct.code}function Qu(r){return r.code===Ze.code}function _o(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Fr(r){let t=kt(W.decode(`z${r}`));return Or(t)}var Mr=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return _o(this.set.entries(),t=>{let e=Fr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Fr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return _o(this.set.values(),t=>Fr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Ao(){return new Mr}var Io={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},vi={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},_i=new globalThis.TextEncoder;function Ju(r,t){let e=Io[t],n=vi[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function tf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Io[t],o=vi[t],s=r;for(;s.length>0;){let i=_i.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 Bo(r,{size:t=32,utf8Buffer:e}={}){if(!Io[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 tf(r,t,e);r=_i.encode(r)}return Ju(r,t)}var tr={hash:r=>Number(Bo(r,{size:32})),hashV:(r,t)=>ef(tr.hash(r,t))};function ef(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),tt(t,"base16")}var Lo=64,It=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Lo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=_t(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?bt(this.fp,t.fp):!1}};function me(r,t){return Math.floor(Math.random()*(t-r))+r}var ge=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");let e=me(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof It))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var rf=500,er=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??tr,this.seed=t.seed??me(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=tt(t));let e=new It(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ge(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ge(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[me(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ge(this.bucketSize));for(let a=0;a<rf;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ge(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=tt(t));let e=new It(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=tt(t));let e=new It(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},nf={1:.5,2:.84,4:.95,8:.98};function of(r=.001){return r>.002?2:r>1e-5?4:8}function Ai(r,t=.001){let e=of(t),n=nf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Lo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var 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??tr,this.seed=t.seed??me(0,Math.pow(2,10)),this.filterSeries=[new er({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=tt(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new er({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=tt(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=tt(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function To(r,t=.001,e){return new zr({...Ai(r,t),...e??{}})}var qr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let 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>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ii=45,sf=15,Ne=new qr;function Vr(r){if(!(r.length>sf))return Ne.new(r).parseWith(()=>Ne.readIPv4Addr())}function Hr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ii))return Ne.new(r).parseWith(()=>Ne.readIPv6Addr())}function be(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Ii)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 Bi(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 Li(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 Ro(r){switch(r.length){case xe:return r.join(".");case ye:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Ti(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 Ri(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var xe=4,ye=16,Yp=parseInt("0xFFFF",16),af=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function rr(r,t){t.length===ye&&r.length===xe&&Bi(t,0,11)&&(t=t.slice(12)),t.length===xe&&r.length===ye&&Li(r,af,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 Pi(r,t){if(typeof t=="string"&&(t=be(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Po(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=xe,o=Vr(t);if(o==null&&(n=ye,o=Hr(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=No(s,8*n);return{network:rr(o,i),mask:i}}function No(r,t){if(t!==8*xe&&t!==8*ye)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var De=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Po(t));else{let n=be(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=be(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=No(o,8*n.length);this.network=rr(n,this.mask)}}contains(t){return Pi({network:this.network,mask:this.mask},t)}toString(){let t=Ti(this.mask),e=t!==-1?String(t):Ri(this.mask);return Ro(this.network)+"/"+e}};function Ni(r,t){return new De(r).contains(t)}var cf=41;function Di(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===cf)return Ni("2000::/3",e)}catch{}return!1}function Kr(r){return!!Vr(r)}function Gr(r){return!!Hr(r)}function jr(r){return!!be(r)}var Ui=ma(ki(),1),uf=["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"],ff=uf.map(r=>new Ui.Netmask(r));function Do(r){for(let t of ff)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 hf(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 Do(o)}function df(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function pf(r){let t=r.split(":"),e=t[t.length-1];return Do(e)}function mf(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 Ci(r){return Kr(r)?Do(r):lf(r)?hf(r):df(r)?pf(r):Gr(r)?mf(r):void 0}function Oi(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function ko(r){try{if(!Oi(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:Ci(t)??!1}catch{}return!0}function Bt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Zr=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 Zr(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 Zr(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 Uo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Fi(r={}){return gf(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 gf(r,t){t=t??{};let e=t.onEnd,n=new ke,o,s,i,a=Bt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,w)=>{s=S=>{s=null,n.push(S);try{d(r(n))}catch(m){w(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Bt()})}},u=d=>s!=null?s(d):(n.push(d),o),l=d=>(n=new ke,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 u({done:!1,value:d})},h=d=>i?o:(i=!0,d!=null?l(d):u({done:!0})),g=()=>(n=new ke,h(),{done:!0}),b=d=>(h(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:b,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let w=d?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let S,m;w!=null&&(S=new Promise((A,R)=>{m=()=>{R(new Uo)},w.addEventListener("abort",m)}));try{await Promise.race([a.promise,S])}finally{m!=null&&w!=null&&w?.removeEventListener("abort",m)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(d){return x.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return x.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:d=>x.onEmpty(d)},o}var Co=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 $r(r,t,e,n){let o=new Co(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",l),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),i(h);return}a(),s(f)},u=f=>{a(),i(f.detail)},l=()=>{a(),i(o)};e?.addEventListener("abort",l),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}var Wr=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Xr=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 we(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Xr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Xr(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 Yr=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Bt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Pt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function xf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Qr=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=xf(),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 Pt),this.cleanup())}async join(t={}){let e=new Yr(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 we(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 Jr=class extends cr{concurrency;maxSize;queue;pending;sort;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Wr;let n=new Qr(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 Pt)}),this.clear()}async onEmpty(t){this.size!==0&&await $r(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await $r(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await $r(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=Fi({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail)},i=()=>{n()},a=()=>{n(new Pt("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 tn=class extends Jr{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function en(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 Mi(r,t,e){let n,o;function s(){let a={signal:o.signal};if(e?.timeout!=null){let c=en([o.signal,AbortSignal.timeout(e.timeout)]);a.signal=c}Promise.resolve().then(async()=>{await r(a)}).catch(()=>{}).finally(()=>{o.signal.aborted||(n=setTimeout(s,t))})}let i=!1;return{setInterval:a=>{t=a,n!=null&&(clearTimeout(n),n=setTimeout(s,t))},setTimeout:a=>{e==null&&(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 zi=Kr,yf=Gr,Oo=function(r){let t=0;if(r=r.toString().trim(),zi(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(yf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=zi(e[n]),i;s&&(i=Oo(e[n]),e[n]=et(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,et(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},qi=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ue={},Fo={},Ef=[[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"]];Ef.forEach(r=>{let t=Sf(...r);Fo[t.code]=t,Ue[t.name]=t});function Sf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function V(r){if(typeof r=="number"){if(Fo[r]!=null)return Fo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ue[r]!=null)return Ue[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var lg=V("ip4"),hg=V("ip6"),dg=V("ipcidr");function Vo(r,t){switch(V(r).code){case 4:case 41:return _f(t);case 42:return qo(t);case 43:return et(t,"base10");case 6:case 273:case 33:case 132:return Ki(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return qo(t);case 421:return Lf(t);case 444:return Hi(t);case 445:return Hi(t);case 466:return Bf(t);case 481:return globalThis.encodeURIComponent(qo(t));default:return et(t,"base16")}}function Ho(r,t){switch(V(r).code){case 4:return Vi(t);case 41:return Vi(t);case 42:return zo(t);case 43:return tt(t,"base10");case 6:case 273:case 33:case 132:return Ko(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return zo(t);case 421:return Af(t);case 444:return Tf(t);case 445:return Rf(t);case 466:return If(t);case 481:return zo(globalThis.decodeURIComponent(t));default:return tt(t,"base16")}}var Mo=Object.values($e).map(r=>r.decoder),vf=function(){let r=Mo[0].or(Mo[1]);return Mo.slice(2).forEach(t=>r=r.or(t)),r}();function Vi(r){if(!jr(r))throw new Error("invalid ip address");return Oo(r)}function _f(r){let t=qi(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!jr(t))throw new Error("invalid ip address");return t}function Ko(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Ki(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function zo(r){let t=tt(r),e=Uint8Array.from(te(t.length));return yt([e,t],e.length+t.length)}function qo(r){let t=qt(r);if(r=r.slice(ut(t)),r.length!==t)throw new Error("inconsistent lengths");return et(r)}function Af(r){let t;r[0]==="Q"||r[0]==="1"?t=kt(W.decode(`z${r}`)).bytes:t=at.parse(r).multihash.bytes;let e=Uint8Array.from(te(t.length));return yt([e,t],e.length+t.length)}function If(r){let t=vf.decode(r),e=Uint8Array.from(te(t.length));return yt([e,t],e.length+t.length)}function Bf(r){let t=qt(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+et(e,"base64url")}function Lf(r){let t=qt(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return et(e,"base58btc")}function Tf(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=Dt.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=Ko(n);return yt([e,o],e.length+o.length)}function Rf(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=Dt.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=Ko(n);return yt([e,o],e.length+o.length)}function Hi(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=et(t,"base32"),o=Ki(e);return`${n}:${o}`}function Gi(r){r=Go(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=V(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new rn("invalid address: "+r);if(a.path===!0){n=Go(o.slice(s).join("/")),t.push([a.code,Ho(a.code,n)]),e.push([a.code,n]);break}let c=Ho(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Vo(a.code,c)])}return{string:ji(e),bytes:nn(t),tuples:t,stringTuples:e,path:n}}function jo(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=qt(r,o),i=ut(s),a=V(s),c=Pf(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let u=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw new rn("Invalid address Uint8Array: "+et(r,"base16"));t.push([s,u]);let l=Vo(s,u);if(e.push([s,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:ji(e),tuples:t,stringTuples:e,path:n}}function ji(r){let t=[];return r.map(e=>{let n=V(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Go(t.join("/"))}function nn(r){return yt(r.map(t=>{let e=V(t[0]),n=Uint8Array.from(te(e.code));return t.length>1&&t[1]!=null&&(n=yt([n,t[1]])),n}))}function Pf(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=qt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ut(e)}}function Go(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var rn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Nf=Symbol.for("nodejs.util.inspect.custom"),$o=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Df=[V("dns").code,V("dns4").code,V("dns6").code,V("dnsaddr").code],Zo=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},on=class r{bytes;#t;#e;#r;#n;[$o]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=jo(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Gi(t)}else if($i(t))e=jo(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=V("tcp"),a=V("udp"),c=V("ip4"),u=V("ip6"),l=V("dns6"),f=V("ip6zone");for(let[g,b]of this.stringTuples())g===f.code&&(s=`%${b??""}`),Df.includes(g)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${b??""}${s}`,t=g===l.code?6:4),(g===i.code||g===a.code)&&(e=V(g).name==="tcp"?"tcp":"udp",o=parseInt(b??"")),(g===c.code||g===u.code)&&(e=V(g).name==="tcp"?"tcp":"udp",n=`${b??""}${s}`,t=g===u.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({},V(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>V(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(nn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ue.p2p.code&&t.push([n,o]),n===Ue["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?et(W.decode(`z${n}`),"base58btc"):et(at.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Zi.get(e.name);if(n==null)throw new Zo(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>or(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)}[Nf](){return`Multiaddr(${this.#t})`}};var Zi=new Map;function $i(r){return!!r?.[$o]}function or(r){return new on(r)}var Wo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Bt(),this.haveNext=Bt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Bt(),t}async throw(t){return this.ended=!0,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=Bt(),await we(this.readNext.promise,e?.signal,e)}};function Wi(){return new Wo}var sn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Xi(r,t){let e=Wi();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 oe;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:c,value:u}=await we(n.next(),i?.signal);return c===!0?null:u}for(;o.byteLength<i.bytes;){let{value:c,done:u}=await we(n.next(),i?.signal);if(u===!0)throw new sn("unexpected end of input");o.append(c)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var an=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},cn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},un=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Yi(r,t={}){let e=Xi(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=ut(t.maxDataLength));let n=t?.lengthDecoder??qt,o=t?.lengthEncoder??te;return{read:async i=>{let a=-1,c=new oe;for(;;){c.append(await e.read({...i,bytes:1}));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new an("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new un("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new cn("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new oe(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new oe(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function Xo(r,t){let e=Yi(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 Qi="libp2p",Ji="autonat",ta="1.0.0";var G;(function(r){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(u){u.codec=()=>Pe(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(u){u.codec=()=>Pe(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,h,g={})=>{if(g.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);g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let b={addrs:[]},x=h==null?f.len:f.pos+h;for(;f.pos<x;){let d=f.uint32();switch(d>>>3){case 1:{b.id=f.bytes();break}case 2:{if(g.limits?.addrs!=null&&b.addrs.length===g.limits.addrs)throw new Tr('Decode error - map field "addrs" had too many elements');b.addrs.push(f.bytes());break}default:{f.skipType(d&7);break}}}return b})),l),u.encode=f=>Ht(f,u.codec()),u.decode=(f,h)=>Vt(f,u.codec(),h)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,h,g={})=>{g.lengthDelimited!==!1&&h.fork(),f.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(f.peer,h)),g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let b={},x=h==null?f.len:f.pos+h;for(;f.pos<x;){let d=f.uint32();switch(d>>>3){case 1:{b.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:g.limits?.peer});break}default:{f.skipType(d&7);break}}}return b})),l),u.encode=f=>Ht(f,u.codec()),u.decode=(f,h)=>Vt(f,u.codec(),h)})(i=r.Dial||(r.Dial={}));let a;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,h,g={})=>{g.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)),g.lengthDelimited!==!1&&h.ldelim()},(f,h,g={})=>{let b={},x=h==null?f.len:f.pos+h;for(;f.pos<x;){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),u.encode=f=>Ht(f,u.codec()),u.decode=(f,h)=>Vt(f,u.codec(),h)})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=Kt((u,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),u.type!=null&&(l.uint32(8),r.MessageType.codec().encode(u.type,l)),u.dial!=null&&(l.uint32(18),r.Dial.codec().encode(u.dial,l)),u.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(u.dialResponse,l)),f.lengthDelimited!==!1&&l.ldelim()},(u,l,f={})=>{let h={},g=l==null?u.len:u.pos+l;for(;u.pos<g;){let b=u.uint32();switch(b>>>3){case 1:{h.type=r.MessageType.codec().decode(u);break}case 2:{h.dial=r.Dial.codec().decode(u,u.uint32(),{limits:f.limits?.dial});break}case 3:{h.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:f.limits?.dialResponse});break}default:{u.skipType(b&7);break}}}return h})),c),r.encode=u=>Ht(u,r.codec()),r.decode=(u,l)=>Vt(u,r.codec(),l)})(G||(G={}));var Mf=4,zf=8,fn=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??Qi}/${Ji}/${ta}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.connectionThreshold=e.connectionThreshold??80,this.maxMessageSize=e.maxMessageSize??8192,this.dialResults=new Map,this.findPeers=Mi(this.findRandomPeers.bind(this),6e4),this.addressFilter=To(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ss]=["@libp2p/autonat"];get[is](){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=en([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=Xo(t.stream,{maxDataLength:this.maxMessageSize}).pb(G);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:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.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:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=kt(a.id);i=Or(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.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:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(f=>or(f)).filter(f=>{let h=f.toOptions();return ko(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(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(f=>f.toString()).join(", "),i);let u="",l=c[0];for await(let f of c){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:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(V("p2p").code).bytes}}}catch(g){this.log.error("could not dial %p - %e",i,g),u=g.message}finally{h!=null&&await h.close()}}return{type:G.MessageType.DIAL_RESPONSE,dialResponse:{status:G.ResponseStatus.E_DIAL_ERROR,statusText:u,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||!Di(o.multiaddr))||ko(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:Ao(),queue:new tn({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=Xo(i).pb(G),[,c]=await Promise.all([a.write({type:G.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==G.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let u=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==G.ResponseStatus.OK&&u!==G.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),u===G.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===G.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Mf&&this.confirmAddress(o),o.failure===zf&&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 qf(r={}){return t=>new fn(t,r)}return ga(Vf);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/autonat",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.28-071267286",
|
|
4
4
|
"description": "Implementation of Autonat Protocol",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-autonat#readme",
|
|
@@ -52,21 +52,21 @@
|
|
|
52
52
|
"doc-check": "aegir doc-check"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@libp2p/interface": "
|
|
56
|
-
"@libp2p/interface-internal": "
|
|
57
|
-
"@libp2p/peer-collections": "
|
|
58
|
-
"@libp2p/peer-id": "
|
|
59
|
-
"@libp2p/utils": "
|
|
55
|
+
"@libp2p/interface": "2.7.0-071267286",
|
|
56
|
+
"@libp2p/interface-internal": "2.3.9-071267286",
|
|
57
|
+
"@libp2p/peer-collections": "6.0.25-071267286",
|
|
58
|
+
"@libp2p/peer-id": "5.1.0-071267286",
|
|
59
|
+
"@libp2p/utils": "6.6.0-071267286",
|
|
60
60
|
"@multiformats/multiaddr": "^12.3.3",
|
|
61
61
|
"any-signal": "^4.1.1",
|
|
62
|
-
"it-protobuf-stream": "^
|
|
62
|
+
"it-protobuf-stream": "^2.0.1",
|
|
63
63
|
"multiformats": "^13.3.1",
|
|
64
64
|
"protons-runtime": "^5.5.0",
|
|
65
65
|
"uint8arraylist": "^2.4.8"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@libp2p/crypto": "
|
|
69
|
-
"@libp2p/logger": "
|
|
68
|
+
"@libp2p/crypto": "5.0.15-071267286",
|
|
69
|
+
"@libp2p/logger": "5.1.13-071267286",
|
|
70
70
|
"aegir": "^45.1.1",
|
|
71
71
|
"it-all": "^3.0.6",
|
|
72
72
|
"it-drain": "^3.0.7",
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATComponents.html",
|
|
3
|
-
".:AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATComponents.html",
|
|
4
|
-
"AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATServiceInit.html",
|
|
5
|
-
".:AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATServiceInit.html",
|
|
6
|
-
"autoNAT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_autonat.autoNAT.html",
|
|
7
|
-
".:autoNAT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_autonat.autoNAT.html"
|
|
8
|
-
}
|