@libp2p/autonat 3.0.26-47cf9cdc1 → 3.0.26-d5534174d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PAutonat=(()=>{var Vc=Object.create;var Or=Object.defineProperty;var jc=Object.getOwnPropertyDescriptor;var $c=Object.getOwnPropertyNames;var Zc=Object.getPrototypeOf,Yc=Object.prototype.hasOwnProperty;var Wn=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},bt=(e,t)=>{for(var r in t)Or(e,r,{get:t[r],enumerable:!0})},oi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $c(t))!Yc.call(e,o)&&o!==r&&Or(e,o,{get:()=>t[o],enumerable:!(n=jc(t,o))||n.enumerable});return e};var Gc=(e,t,r)=>(r=e!=null?Vc(Zc(e)):{},oi(t||!e||!e.__esModule?Or(r,"default",{value:e,enumerable:!0}):r,e)),Wc=e=>oi(Or({},"__esModule",{value:!0}),e);var Ps=Wn(Ze=>{"use strict";Object.defineProperty(Ze,"__esModule",{value:!0});Ze.Netmask4Impl=void 0;Ze.ip2long=$e;Ze.long2ip=kt;function kt(e){let t=(e&-16777216)>>>24,r=(e&255<<16)>>>16,n=(e&65280)>>>8,o=e&255;return[t,r,n,o].join(".")}var $l=48,Zl=97,Yl=65;function Gl(e){let t=0,r=10,n="9",o=0;e.length>1&&e[o]==="0"&&(e[o+1]==="x"||e[o+1]==="X"?(o+=2,r=16):"0"<=e[o+1]&&e[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<e.length;){if("0"<=e[o]&&e[o]<=n)t=t*r+(e.charCodeAt(o)-$l)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-Zl)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-Yl)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function $e(e){let t=[];for(let r=0;r<=3&&e.length!==0;r++){if(r>0){if(e[0]!==".")throw new Error("Invalid IP");e=e.substring(1)}let[n,o]=Gl(e);e=e.substring(o),t.push(n)}if(e.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var Os=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=$e(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=($e(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=kt(this.netLong),this.mask=kt(this.maskLong),this.hostmask=kt(~this.maskLong),this.first=this.bitmask<=30?kt(this.netLong+1):this.base,this.last=this.bitmask<=30?kt(this.netLong+this.size-2):kt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?kt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):($e(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new e(kt(this.netLong+this.size*t),this.mask)}forEach(t){let r=$e(this.first),n=$e(this.last),o=0;for(;r<=n;)t(kt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Ze.Netmask4Impl=Os});var yc=Wn(Ye=>{"use strict";Object.defineProperty(Ye,"__esModule",{value:!0});Ye.Netmask6Impl=void 0;Ye.ip6bigint=Ns;Ye.bigint2ip6=Se;var Wl=Ps(),ks=(1n<<128n)-1n;function Ns(e){let t=e.indexOf("%");t!==-1&&(e=e.substring(0,t));let r=e.lastIndexOf(":");if(r!==-1&&e.indexOf(".",r)!==-1){let n=e.substring(r+1),o=(0,Wl.ip2long)(n),s=e.substring(0,r+1)+"0:0";return gc(s)&~0xffffffffn|BigInt(o)}return gc(e)}function gc(e){let t=e.indexOf("::"),r;if(t!==-1){let o=e.substring(0,t),s=e.substring(t+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=e.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Se(e){if(e<0n||e>ks)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(e&0xffffn)),e>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return t.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=t.slice(0,r).map(c=>c.toString(16)),a=t.slice(r+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var Fs=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=ks>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ns(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Se(this.netBigint),this.mask=Se(this.maskBigint),this.hostmask=Se(~this.maskBigint&ks),this.first=this.base,this.last=Se(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.last):(Ns(t)&this.maskBigint)===this.netBigint}next(t=1){let r=1n<<BigInt(128-this.bitmask);return new e(Se(this.netBigint+r*BigInt(t)),this.bitmask)}forEach(t){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)t(Se(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};Ye.Netmask6Impl=Fs});var bc=Wn(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});ie.long2ip=ie.ip2long=ie.Netmask=void 0;var Pn=Ps();Object.defineProperty(ie,"ip2long",{enumerable:!0,get:function(){return Pn.ip2long}});Object.defineProperty(ie,"long2ip",{enumerable:!0,get:function(){return Pn.long2ip}});var Xl=yc(),Us=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new Xl.Netmask6Impl(t,r):this._impl=new Pn.Netmask4Impl(t,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Pn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new e(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new e(t))),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let r=this._impl.next(t);return new e(r.base,r.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ie.Netmask=Us});var wh={};bt(wh,{autoNAT:()=>bh});var Nt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ht=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Pr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var kr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var er=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Xn=Symbol.for("@libp2p/peer-id");function Xc(e){return typeof e?.handleEvent=="function"}function Qc(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Nr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let o=Qc(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#t.set(i.type,a))}Xc(r)?r.handleEvent(i):r(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:o})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var si=Symbol.for("@libp2p/service-capabilities"),ii=Symbol.for("@libp2p/service-dependencies");var ro={};bt(ro,{base58btc:()=>tt,base58flickr:()=>iu});var Gh=new Uint8Array(0);function ci(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function xt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ae(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ae(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function ui(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var ai=4096;function fi(e){let t=e.length;if(t<=ai)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=ai));return r}function Jc(e){return e?.buffer instanceof ArrayBuffer}function ae(e){return Jc(e)?e:e.slice()}function tu(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<e.length;s++){var i=e.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var l=e.length,h=e.charAt(0),f=Math.log(l)/Math.log(256),p=Math.log(256)/Math.log(l);function S(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var m=0,g=0,x=0,v=d.length;x!==v&&d[x]===0;)x++,m++;for(var C=(v-x)*p+1>>>0,M=new Uint8Array(C);x!==v;){for(var N=d[x],P=0,k=C-1;(N!==0||P<g)&&k!==-1;k--,P++)N+=256*M[k]>>>0,M[k]=N%l>>>0,N=N/l>>>0;if(N!==0)throw new Error("Non-zero carry");g=P,x++}for(var z=C-g;z!==C&&M[z]===0;)z++;for(var R=h.repeat(m);z<C;++z)R+=e.charAt(M[z]);return R}function E(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var m=0;if(d[m]!==" "){for(var g=0,x=0;d[m]===h;)g++,m++;for(var v=(d.length-m)*f+1>>>0,C=new Uint8Array(v);d[m];){var M=n[d.charCodeAt(m)];if(M===255)return;for(var N=0,P=v-1;(M!==0||N<x)&&P!==-1;P--,N++)M+=l*C[P]>>>0,C[P]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");x=N,m++}if(d[m]!==" "){for(var k=v-x;k!==v&&C[k]===0;)k++;for(var z=new Uint8Array(g+(v-k)),R=g;k!==v;)z[R++]=C[k++];return z}}}function w(d){var m=E(d);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:S,decodeUnsafe:E,decode:w}}var eu=tu,ru=eu,di=ru;var Qn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Jn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return hi(this,t)}},to=class{decoders;constructor(t){this.decoders=t}or(t){return hi(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function hi(e,t){return new to({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var eo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Qn(t,r,n),this.decoder=new Jn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ie({name:e,prefix:t,encode:r,decode:n}){return new eo(e,t,r,n)}function Zt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=di(r,e,n);return Ie({prefix:t,name:e,encode:o,decode:i=>xt(s(i))})}function nu(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=t[e[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ou(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function su(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let o=e[n].toLowerCase(),s=e[n].toUpperCase();o!==e[n]&&(r[o]=n),s!==e[n]&&(r[s]=n)}return r}function J({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=su(n,o);return Ie({prefix:t,name:e,encode(i){return ou(i,n,r)},decode(i){return nu(i,s,r,e)}})}var tt=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),iu=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var no={};bt(no,{base32:()=>Yt,base32hex:()=>fu,base32hexpad:()=>du,base32hexpadupper:()=>hu,base32hexupper:()=>lu,base32pad:()=>cu,base32padupper:()=>uu,base32upper:()=>au,base32z:()=>pu});var Yt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),au=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),cu=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),uu=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),fu=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),lu=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),du=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),hu=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),pu=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var oo={};bt(oo,{base36:()=>rr,base36upper:()=>mu});var rr=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),mu=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var gu=gi,pi=128,yu=127,bu=~yu,wu=Math.pow(2,31);function gi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=wu;)t[r++]=e&255|pi,e/=128;for(;e&bu;)t[r++]=e&255|pi,e>>>=7;return t[r]=e|0,gi.bytes=r-n+1,t}var xu=so,Eu=128,mi=127;function so(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw so.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&mi)<<o:(i&mi)*Math.pow(2,o),o+=7}while(i>=Eu);return so.bytes=s-n,r}var Su=Math.pow(2,7),vu=Math.pow(2,14),_u=Math.pow(2,21),Au=Math.pow(2,28),Iu=Math.pow(2,35),Bu=Math.pow(2,42),Tu=Math.pow(2,49),Lu=Math.pow(2,56),Du=Math.pow(2,63),Cu=function(e){return e<Su?1:e<vu?2:e<_u?3:e<Au?4:e<Iu?5:e<Bu?6:e<Tu?7:e<Lu?8:e<Du?9:10},Ru={encode:gu,decode:xu,encodingLength:Cu},Ou=Ru,nr=Ou;function or(e,t=0){let r=nr.decode(e,t),n=nr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Be(e,t,r=0){return nr.encode(e,t,r),t}function Te(e){return nr.encodingLength(e)}function De(e,t){let r=t.byteLength,n=Te(e),o=n+Te(r),s=new Uint8Array(o+r);return Be(e,s,0),Be(r,s,n),s.set(t,o),new Le(e,r,t,s)}function ce(e){let t=xt(e),[r,n]=or(t),[o,s]=or(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(r,o,i,t)}function yi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ci(e.bytes,r.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=ae(n),this.bytes=ae(o)}};function bi(e,t){let{bytes:r,version:n}=e;return n===0?ku(r,io(e),t??tt.encoder):Nu(r,io(e),t??Yt.encoder)}var wi=new WeakMap;function io(e){let t=wi.get(e);if(t==null){let r=new Map;return wi.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=ae(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==sr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Fu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=De(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&yi(t.multihash,n.multihash)}toString(t){return bi(this,t)}toJSON(){return{"/":bi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??xi(n,o,s.bytes))}else if(r[Uu]===!0){let{version:n,multihash:o,code:s}=r,i=ce(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==sr)throw new Error(`Version 0 CID must use dag-pb (code: ${sr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=xi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,sr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=xt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Le(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,f]=or(t.subarray(r));return r+=f,h},o=n(),s=sr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,r){let[n,o]=Pu(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return io(s).set(n,t),s}};function Pu(e,t){switch(e[0]){case"Q":{let r=t??tt;return[tt.prefix,r.decode(`${tt.prefix}${e}`)]}case tt.prefix:{let r=t??tt;return[tt.prefix,r.decode(e)]}case Yt.prefix:{let r=t??Yt;return[Yt.prefix,r.decode(e)]}case rr.prefix:{let r=t??rr;return[rr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function ku(e,t,r){let{prefix:n}=r;if(n!==tt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Nu(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var sr=112,Fu=18;function xi(e,t,r){let n=Te(e),o=n+Te(t),s=new Uint8Array(o+r.byteLength);return Be(e,s,0),Be(t,s,n),s.set(r,o),s}var Uu=Symbol.for("@ipld/js-cid/CID");var ao={};bt(ao,{identity:()=>_t});var Ei=0,Mu="identity",Si=xt;function zu(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return De(Ei,Si(e))}var _t={code:Ei,name:Mu,encode:Si,digest:zu};function ct(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Ku(e){return e.buffer instanceof ArrayBuffer}function At(e){return Ku(e)?e:e.slice()}async function vi(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,At(t),At(r.subarray()));return n?.signal?.throwIfAborted(),s}function Et(e=0){return new Uint8Array(e)}function ut(e=0){return new Uint8Array(e)}function qu(e){return e?.buffer instanceof ArrayBuffer}function co(e){if(qu(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Rt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ut(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return co(r)}var Ai=Symbol.for("@achingbrain/uint8arraylist");function _i(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Ur(e){return!!e?.[Ai]}var nt=class e{bufs;length;[Ai]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ur(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ur(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=_i(this.bufs,t);return r.buf[r.index]}set(t,r){let n=_i(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Ur(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Rt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Rt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=r>a&&r<=c;if(u&&l){if(t===a&&r===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Ur(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let h=r;h<=c;h+=l){l=0;for(let f=u;f>=0;f--){let p=this.get(h+f);if(n[f]!==p){l=Math.max(1,f-a[p]);break}}if(l===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ut(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ut(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ct(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var uo={};bt(uo,{base10:()=>Hu});var Hu=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var fo={};bt(fo,{base16:()=>Vu,base16upper:()=>ju});var Vu=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),ju=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var lo={};bt(lo,{base2:()=>$u});var $u=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ho={};bt(ho,{base256emoji:()=>Xu});var Ii=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}"),Zu=Ii.reduce((e,t,r)=>(e[r]=t,e),[]),Yu=Ii.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Gu(e){return e.reduce((t,r)=>(t+=Zu[r],t),"")}function Wu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Yu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Xu=Ie({prefix:"\u{1F680}",name:"base256emoji",encode:Gu,decode:Wu});var mo={};bt(mo,{base64:()=>Qu,base64pad:()=>Ju,base64url:()=>po,base64urlpad:()=>tf});var Qu=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ju=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),po=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),tf=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var go={};bt(go,{base8:()=>ef});var ef=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var yo={};bt(yo,{identity:()=>rf});var rf=Ie({prefix:"\0",name:"identity",encode:e=>fi(xt(e)),decode:e=>xt(ui(e))});var Pp=new TextEncoder,kp=new TextDecoder;var xo={};bt(xo,{sha256:()=>ir,sha512:()=>af});var sf=20;function wo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new bo(e,t,r,n,o)}var bo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??sf,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Bi(n,this.code,r?.truncate):n.then(o=>Bi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Bi(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return De(t,e)}function Li(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ir=wo({name:"sha2-256",code:18,encode:Li("SHA-256")}),af=wo({name:"sha2-512",code:19,encode:Li("SHA-512")});var ar={...yo,...lo,...go,...uo,...fo,...no,...oo,...ro,...mo,...ho},Zp={...xo,...ao};function Ci(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Di=Ci("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Eo=Ci("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ut(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),cf={utf8:Di,"utf-8":Di,hex:ar.base16,latin1:Eo,ascii:Eo,binary:Eo,...ar},Mr=cf;function Y(e,t="utf8"){let r=Mr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function et(e,t="utf8"){let r=Mr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var uf=parseInt("11111",2),So=parseInt("10000000",2),ff=parseInt("01111111",2),Ri={0:cr,1:cr,2:lf,3:pf,4:mf,5:hf,6:df,16:cr,22:cr,48:cr};function vo(e,t={offset:0}){let r=e[t.offset]&uf;if(t.offset++,Ri[r]!=null)return Ri[r](e,t);throw new Error("No decoder for tag "+r)}function ur(e,t){let r=0;if((e[t.offset]&So)===So){let n=e[t.offset]&ff,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");o+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function cr(e,t){ur(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=vo(e,t);if(n===null)break;r.push(n)}return r}function lf(e,t){let r=ur(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function df(e,t){let r=ur(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let h=0;h<c.length;h++)l+=c[h]<<h*7;a+=`.${l}`,c=[]}}return a}function hf(e,t){return t.offset++,null}function pf(e,t){let r=ur(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function mf(e,t){let r=ur(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function gf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new nt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function _o(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=gf(e.byteLength);return new nt(Uint8Array.from([t.byteLength|So]),t)}function Oi(e){let t=new nt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new nt(Uint8Array.from([2]),_o(t),t)}function Pi(e){let t=Uint8Array.from([0]),r=new nt(t,e);return new nt(Uint8Array.from([3]),_o(r),r)}function zr(e,t=48){let r=new nt;for(let n of e)r.append(n);return new nt(Uint8Array.from([t]),_o(r),r)}var yf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),bf=Uint8Array.from([6,5,43,129,4,0,34]),wf=Uint8Array.from([6,5,43,129,4,0,35]),xf={ext:!0,kty:"EC",crv:"P-256"},Ef={ext:!0,kty:"EC",crv:"P-384"},Sf={ext:!0,kty:"EC",crv:"P-521"},Ao=32,Io=48,Bo=66;function ki(e){let t=vo(e);return Ni(t)}function Ni(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ao*2+1)return n=et(t.subarray(r,r+Ao),"base64url"),o=et(t.subarray(r+Ao),"base64url"),new Ce({...xf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Io*2+1)return n=et(t.subarray(r,r+Io),"base64url"),o=et(t.subarray(r+Io),"base64url"),new Ce({...Ef,key_ops:["verify"],x:n,y:o});if(t.byteLength===Bo*2+1)return n=et(t.subarray(r,r+Bo),"base64url"),o=et(t.subarray(r+Bo),"base64url"),new Ce({...Sf,key_ops:["verify"],x:n,y:o});throw new ht(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Fi(e){return zr([Oi(Uint8Array.from([1])),zr([vf(e.crv)],160),zr([Pi(new nt(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function vf(e){if(e==="P-256")return yf;if(e==="P-384")return bf;if(e==="P-521")return wf;throw new ht(`Invalid curve ${e}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Fi(this.jwk)),this._raw}toMultihash(){return _t.digest(Re(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r,n){return vi(this.jwk,r,t,n)}};var Kr=BigInt(4294967295),Ui=BigInt(32);function _f(e,t=!1){return t?{h:Number(e&Kr),l:Number(e>>Ui&Kr)}:{h:Number(e>>Ui&Kr)|0,l:Number(e&Kr)|0}}function Mi(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=_f(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Af=e=>e/2**32|0,If=e=>e>>>0;function zi(e,t,r,n){let o=Af(r),s=If(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var To=(e,t,r)=>e>>>r,Lo=(e,t,r)=>e<<32-r|t>>>r,ue=(e,t,r)=>e>>>r|t<<32-r,fe=(e,t,r)=>e<<32-r|t>>>r,fr=(e,t,r)=>e<<64-r|t>>>r-32,lr=(e,t,r)=>e>>>r-32|t<<64-r;function Ot(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ki=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),qi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Hi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Vi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ji=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),$i=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function qr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Do=e=>e?`"${e}" `:"";function Ft(e,t=""){if(typeof e!="number")throw new TypeError(Do(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Do(t)+"expected integer >= 0, got "+e);return e}function St(e,t,r=""){if(qr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Ft(t,"length");let n=qr(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=Do(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function Hr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ft(e.outputLen),Ft(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Zi=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)};function Oe(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function Vr(e,t){St(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function le(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function jr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var Gi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Tf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $r(e){if(St(e),Gi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Tf[e[r]];return t}function Yi(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Zr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Gi)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Yi(e.charCodeAt(s)),a=Yi(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Co(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];St(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Lf(e,t,r="opts"){return Zi(e,"defaults"),t!==void 0&&Zi(t,r),Object.assign(e,t)}function Ro(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Lf({},t,"info");let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Wi(e=32){Ft(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Oo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Xi(e,t,r){return e&t^~e&r}function Qi(e,t,r){return e&t^e&r^t&r}var dr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=jr(this.buffer)}update(t){Oe(this),St(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=jr(t);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){Oe(this),Vr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),zi(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:jr(t),c=this.outputLen,u=c/4,l=this.get();if(c%4||u>l.length)throw new Error("invalid outputLen");for(let h=0;h<u;h++)a.setUint32(4*h,l[h],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(r),t}clone(){return this._cloneInto()}},Ji=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ta=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Df=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Wt=new Uint32Array(64),Po=class extends dr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let h=0;h<16;h++,r+=4)Wt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let f=Wt[h-15],p=Wt[h-2],S=It(f,7)^It(f,18)^f>>>3,E=It(p,17)^It(p,19)^p>>>10;Wt[h]=E+Wt[h-7]+S+Wt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let h=0;h<64;h++){let f=It(a,6)^It(a,11)^It(a,25),p=l+f+Xi(a,c,u)+Df[h]+Wt[h]|0,E=(It(n,2)^It(n,13)^It(n,22))+Qi(n,o,s)|0;l=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+E|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(){le(Wt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),le(this.buffer)}},ko=class extends Po{constructor(){super(32,Ji)}};var ea=Mi(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Cf=ea[0],Rf=ea[1],Xt=new Uint32Array(80),Qt=new Uint32Array(80),No=class extends dr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:h,Fl:f,Gh:p,Gl:S,Hh:E,Hl:w}=this;return[t,r,n,o,s,i,a,c,u,l,h,f,p,S,E,w]}set(t,r,n,o,s,i,a,c,u,l,h,f,p,S,E,w){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=h|0,this.Fl=f|0,this.Gh=p|0,this.Gl=S|0,this.Hh=E|0,this.Hl=w|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let g=0;g<16;g++,r+=4)Xt[g]=t.getUint32(r),Qt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let x=Xt[g-15]|0,v=Qt[g-15]|0,C=ue(x,v,1)^ue(x,v,8)^To(x,v,7),M=fe(x,v,1)^fe(x,v,8)^Lo(x,v,7),N=Xt[g-2]|0,P=Qt[g-2]|0,k=ue(N,P,19)^fr(N,P,61)^To(N,P,6),z=fe(N,P,19)^lr(N,P,61)^Lo(N,P,6),R=Hi(M,z,Qt[g-7],Qt[g-16]),Z=Vi(R,C,k,Xt[g-7],Xt[g-16]);Xt[g]=Z|0,Qt[g]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:h,El:f,Fh:p,Fl:S,Gh:E,Gl:w,Hh:d,Hl:m}=this;for(let g=0;g<80;g++){let x=ue(h,f,14)^ue(h,f,18)^fr(h,f,41),v=fe(h,f,14)^fe(h,f,18)^lr(h,f,41),C=h&p^~h&E,M=f&S^~f&w,N=ji(m,v,M,Rf[g],Qt[g]),P=$i(N,d,x,C,Cf[g],Xt[g]),k=N|0,z=ue(n,o,28)^fr(n,o,34)^fr(n,o,39),R=fe(n,o,28)^lr(n,o,34)^lr(n,o,39),Z=n&s^n&a^s&a,D=o&i^o&c^i&c;d=E|0,m=w|0,E=p|0,w=S|0,p=h|0,S=f|0,{h,l:f}=Ot(u|0,l|0,P|0,k|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let L=Ki(k,R,D);n=qi(L,P,z,Z),o=L|0}({h:n,l:o}=Ot(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ot(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ot(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Ot(this.Dh|0,this.Dl|0,u|0,l|0),{h,l:f}=Ot(this.Eh|0,this.El|0,h|0,f|0),{h:p,l:S}=Ot(this.Fh|0,this.Fl|0,p|0,S|0),{h:E,l:w}=Ot(this.Gh|0,this.Gl|0,E|0,w|0),{h:d,l:m}=Ot(this.Hh|0,this.Hl|0,d|0,m|0),this.set(n,o,s,i,a,c,u,l,h,f,p,S,E,w,d,m)}roundClean(){le(Xt,Qt)}destroy(){this.destroyed=!0,le(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Fo=class extends No{constructor(){super(64,ta)}};var ra=Ro(()=>new ko,Oo(1));var Uo=Ro(()=>new Fo,Oo(3));function Gr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var H=(e,t,r)=>St(e,t,r),Mo=Ft;function oa(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Jt(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function de(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var hr=$r,vt=(...e)=>Co(...e),Pe=e=>Zr(e),ee=qr,he=e=>Wi(e),Yr=BigInt(0),na=BigInt(1),Of=e=>e?`"${e}" `:"";function mt(e,t=""){if(typeof e!="boolean")throw new TypeError(Of(t)+"expected boolean, got type="+typeof e);return e}function Wr(e){if(typeof e=="bigint"){if(!te(e))throw new RangeError("positive bigint expected, got "+e)}else Mo(e);return e}function re(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function pr(e){let t=Wr(e).toString(16);return t.length&1?"0"+t:t}function sa(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Yr:BigInt("0x"+e)}function Pt(e){return sa($r(e))}function pe(e){return sa($r(Qr(St(e)).reverse()))}function Xr(e,t){if(Ft(t),t===0)throw new Error("zero output length is invalid");e=Wr(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Zr(n.padStart(r,"0"))}function zo(e,t){return Xr(e,t).reverse()}function Qr(e){return Uint8Array.from(H(e))}function te(e){return typeof e=="bigint"&&Yr<=e}function Ko(e,t,r){return te(e)&&te(t)&&te(r)&&t<=e&&e<r}function ke(e,t,r,n){if(!Ko(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ne(e){if(e<Yr)throw new Error("expected non-negative bigint, got "+e);return e===Yr?0:e.toString(2).length}var mr=e=>(re(e,"n"),(na<<BigInt(e))-na);function ia(e,t,r){if(Ft(e,"hashLen"),Ft(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),l=0,h=()=>{c.fill(1),u.fill(0),l=0},f=(...w)=>r(u,vt(c,...w)),p=(w=o)=>{u=f(s,w),c=f(),w.length!==0&&(u=f(i,w),c=f())},S=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,d=[];for(;w<t;){c=f();let m=c.slice();d.push(m),w+=c.length}return vt(...d)};return(w,d)=>{h(),p(w);let m;for(;(m=d(S()))===void 0;)p();return h(),m}}function gt(e,t={},r={},n="object"){Jt(e,n),Jt(t,"fields"),Jt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,l=e[i];if(!Object.hasOwn(e,i)&&(c?l!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&l===void 0)return;let h=typeof l;if(h!==a||l===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${h}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var rt=BigInt(0),V=BigInt(1),ne=BigInt(2),ua=BigInt(3),qo=BigInt(4),fa=BigInt(5),Pf=BigInt(7),la=BigInt(8),kf=BigInt(9),Nf=BigInt(15),da=BigInt(16),Ff=BigInt("0x10000000000000000");function W(e,t){if(t<=rt)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=rt?r:t+r}function ha(e,t,r){if(r<=V)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<rt)throw new Error("invalid exponent, negatives unsupported");if(t===rt)return V;if(t===V)return e;let n=e%r;if(n<rt&&(n+=r),t<Ff){let a=V;for(;t>rt;)t&V&&(a=a*n%r),n=n*n%r,t>>=V;return a}let o=[];for(;t>rt;)o.push(Number(t&Nf)),t>>=qo;let s=new Array(16);s[0]=V,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function G(e,t,r){if(r<=V)throw new Error("pow2: expected modulus > 1, got "+r);if(t<rt)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >rt;)n*=n,n%=r;return n}function aa(e,t){if(e===rt)throw new Error("invert: expected non-zero number");if(t<=V)throw new Error("invert: expected modulus > 1, got "+t);let r=W(e,t),n=t,o=rt,s=V;for(;r!==rt;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==V)throw new Error("invert: does not exist");return W(o,t)}function pa(e,t){if(t<=V)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=W(e,t);if(r===rt)throw new Error("invertCt: expected non-zero number");let n=ha(r,t-ne,t);if(W(r*n,t)!==V)throw new Error("invertCt: does not exist");return n}function Ho(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function Vo(e,t){if((e&V)===rt)throw new Error(t+": expected odd modulus, got "+e)}function ma(e,t){let r=e,n=(r.ORDER+V)/qo,o=r.pow(t,n);return Ho(r,o,t),o}function Uf(e,t){let r=e,n=(r.ORDER-fa)/la,o=r.mul(t,ne),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,ne),s),c=r.mul(i,r.sub(a,r.ONE));return Ho(r,c,t),c}function Mf(e){let t=Ue(e),r=ga(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Pf)/da;return((a,c)=>{let u=a,l=u.pow(c,i),h=u.mul(l,n),f=u.mul(l,o),p=u.mul(l,s),S=u.eql(u.sqr(h),c),E=u.eql(u.sqr(f),c);l=u.cmov(l,h,S),h=u.cmov(p,f,E);let w=u.eql(u.sqr(h),c),d=u.cmov(l,h,w);return Ho(u,d,c),d})}function ga(e){if(e<ua)throw new Error("sqrt is not defined for small field");Vo(e,"tonelliShanks");let t=e-V,r=0;for(;t%ne===rt;)t/=ne,r++;let n=ne,o=Ue(e);for(;gr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ma;let s=o.pow(n,t),i=(t+V)/ne;return function(c,u){let l=c;if(l.is0(u))return u;if(gr(l,u)!==1)throw new Error("Cannot find square root");let h=r,f=l.mul(l.ONE,s),p=l.pow(u,t),S=l.pow(u,i);for(;!l.eql(p,l.ONE);){if(l.is0(p))throw new Error("Cannot find square root: probably non-prime P");let E=1,w=l.sqr(p);for(;!l.eql(w,l.ONE);)if(E++,w=l.sqr(w),E===h)throw new Error("Cannot find square root");let d=V<<BigInt(h-E-1),m=l.pow(f,d);h=E,f=l.sqr(m),p=l.mul(p,f),S=l.mul(S,m)}return S}}function zf(e){return Vo(e,"Fp.sqrt"),e%qo===ua?ma:e%la===fa?Uf:e%da===kf?Mf(e):ga(e)}var ya=(e,t)=>(W(e,t)&V)===V,Kf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Fe(e){if(Jt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);re(e.BYTES,"BYTES"),re(e.BITS,"BITS");for(let t of Kf)de(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=V)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function tn(e,t,r=!1){Fe(e),Gr(t,"nums"),mt(r,"passZero");let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function gr(e,t){Fe(e);let r=e;Vo(r.ORDER,"FpLegendre");let n=(r.ORDER-V)/ne,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function qf(e,t){if(t!==void 0&&Mo(t),e<=rt)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Ne(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var ca=new WeakMap,Jr=class{ORDER;BITS;BYTES;isLE;ZERO=rt;ONE=V;_lengths;_mod;constructor(t,r={}){if(t<=V)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=qf(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return rt<=t&&t<this.ORDER}is0(t){return t===rt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return W(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return W(t*t,this.ORDER)}add(t,r){return W(t+r,this.ORDER)}sub(t,r){return W(t-r,this.ORDER)}mul(t,r){return W(t*r,this.ORDER)}pow(t,r){return ha(t,r,this.ORDER)}div(t,r){return W(t*aa(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return aa(t,this.ORDER)}sqrt(t){let r=ca.get(this);return r||ca.set(this,r=zf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?zo(t,this.BYTES):Xr(t,this.BYTES)}fromBytes(t,r=!1){H(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?pe(t):Pt(t);if(a&&(c=W(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return tn(this,t,!0)}cmov(t,r,n){return mt(n,"condition"),n?r:t}};function Ue(e,t={}){return Object.freeze(Jr.prototype),new Jr(e,t)}function ba(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=V)throw new Error("field order must be greater than 1");let t=Ne(e-V);return Math.ceil(t/8)}function en(e){let t=ba(e);return t+Math.ceil(t/2)}function rn(e,t,r=!1){H(e);let n=e.length,o=ba(t),s=Math.max(en(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?pe(e):Pt(e),a=W(i,t-V)+V;return r?zo(a,o):Xr(a,o)}var Zo=BigInt(0),yr=BigInt(1),Hf=BigInt(4),jo=16,wa=128,Vf=5,xa=2**31;function oe(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);de(t.fromAffine,"Point.fromAffine"),de(t.fromBytes,"Point.fromBytes"),de(t.fromHex,"Point.fromHex"),Jt(t.BASE,"Point.BASE"),Jt(t.ZERO,"Point.ZERO"),Fe(t.Fp),Fe(t.Fn)}function nn(e,t){oe(e),Sa(t,e);let r=tn(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function jf(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function $f(e,t){let r=e*(4*t+128);if(r>xa)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+xa/2**20+" MiB")}function Yo(e,t){if(e!==void 0){de(e,"randomBytes");try{let r=e(t);if(!ee(r)||r.length!==t)return}catch{return}return e}}function Sa(e,t){Gr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Zf(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,o)=>{if(!(r===void 0?t.isValid(n):te(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var va=new WeakMap;function $o(e){return va.get(e)||1}function Yf(e,t){let r=e.double(),n=[e];for(let o=1;o<t;o++)n.push(n[o-1].add(r));return n}function Gf(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>Zo;){let i=0;e&yr&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=yr}return s}function Wf(e,t,r){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&s);e>>=i,u>o&&(u-=n,e+=yr),a.push(u)}if(e!==Zo)throw new Error("invalid wnaf");return a}function Xf(e,t,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=e;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=t[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Me=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){oe(t),this.randomBytes=Yo(r,jo),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=t;for(let c=0;c<o;c++){let u=a;for(let l=0;l<s;l++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(t,r){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=Wf(r,n,o),c=this.ZERO,u=this.BASE;for(let l=0;l<o;l++){let h=a[l],f=l*i,p=Math.abs(h)-1,S=s[f];for(let w=1;w<i;w++)S=w===p?s[f+w]:S;let E=S.negate();h===0?u=u.add(s[f]):c=c.add(h<0?E:S)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===t&&a.bits===n);return i||(i=this.buildWnafTable(r,t,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!Ko(r,yr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=$o(t);return s===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+wa,s=this.randomBytes(jo);if(!ee(s)||s.length!==jo)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Pt(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,r,n){let o=Vf,s=1<<o,i=mr(o),a=new Array(s);a[0]=this.ZERO;for(let l=1;l<s;l++)a[l]=a[l-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let l=c-1;l>=0;l--){if(l!==c-1)for(let p=0;p<o;p++)u=u.double();let h=Number(r>>BigInt(l*o)&i),f=a[0];for(let p=1;p<s;p++)f=p===h?a[p]:f;u=u.add(f)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===yr?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,o):this.mulCT(t,r,o)}mulUnsafe(t,r,n){if(this.assertPoint(t),!te(r))throw new Error("invalid scalar");let o=$o(t);if(o===1||r>=this.Point.Fn.ORDER)return on(this.Point,[t],[r],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(t,r){this.assertPoint(t),jf(r,this.bits);let n=Math.ceil((this.bits+wa)/r)+1;$f(n*2**(r-1),this.Point.Fp.BYTES),va.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return $o(t)!==1}};function on(e,t,r,n=!1){if(oe(e),Sa(t,e),mt(n,"allowOversized"),Zf(r,e.Fn,n?e.Fn.ORDER**Hf:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>Yf(i,4)),s=r.map(i=>Gf(i,4));return Xf(e.ZERO,o,s)}function Ea(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Fe(t),t}else return Ue(e,{isLE:r})}function sn(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);gt(r);for(let c of["p","n","h"]){let u=t[c];if(!(te(u)&&u!==Zo))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ea(t.p,r.Fp,n),s=Ea(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function an(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var cn=BigInt(0),un=BigInt(1),fn=BigInt(2),Qf=BigInt(4),_a=BigInt(8);function Jf(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function Aa(e,t={}){gt(t,{},{},"extraOpts");let r=t,n=sn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(gr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(gr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");gt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?he:r.randomBytes,u=fn<<BigInt(o.BYTES*8)-un;function l(m){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(m)}let h=r.uvRatio===void 0?(m,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(m,g))}}catch{return{isValid:!1,value:cn}}}:r.uvRatio;if(!Jf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let f=o.eql(i.a,o.neg(o.ONE))?m=>o.neg(m):o.eql(i.a,o.ONE)?m=>m:m=>o.mul(i.a,m);function p(m,g,x=!1){let v=x?un:cn;return ke("coordinate "+m,g,v,u),g}function S(m){if(!(m instanceof E))throw new Error("EdwardsPoint expected")}class E{static BASE=new E(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new E(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(g,x,v,C){this.X=p("x",g),this.Y=p("y",x),this.Z=p("z",v,!0),this.T=p("t",C),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof E)throw new Error("extended point not allowed");let{x,y:v}=g||{};return p("x",x),p("y",v),new E(x,v,o.ONE,o.mul(x,v))}static fromBytes(g,x=!1){let v=o.BYTES,{a:C,d:M}=i;g=Qr(H(g,v,"point")),mt(x,"zip215");let N=Qr(g),P=g[v-1];N[v-1]=P&-129;let k=pe(N),z=x?u:o.ORDER;ke("point.y",k,cn,z);let R=o.sqr(k),Z=o.sub(R,o.ONE),D=o.sub(o.mulN(M,R),C),{isValid:L,value:y}=h(Z,D);if(!L)throw new Error("bad point: invalid y coordinate");let _=l(y),I=(P&128)!==0;if(!x&&o.is0(y)&&I)throw new Error("bad point: x=0 and x_0=1");return I!==_&&(y=o.neg(y)),E.fromAffine({x:y,y:k})}static fromHex(g,x=!1){return E.fromBytes(Pe(g),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,x=!0){return d.setWindowSize(this,g),x||this.multiply(fn),this}assertValidity(){let g=this,{a:x,d:v}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:C,Y:M,Z:N,T:P}=g,k=o.sqr(C),z=o.sqr(M),R=o.sqr(N),Z=o.sqr(R),D=o.mul(k,x),L=o.mul(o.add(D,z),R),y=o.add(Z,o.mul(v,o.mul(k,z)));if(!o.eql(L,y))throw new Error("bad point: equation left != right (1)");let _=o.mul(C,M),I=o.mul(N,P);if(!o.eql(_,I))throw new Error("bad point: equation left != right (2)")}equals(g){S(g);let{X:x,Y:v,Z:C}=this,{X:M,Y:N,Z:P}=g,k=o.mul(x,P),z=o.mul(M,C),R=o.mul(v,P),Z=o.mul(N,C);return o.eql(k,z)&&o.eql(R,Z)}is0(){return this.equals(E.ZERO)}negate(){return new E(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:x,Z:v}=this,C=o.sqr(g),M=o.sqr(x),N=o.mul(o.sqr(v),fn),P=f(C),k=o.addN(g,x),z=o.sub(o.subN(o.sqr(k),C),M),R=o.addN(P,M),Z=o.subN(R,N),D=o.subN(P,M),L=o.mul(z,Z),y=o.mul(R,D),_=o.mul(z,D),I=o.mul(Z,R);return new E(L,y,I,_)}add(g){S(g);let{d:x}=i,{X:v,Y:C,Z:M,T:N}=this,{X:P,Y:k,Z:z,T:R}=g,Z=o.mul(v,P),D=o.mul(C,k),L=o.mul(o.mulN(N,x),R),y=o.mul(M,z),_=o.sub(o.subN(o.mulN(o.addN(v,C),o.addN(P,k)),Z),D),I=o.subN(y,L),O=o.addN(y,L),A=o.sub(D,f(Z)),b=o.mul(_,I),B=o.mul(O,A),T=o.mul(_,A),F=o.mul(I,O);return new E(b,B,F,T)}subtract(g){return S(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:v}=d.mulSecret(this,g,a,w);return w([x,v])[0]}multiplyUnsafe(g){if(!s.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===cn?E.ZERO:this.is0()||g===un?this:d.mulUnsafe(this,g,w)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return d.mulUnsafe(this,i.n).is0()}toAffine(g){let x=this,v=g;if(v!=null&&typeof v!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof v);let{X:C,Y:M,Z:N}=x,P=x.is0();v==null&&(v=P?o.create(_a):o.inv(N));let k=o.mul(C,v),z=o.mul(M,v),R=o.mul(N,v);if(P)return{x:o.ZERO,y:o.ONE};if(!o.eql(R,o.ONE))throw new Error("invZ was invalid");return{x:k,y:z}}clearCofactor(){return a===un?this:a===fn?this.double():a===Qf?this.double().double():a===_a?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:x}=this.toAffine(),v=o.toBytes(x);return v[v.length-1]|=l(g)?128:0,v}toHex(){return hr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let w=m=>nn(E,m),d=new Me(E,c);return d.bits>=6&&E.BASE.precompute(6),Object.freeze(E.prototype),Object.freeze(E),E}function Ia(e,t,r={}){if(oe(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;gt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,l=2*a.BYTES;if(u!==void 0&&(re(u,"hash.outputLen"),u!==l))throw new Error(`hash.outputLen must be ${l}, got ${u}`);let h=o.randomBytes===void 0?he:o.randomBytes,f=o.toMontgomery,p=o.toMontgomerySecret,S=o.adjustScalarBytes===void 0?D=>D:o.adjustScalarBytes,E=o.domain===void 0?(D,L,y)=>{if(mt(y,"phflag"),L.length||y)throw new Error("Contexts/pre-hash are not supported");return D}:o.domain;function w(D){return c.create(pe(D))}function d(D){let L=P.secretKey;H(D,P.secretKey,"secretKey");let y=H(n(D),2*L,"hashedSecretKey"),_=S(y.slice(0,L)),I=y.slice(L,2*L),O=w(_);return{head:_,prefix:I,scalar:O}}function m(D){let{head:L,prefix:y,scalar:_}=d(D),I=i.multiply(_),O=I.toBytes();return{head:L,prefix:y,scalar:_,point:I,pointBytes:O}}function g(D){return m(D).pointBytes}function x(D=Uint8Array.of(),...L){let y=vt(...L);return w(n(E(y,H(D,void 0,"context"),!!s)))}function v(D,L,y={}){gt(y,{},{},"options"),D=H(D,void 0,"message"),s&&(D=s(D));let{prefix:_,scalar:I,pointBytes:O}=m(L),A=x(y.context,_,D),b=i.multiply(A).toBytes(),B=x(y.context,b,O,D),T=c.create(A+B*I);if(!c.isValid(T))throw new Error("sign failed: invalid s");let F=vt(b,c.toBytes(T));return H(F,P.signature,"result")}let C={zip215:o.zip215};function M(D,L,y,_=C){gt(_);let{context:I}=_,O=_.zip215===void 0?!!C.zip215:_.zip215,A=P.signature;D=H(D,A,"signature"),L=H(L,void 0,"message"),y=H(y,P.publicKey,"publicKey"),O!==void 0&&mt(O,"zip215"),s&&(L=s(L));let b=A/2,B=D.subarray(0,b),T=pe(D.subarray(b,A)),F,U,q;try{F=e.fromBytes(y,O),U=e.fromBytes(B,O),q=i.multiplyUnsafe(T)}catch{return!1}if(!O&&F.isSmallOrder())return!1;let K=x(I,B,y,L);return U.add(F.multiplyUnsafe(K)).subtract(q).clearCofactor().is0()}let N=a.BYTES,P={secretKey:N,publicKey:N,signature:2*N,seed:N};function k(D){return D=D===void 0?h(P.seed):D,H(D,P.seed,"seed")}function z(D){return ee(D)&&D.length===P.secretKey}function R(D,L){try{return!!e.fromBytes(D,L===void 0?C.zip215:L)}catch{return!1}}let Z={getExtendedPublicKey:m,randomSecretKey:k,isValidSecretKey:z,isValidPublicKey:R,toMontgomery(D){if(f===void 0)throw new Error("Montgomery conversion is not supported for this curve");return f(e.fromBytes(D))},toMontgomerySecret(D){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(D)}};return Object.freeze(P),Object.freeze(Z),Object.freeze({keygen:an(k,g),getPublicKey:g,sign:v,verify:M,utils:Z,Point:e,lengths:P})}var Go=BigInt(1),Ba=BigInt(2);var tl=BigInt(5),el=BigInt(8),Wo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),rl={p:Wo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:el,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function nl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Wo,a=e*e%s*e%s,c=G(a,Ba,s)*a%s,u=G(c,Go,s)*e%s,l=G(u,tl,s)*u%s,h=G(l,t,s)*l%s,f=G(h,r,s)*h%s,p=G(f,n,s)*f%s,S=G(p,o,s)*p%s,E=G(S,o,s)*p%s,w=G(E,t,s)*l%s;return{pow_p_5_8:G(w,Ba,s)*e%s,b2:a}}function Da(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ta=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ol(e,t){let r=Wo,n=W(t*t*t,r),o=W(n*n*t,r),s=nl(e*o).pow_p_5_8,i=W(e*n*s,r),a=W(t*i*i,r),c=i,u=W(i*Ta,r),l=a===e,h=a===W(-e,r),f=a===W(-e*Ta,r);return l&&(i=c),(h||f)&&(i=u),ya(i,r)&&(i=W(-i,r)),{isValid:l||h,value:i}}var Xo=Aa(rl,{uvRatio:ol}),La=Xo.Fp;function sl(e){let{y:t}=e;return La.toBytes(La.div(Go+t,Go-t))}function il(e){let t=Xo.Fp.BYTES;return St(e,t),Da(Uo(e.subarray(0,t))).subarray(0,t)}function al(e){return Ia(Xo,Uo,Object.assign({adjustScalarBytes:Da,toMontgomery:sl,toMontgomerySecret:il,zip215:!0},e))}var Ca=al({});var br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},ln=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var dn={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new ln("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var hn=32;var Qo,cl=(async()=>{try{return await dn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ul(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await dn.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await dn.get().subtle.verify({name:"Ed25519"},n,At(t),At(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function fl(e,t,r){return Ca.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ra(e,t,r){return Qo==null&&(Qo=await cl),Qo?ul(e,t,r):fl(e,t,r)}function pn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var mn=class{type="Ed25519";raw;constructor(t){this.raw=Jo(t,hn)}toMultihash(){return _t.digest(Re(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ra(this.raw,r,t);return pn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Pa(e){return e=Jo(e,hn),new mn(e)}function Jo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ht(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var dl=Math.pow(2,7),hl=Math.pow(2,14),pl=Math.pow(2,21),ts=Math.pow(2,28),es=Math.pow(2,35),rs=Math.pow(2,42),ns=Math.pow(2,49),j=128,ft=127;function yt(e){if(e<dl)return 1;if(e<hl)return 2;if(e<pl)return 3;if(e<ts)return 4;if(e<es)return 5;if(e<rs)return 6;if(e<ns)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ze(e,t,r=0){switch(yt(e)){case 8:t[r++]=e&255|j,e/=128;case 7:t[r++]=e&255|j,e/=128;case 6:t[r++]=e&255|j,e/=128;case 5:t[r++]=e&255|j,e/=128;case 4:t[r++]=e&255|j,e>>>=7;case 3:t[r++]=e&255|j,e>>>=7;case 2:t[r++]=e&255|j,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ml(e,t,r=0){switch(yt(e)){case 8:t.set(r++,e&255|j),e/=128;case 7:t.set(r++,e&255|j),e/=128;case 6:t.set(r++,e&255|j),e/=128;case 5:t.set(r++,e&255|j),e/=128;case 4:t.set(r++,e&255|j),e>>>=7;case 3:t.set(r++,e&255|j),e>>>=7;case 2:t.set(r++,e&255|j),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function os(e,t){let r=e[t],n=0;if(n+=r&ft,r<j||(r=e[t+1],n+=(r&ft)<<7,r<j)||(r=e[t+2],n+=(r&ft)<<14,r<j)||(r=e[t+3],n+=(r&ft)<<21,r<j)||(r=e[t+4],n+=(r&ft)*ts,r<j)||(r=e[t+5],n+=(r&ft)*es,r<j)||(r=e[t+6],n+=(r&ft)*rs,r<j)||(r=e[t+7],n+=(r&ft)*ns,r<j))return n;throw new RangeError("Could not decode varint")}function gl(e,t){let r=e.get(t),n=0;if(n+=r&ft,r<j||(r=e.get(t+1),n+=(r&ft)<<7,r<j)||(r=e.get(t+2),n+=(r&ft)<<14,r<j)||(r=e.get(t+3),n+=(r&ft)<<21,r<j)||(r=e.get(t+4),n+=(r&ft)*ts,r<j)||(r=e.get(t+5),n+=(r&ft)*es,r<j)||(r=e.get(t+6),n+=(r&ft)*rs,r<j)||(r=e.get(t+7),n+=(r&ft)*ns,r<j))return n;throw new RangeError("Could not decode varint")}function ka(e,t,r=0){return t==null&&(t=ut(yt(e))),t instanceof Uint8Array?ze(e,t,r):ml(e,t,r)}function wr(e,t=0){return e instanceof Uint8Array?os(e,t):gl(e,t)}var ss=new Float32Array([-0]),se=new Uint8Array(ss.buffer);function Fa(e,t,r){ss[0]=e,t[r]=se[0],t[r+1]=se[1],t[r+2]=se[2],t[r+3]=se[3]}function Ua(e,t){return se[0]=e[t],se[1]=e[t+1],se[2]=e[t+2],se[3]=e[t+3],ss[0]}var is=new Float64Array([-0]),lt=new Uint8Array(is.buffer);function Ma(e,t,r){is[0]=e,t[r]=lt[0],t[r+1]=lt[1],t[r+2]=lt[2],t[r+3]=lt[3],t[r+4]=lt[4],t[r+5]=lt[5],t[r+6]=lt[6],t[r+7]=lt[7]}function za(e,t){return lt[0]=e[t],lt[1]=e[t+1],lt[2]=e[t+2],lt[3]=e[t+3],lt[4]=e[t+4],lt[5]=e[t+5],lt[6]=e[t+6],lt[7]=e[t+7],is[0]}var yl=BigInt(Number.MAX_SAFE_INTEGER),bl=BigInt(Number.MIN_SAFE_INTEGER),wt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return me;if(t<yl&&t>bl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Ka&&(o=0n,++n>Ka&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return me;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):me}},me=new wt(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var Ka=4294967296n;function qa(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ha(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function as(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Bt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function gn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var cs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=At(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Bt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Bt(this,4);return gn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return gn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=Ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=za(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ha(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new wt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=gn(this.buf,this.pos+=4),r=gn(this.buf,this.pos+=4);return new wt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=os(this.buf,this.pos);return this.pos+=yt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function xr(e){return new cs(e instanceof Uint8Array?e:e.subarray())}function Ut(e,t,r){let n=xr(e);return t.decode(n,void 0,r)}function us(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ut(i);o+i>t&&(n=ut(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ge=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function fs(){}var ds=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},wl=us();function xl(e){return globalThis.Buffer!=null?ut(e):wl(e)}var Sr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ge(fs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ge(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new hs((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(yn,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=wt.fromBigInt(t);return this._push(yn,r.length(),r)}uint64Number(t){return this._push(ze,yt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=wt.fromBigInt(t).zzEncode();return this._push(yn,r.length(),r)}sint64Number(t){let r=wt.fromNumber(t).zzEncode();return this._push(yn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ls,1,t?1:0)}fixed32(t){return this._push(Er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=wt.fromBigInt(t);return this._push(Er,4,r.lo)._push(Er,4,r.hi)}fixed64Number(t){let r=wt.fromNumber(t);return this._push(Er,4,r.lo)._push(Er,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Fa,4,t)}double(t){return this._push(Ma,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ls,1,0):this.uint32(r)._push(Sl,r,t)}string(t){let r=qa(t);return r!==0?this.uint32(r)._push(as,r,t):this._push(ls,1,0)}fork(){return this.states=new ds(this),this.head=this.tail=new ge(fs,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 ge(fs,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=xl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ls(e,t,r){t[r]=e&255}function El(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var hs=class extends ge{next;constructor(t,r){super(El,t,r),this.next=void 0}};function yn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Er(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Sl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Sr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(vl,t,e),this},Sr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(_l,t,e),this});function vl(e,t,r){t.set(e,r)}function _l(e,t,r){e.length<40?as(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Y(e),r)}function ps(){return new Sr}function Mt(e,t){let r=ps();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*zt(e,t,r){let n=xr(e);yield*t.stream(n,void 0,"$",r)}var bn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function wn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Ke(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return wn("enum",bn.VARINT,r,n,o)}function Kt(e,t,r){return wn("message",bn.LENGTH_DELIMITED,e,t,r)}var vr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var pt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(pt||(pt={}));var ms;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(ms||(ms={}));(function(e){e.codec=()=>Ke(ms)})(pt||(pt={}));var _r;(function(e){let t;e.codec=()=>(t==null&&(t=Kt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return Mt(s,e.codec())}e.encode=r;function n(s,i){return Ut(s,e.codec(),i)}e.decode=n;function o(s,i){return zt(s,e.codec(),i)}e.stream=o})(_r||(_r={}));var gs;(function(e){let t;e.codec=()=>(t==null&&(t=Kt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return Mt(s,e.codec())}e.encode=r;function n(s,i){return Ut(s,e.codec(),i)}e.decode=n;function o(s,i){return zt(s,e.codec(),i)}e.stream=o})(gs||(gs={}));var xn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Hr(t),St(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),le(o)}update(t){return Oe(this),this.iHash.update(t),this}digestInto(t){Oe(this),Vr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.canXOF=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ja=(()=>{let e=((t,r,n)=>new xn(t,r).update(n).digest());return e.create=(t,r)=>new xn(t,r),e})();var Il=BigInt(0),ys=class extends Error{constructor(t=""){super(t)}},qt={Err:ys,_tlv:{encode:(e,t)=>{let{Err:r}=qt;if(re(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(oa(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=pr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?pr(o.length/2|128):"";return pr(e)+s+o+t},decode(e,t){let{Err:r}=qt;t=H(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=qt;if(Wr(e),e<Il)throw new t("integer: negative integers are not allowed");let r=pr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=qt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Pt(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=qt,o=H(e,void 0,"signature"),{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:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=qt;gt(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},bs=(Object.freeze(qt._tlv),Object.freeze(qt._int),Object.freeze(qt));var $a=(e,t)=>(e+(e>=0?t:-t)/Za)/t;function Bl(e,t,r){ke("scalar",e,Ht,r);let[[n,o],[s,i]]=t,a=$a(i*e,r),c=$a(-o*e,r),u=e-a*n-c*s,l=-a*o-c*i,h=u<Ht,f=l<Ht;h&&(u=-u),f&&(l=-l);let p=mr(Math.ceil(Ne(r)/2))+ye;if(u<Ht||u>=p||l<Ht||l>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:u,k2neg:f,k2:l}}function Es(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ws(e,t){gt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return mt(r.lowS,"lowS"),mt(r.prehash,"prehash"),r.format!==void 0&&Es(r.format),r}var Ht=BigInt(0),ye=BigInt(1),Za=BigInt(2),xs=BigInt(3),Tl=BigInt(4);function Ya(e,t={}){let r=sn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;gt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u}=t,l=t.randomBytes===void 0?he:t.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let h=Wa(n,o);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(L,y,_){if(u&&y.is0())return Uint8Array.of(0);let{x:I,y:O}=y.toAffine(),A=n.toBytes(I);if(mt(_,"isCompressed"),_){f();let b=!n.isOdd(O);return vt(Ga(b),A)}else return vt(Uint8Array.of(4),A,n.toBytes(O))}function S(L){H(L,void 0,"Point");let{publicKey:y,publicKeyUncompressed:_}=h,I=L.length,O=L[0],A=L.subarray(1);if(u&&I===1&&O===0)return{x:n.ZERO,y:n.ZERO};if(I===y&&(O===2||O===3)){let b=n.fromBytes(A);if(!n.isValid(b))throw new Error("bad point: is not on curve, wrong x");let B=g(b),T;try{T=n.sqrt(B)}catch(q){let K=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+K)}f();let F=n.isOdd(T);return(O&1)===1!==F&&(T=n.neg(T)),{x:b,y:T}}else if(I===_&&O===4){let b=n.BYTES,B=n.fromBytes(A.subarray(0,b)),T=n.fromBytes(A.subarray(b,b*2));if(!x(B,T))throw new Error("bad point: is not on curve");return{x:B,y:T}}else throw new Error(`bad point: got length ${I}, expected compressed=${y} or uncompressed=${_}`)}let E=t.toBytes===void 0?p:t.toBytes,w=t.fromBytes===void 0?S:t.fromBytes,d=n.mul(s.b,xs),m=n.is0(s.a)?L=>n.ZERO:L=>n.mul(s.a,L);function g(L){let y=n.sqr(L),_=n.mul(y,L);return n.add(n.add(_,n.mul(L,s.a)),s.b)}function x(L,y){let _=n.sqr(y),I=g(L);return n.eql(_,I)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,xs),Tl),C=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,C)))throw new Error("bad curve params: a or b");function M(L,y,_=!1){if(!n.isValid(y)||_&&n.is0(y))throw new Error(`bad point coordinate ${L}`);return y}function N(L){if(!(L instanceof R))throw new Error("Weierstrass Point expected")}function P(L){if(!c||!c.basises)throw new Error("no endo");return Bl(L,c.basises,o.ORDER)}function k(L,y,_,I){if(!o.isValid(I))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:O,k1:A,k2neg:b,k2:B}=P(I),T=new R(n.mul(_.X,c.beta),_.Y,_.Z);L.push(O?_.negate():_,b?T.negate():T),y.push(A,B)}else L.push(_),y.push(I)}let z=new WeakSet;class R{static BASE=new R(s.Gx,s.Gy,n.ONE);static ZERO=new R(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,_,I){this.X=M("x",y),this.Y=M("y",_,!0),this.Z=M("z",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:_,y:I}=y||{};if(!y||!n.isValid(_)||!n.isValid(I))throw new Error("invalid affine point");if(y instanceof R)throw new Error("projective point not allowed");return n.is0(_)&&n.is0(I)?R.ZERO:new R(_,I,n.ONE)}static fromBytes(y){let _=R.fromAffine(w(H(y,void 0,"point")));return _.assertValidity(),_}static fromHex(y){return R.fromBytes(Pe(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,_=!0){return D.setWindowSize(this,y),_||this.multiply(xs),this}assertValidity(){let y=this;if(y.is0()){if(t.allowInfinityPoint&&n.is0(y.X)&&n.eql(y.Y,n.ONE)&&n.is0(y.Z))return;throw new Error("bad point: ZERO")}if(z.has(y))return;let{x:_,y:I}=y.toAffine();if(!n.isValid(_)||!n.isValid(I))throw new Error("bad point: x or y not field elements");if(!x(_,I))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");z.add(y)}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){N(y);let{X:_,Y:I,Z:O}=this,{X:A,Y:b,Z:B}=y,T=n.eql(n.mul(_,B),n.mul(A,O)),F=n.eql(n.mul(I,B),n.mul(b,O));return T&&F}negate(){return new R(this.X,n.neg(this.Y),this.Z)}double(){let{X:y,Y:_,Z:I}=this,O=n.ZERO,A=n.ZERO,b=n.ZERO,B=n.mul(y,y),T=n.mul(_,_),F=n.mul(I,I),U=n.mul(y,_);return U=n.add(U,U),b=n.mul(y,I),b=n.add(b,b),O=m(b),A=n.mul(d,F),A=n.add(O,A),O=n.sub(T,A),A=n.add(T,A),A=n.mul(O,A),O=n.mul(U,O),b=n.mul(d,b),F=m(F),U=n.sub(B,F),U=m(U),U=n.add(U,b),b=n.add(B,B),B=n.add(b,B),B=n.add(B,F),B=n.mul(B,U),A=n.add(A,B),F=n.mul(_,I),F=n.add(F,F),B=n.mul(F,U),O=n.sub(O,B),b=n.mul(F,T),b=n.add(b,b),b=n.add(b,b),new R(O,A,b)}add(y){N(y);let{X:_,Y:I,Z:O}=this,{X:A,Y:b,Z:B}=y,T=n.ZERO,F=n.ZERO,U=n.ZERO,q=n.mul(_,A),K=n.mul(I,b),X=n.mul(O,B),dt=n.add(_,I),Q=n.add(A,b);dt=n.mul(dt,Q),Q=n.add(q,K),dt=n.sub(dt,Q),Q=n.add(_,O);let it=n.add(A,B);return Q=n.mul(Q,it),it=n.add(q,X),Q=n.sub(Q,it),it=n.add(I,O),T=n.add(b,B),it=n.mul(it,T),T=n.add(K,X),it=n.sub(it,T),U=m(Q),T=n.mul(d,X),U=n.add(T,U),T=n.sub(K,U),U=n.add(K,U),F=n.mul(T,U),K=n.add(q,q),K=n.add(K,q),X=m(X),Q=n.mul(d,Q),K=n.add(K,X),X=n.sub(q,X),X=m(X),Q=n.add(Q,X),q=n.mul(K,Q),F=n.add(F,q),q=n.mul(it,Q),T=n.mul(dt,T),T=n.sub(T,q),q=n.mul(dt,K),U=n.mul(it,U),U=n.add(U,q),new R(T,F,U)}subtract(y){return N(y),this.add(y.negate())}is0(){return this.equals(R.ZERO)}multiply(y){if(!o.isValidNot0(y))throw new RangeError("invalid scalar: out of range");let{p:_,f:I}=D.mulSecret(this,y,i,Z);return Z([_,I])[0]}multiplyUnsafe(y){let _=this,I=y;if(!o.isValid(I))throw new RangeError("invalid scalar: out of range");if(I===Ht||_.is0())return R.ZERO;if(I===ye)return _;if(D.hasWindowSize(this))return D.mulUnsafe(_,I,Z);let O=[],A=[];return k(O,A,_,I),on(R,O,A)}mulAddUnsafe(y,_,I){N(_);let O=[],A=[];return k(O,A,this,y),k(O,A,_,I),on(R,O,A)}toAffine(y){let _=this,I=y;if(I!=null&&!n.isValid(I))throw new RangeError('"invertedZ" expected valid field element');let{X:O,Y:A,Z:b}=_;if(n.eql(b,n.ONE))return{x:O,y:A};let B=_.is0();I==null&&(I=B?n.ONE:n.inv(b));let T=n.mul(O,I),F=n.mul(A,I),U=n.mul(b,I);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(U,n.ONE))throw new Error("invZ was invalid");return{x:T,y:F}}isTorsionFree(){let{isTorsionFree:y}=t;return i===ye?!0:y?y(R,this):D.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=t;return i===ye?this:y?y(R,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ye?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return mt(y,"isCompressed"),this.assertValidity(),E(R,this,y)}toHex(y=!0){return hr(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Z=L=>nn(R,L),D=new Me(R,l);return D.bits>=6&&R.BASE.precompute(6),Object.freeze(R.prototype),Object.freeze(R),R}function Ga(e){return Uint8Array.of(e?2:3)}function Wa(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ll(e,t={}){oe(e);let{Fn:r}=e,n=t.randomBytes===void 0?he:t.randomBytes,o=Object.assign(Wa(e.Fp,r),{seed:Math.max(en(r.ORDER),16)});function s(p){try{let S=r.fromBytes(p);return r.isValidNot0(S)}catch{return!1}}function i(p,S){let{publicKey:E,publicKeyUncompressed:w}=o;try{let d=p.length;return S===!0&&d!==E||S===!1&&d!==w?!1:!!e.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,rn(H(p,o.seed,"seed"),r.ORDER)}function c(p,S=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(S)}function u(p){let{secretKey:S,publicKey:E,publicKeyUncompressed:w}=o,d=r._lengths;if(!ee(p))return;let m=H(p,void 0,"key").length,g=m===E||m===w,x=m===S||!!d?.includes(m);if(!(g&&x))return g}function l(p,S,E=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(S)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(p);return e.fromBytes(S).multiply(w).toBytes(E)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},f=an(a,c);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:f,Point:e,utils:h,lengths:o})}function Xa(e,t,r={}){oe(e);let n=t;Hr(n),gt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?he:o.randomBytes,i=o.hmac===void 0?(A,b)=>ja(n,A,b):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:l}=c,h=en(u),f=Yo(s,h),{keygen:p,getPublicKey:S,getSharedSecret:E,utils:w,lengths:d}=Ll(e,o),m={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*Za+ye<a.ORDER;function x(A){let b=u>>ye;return A>b}function v(A,b){if(!c.isValidNot0(b))throw new Error(`invalid signature ${A}: out of range 1..Point.Fn.ORDER`);return b}function C(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(A,b,B){return C(),(A===B?0:2)|Number(a.isOdd(b))}function N(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function P(A,b){Es(b);let B=d.signature,T=b==="compact"?B:b==="recovered"?B+1:void 0;return H(A,T)}class k{r;s;recovery;constructor(b,B,T){if(this.r=v("r",b),this.s=v("s",B),T!=null){if(N(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(b,B=m.format){P(b,B);let T;if(B==="der"){let{r:K,s:X}=bs.toSig(H(b));return new k(K,X)}B==="recovered"&&(T=b[0],B="compact",b=b.subarray(1));let F=d.signature/2,U=b.subarray(0,F),q=b.subarray(F,F*2);return new k(c.fromBytes(U),c.fromBytes(q),T)}static fromHex(b,B){return this.fromBytes(Pe(b),B)}assertRecovery(){let{recovery:b}=this;if(b==null)throw new Error("invalid recovery id: must be present");return b}addRecoveryBit(b){return new k(this.r,this.s,b)}recoverPublicKey(b){let{r:B,s:T}=this,F=this.assertRecovery(),U=F===2||F===3?B+u:B;if(!a.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let q=a.toBytes(U),K=e.fromBytes(vt(Ga((F&1)===0),q)),X=c.inv(U),dt=R(H(b,void 0,"msgHash")),Q=c.create(-dt*X),it=c.create(T*X),Dt=e.BASE.mulAddUnsafe(Q,K,it);if(Dt.is0())throw new Error("invalid recovery: point at infinify");return Dt.assertValidity(),Dt}hasHighS(){return x(this.s)}toBytes(b=m.format){if(Es(b),b==="der")return Pe(bs.hexFromSig(this));let{r:B,s:T}=this,F=c.toBytes(B),U=c.toBytes(T);return b==="recovered"?(N(),vt(Uint8Array.of(this.assertRecovery()),F,U)):vt(F,U)}toHex(b){return hr(this.toBytes(b))}}Object.freeze(k.prototype),Object.freeze(k);let z=o.bits2int===void 0?function(b){if(b.length>8192)throw new Error("input is too large");let B=Pt(b),T=b.length*8-l;return T>0?B>>BigInt(T):B}:o.bits2int,R=o.bits2int_modN===void 0?function(b){return c.create(z(b))}:o.bits2int_modN,Z=mr(l);function D(A){return ke("num < 2^"+l,A,Ht,Z),c.toBytes(A)}function L(A,b){return H(A,void 0,"message"),b?H(n(A),void 0,"prehashed message"):A}function y(A,b,B){let{lowS:T,prehash:F,extraEntropy:U}=ws(B,m);A=L(A,F);let q=R(A),K=c.fromBytes(b);if(!c.isValidNot0(K))throw new Error("invalid private key");let X=[D(K),D(q)];if(U!=null&&U!==!1){let Dt=U===!0?s(d.secretKey):U;X.push(H(Dt,void 0,"extraEntropy"))}let dt=vt(...X),Q=q;function it(Dt){let Ae=z(Dt);if(!c.isValidNot0(Ae))return;let Je=e.BASE.multiply(Ae).toAffine(),$t=c.create(Je.x);if($t===Ht)return;let Ct;if(f!==void 0){let tr=Pt(rn(f(h),u)),Kc=c.inv(c.mul(tr,Ae)),qc=c.mul(tr,Q),Hc=c.mul(tr,K);Ct=c.create(Kc*c.create(qc+Hc*$t))}else{let tr=pa(Ae,u);Ct=c.create(tr*c.create(Q+$t*K))}if(Ct===Ht)return;let Gn=M(Je.x,Je.y,$t),ni=Ct;return T&&x(Ct)&&(ni=c.neg(Ct),Gn^=1),new k($t,ni,g?void 0:Gn)}return{seed:dt,k2sig:it}}function _(A,b,B={}){let{seed:T,k2sig:F}=y(A,b,B);return ia(n.outputLen,c.BYTES,i)(T,F).toBytes(B.format)}function I(A,b,B,T={}){let{lowS:F,prehash:U,format:q}=ws(T,m);if(B=H(B,void 0,"publicKey"),b=L(b,U),!ee(A)){let K=A instanceof k?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}P(A,q);try{let K=k.fromBytes(A,q),X=e.fromBytes(B);if(F&&K.hasHighS())return!1;let{r:dt,s:Q}=K,it=R(b),Dt=c.inv(Q),Ae=c.create(it*Dt),Je=c.create(dt*Dt),$t=e.BASE.mulAddUnsafe(Ae,X,Je);if($t.is0())return!1;let Ct=$t.toAffine();return!(c.create(Ct.x)!==dt||q==="recovered"&&K.recovery!==M(Ct.x,Ct.y,dt))}catch{return!1}}function O(A,b,B={}){let{prehash:T}=ws(B,m);return b=L(b,T),k.fromBytes(A,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:p,getPublicKey:S,getSharedSecret:E,utils:w,lengths:d,Point:e,sign:_,verify:I,recoverPublicKey:O,Signature:k,hash:n})}var vs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Dl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Qa=BigInt(2);function Cl(e){let t=vs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,h=G(l,r,t)*l%t,f=G(h,r,t)*l%t,p=G(f,Qa,t)*u%t,S=G(p,o,t)*p%t,E=G(S,s,t)*S%t,w=G(E,a,t)*E%t,d=G(w,c,t)*w%t,m=G(d,a,t)*E%t,g=G(m,r,t)*l%t,x=G(g,i,t)*S%t,v=G(x,n,t)*u%t,C=G(v,Qa,t);if(!Ss.eql(Ss.sqr(C),e))throw new Error("Cannot find square root");return C}var Ss=Ue(vs.p,{sqrt:Cl}),Rl=Ya(vs,{Fp:Ss,endo:Dl}),qe=Xa(Rl,ra);function Ja(e,t,r,n){let o=ir.digest(r instanceof Uint8Array?r:r.subarray());if(pn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),qe.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new br(String(s))});try{return n?.signal?.throwIfAborted(),qe.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new br(String(s))}}var En=class{type="secp256k1";raw;_key;constructor(t){this._key=ec(t),this.raw=tc(this._key)}toMultihash(){return _t.digest(Re(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return Ja(this._key,r,t,n)}};function rc(e){return new En(e)}function tc(e){return qe.Point.fromBytes(e).toBytes()}function ec(e){try{return qe.Point.fromBytes(e),e}catch(t){throw new Pr(String(t))}}function nc(e){let{Type:t,Data:r}=_r.decode(e.digest),n=r??new Uint8Array;switch(t){case pt.Ed25519:return Pa(n);case pt.secp256k1:return rc(n);case pt.ECDSA:return ki(n);default:throw new er}}function Re(e){return _r.encode({Type:pt[e.type],Data:e.raw})}var oc=Symbol.for("nodejs.util.inspect.custom"),Ol=114,Ar=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()})`}[Xn]=!0;toString(){return this.string==null&&(this.string=tt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Ol,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ct(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ct(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[oc](){return`PeerId(${this.toString()})`}},Sn=class extends Ar{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},vn=class extends Ar{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},_n=class extends Ar{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Pl=2336,An=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(Y(this.url))}[oc](){return`PeerId(${this.url})`}[Xn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Pl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};function In(e){if(Nl(e))return new Sn({multihash:e});if(kl(e))try{let t=nc(e);if(t.type==="Ed25519")return new vn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new _n({multihash:e,publicKey:t})}catch{let r=et(e.digest);return new An(new URL(r))}throw new kr("Supplied PeerID Multihash is invalid")}function kl(e){return e.code===_t.code}function Nl(e){return e.code===ir.code}function _s(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function Bn(e){let t=ce(tt.decode(`z${e}`));return In(t)}var Tn=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return _s(this.set.entries(),t=>{let r=Bn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=Bn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return _s(this.set.values(),t=>Bn(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function As(){return new Tn}var Is={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},sc={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},ic=new globalThis.TextEncoder;function Fl(e,t){let r=Is[t],n=sc[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function Ul(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Is[t],o=sc[t],s=e;for(;s.length>0;){let i=ic.encodeInto(s,r);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(t,o*n)}return o}function Bs(e,{size:t=32,utf8Buffer:r}={}){if(!Is[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof e=="string"){if(r)return Ul(e,t,r);e=ic.encode(e)}return Fl(e,t)}var Ir={hash:e=>Number(Bs(e,{size:32})),hashV:(e,t)=>Ml(Ir.hash(e,t))};function Ml(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),Y(t,"base16")}var Ts=64,Tt=class{fp;h;seed;constructor(t,r,n,o=2){if(o>Ts)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=Et(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ct(this.fp,t.fp):!1}};function be(e,t){return Math.floor(Math.random()*(t-e))+e}var we=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=t,!0;return!0}swap(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let r=be(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=t,n}remove(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var zl=500,Br=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??Ir,this.seed=t.seed??be(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=Y(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new we(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new we(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[be(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new we(this.bucketSize));for(let a=0;a<zl;a++){let c=this.buckets[i].swap(r);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new we(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=Y(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(t){typeof t=="string"&&(t=Y(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Kl={1:.5,2:.84,4:.95,8:.98};function ql(e=.001){return e>.002?2:e>1e-5?4:8}function ac(e,t=.001){let r=ql(t),n=Kl[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),Ts);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var Ln=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??Ir,this.seed=t.seed??be(0,Math.pow(2,10)),this.filterSeries=[new Br({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=Y(t)),this.has(t))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new Br({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(t)}has(t){typeof t=="string"&&(t=Y(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=Y(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,r)=>t+r.count,0)}};function Ls(e,t=.001,r){return new Ln({...ac(e,t),...r??{}})}function Hl(e){let t=e.getComponents(),r={},n=0;return t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r)}function Lt(e){let t=Hl(e);if(t==null)throw new ht(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var Dn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let f=Number.parseInt(h,t);if(!Number.isNaN(f))return f});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var cc=45,Vl=15,He=new Dn;function Cn(e){if(!(e.length>Vl))return He.new(e).parseWith(()=>He.readIPv4Addr())}function Rn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>cc))return He.new(e).parseWith(()=>He.readIPv6Addr())}function Ve(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>cc)return;let r=He.new(e).parseWith(()=>He.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function uc(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function fc(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Ds(e){switch(e.length){case xe:return e.join(".");case Ee:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function lc(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function dc(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var xe=4,Ee=16,ob=parseInt("0xFFFF",16),jl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Tr(e,t){t.length===Ee&&e.length===xe&&uc(t,0,11)&&(t=t.slice(12)),t.length===xe&&e.length===Ee&&fc(e,jl,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function hc(e,t){if(typeof t=="string"&&(t=Ve(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function Cs(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=xe,o=Cn(t);if(o==null&&(n=Ee,o=Rn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+e);let i=Rs(s,8*n);return{network:Tr(o,i),mask:i}}function Rs(e,t){if(t!==8*xe&&t!==8*Ee)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var Lr=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=Cs(t));else{let n=Ve(t);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Ve(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Rs(o,8*n.length);this.network=Tr(n,this.mask)}}contains(t){return hc({network:this.network,mask:this.mask},t)}toString(){let t=lc(this.mask),r=t!==-1?String(t):dc(this.mask);return Ds(this.network)+"/"+r}};function pc(e,t){return new Lr(e).contains(t)}function mc(e){try{let t=Lt(e);return t.type==="ip6"?pc("2000::/3",t.host):!1}catch{return!1}}function je(e){return!!Cn(e)}function On(e){return!!Rn(e)}var wc=Gc(bc(),1),Ql=["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"],Jl=Ql.map(e=>new wc.Netmask(e));function Ms(e){for(let t of Jl)if(t.contains(e))return!0;return!1}function td(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function ed(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return Ms(o)}function rd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function nd(e){let t=e.split(":"),r=t[t.length-1];return Ms(r)}function od(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function xc(e){if(je(e))return Ms(e);if(td(e))return ed(e);if(rd(e))return nd(e);if(On(e))return od(e)}function zs(e){try{let t=Lt(e);switch(t.type){case"ip4":case"ip6":return xc(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var st=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Vt=class extends Error{static name="ValidationError";name="ValidationError"},kn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Nn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function qs(e){return t=>et(t,e)}function Hs(e){return t=>Y(t,e)}function Ge(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function ve(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Ec(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=Y(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ve(n);return Rt([r,o],r.length+o.length)}function Sc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Yt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ve(n);return Rt([r,o],r.length+o.length)}function Vs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=et(t,"base32"),o=Ge(r);return`${n}:${o}`}var js=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new st("Invalid byte value in IP address");t[n]=o}),t},vc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=je(r[n]),i;s&&(i=js(r[n]),r[n]=et(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,et(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new st("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},_c=function(e){if(e.byteLength!==4)throw new st("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Ac=function(e){if(e.byteLength!==16)throw new st("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${r}"`)}};function Ic(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${e}"`)}}var Ks=Object.values(ar).map(e=>e.decoder),sd=(function(){let e=Ks[0].or(Ks[1]);return Ks.slice(2).forEach(t=>e=e.or(t)),e})();function Bc(e){return sd.decode(e)}function Tc(e){return t=>e.encoder.encode(t)}function id(e){if(parseInt(e).toString()!==e)throw new Vt("Value must be an integer")}function ad(e){if(e<0)throw new Vt("Value must be a positive integer, or zero")}function cd(e){return t=>{if(t>e)throw new Vt(`Value must be smaller than or equal to ${e}`)}}function ud(...e){return t=>{for(let r of e)r(t)}}var Dr=ud(id,ad,cd(65535));var ot=-1,$s=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Nn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},jt=new $s,Gd=[{code:4,name:"ip4",size:32,valueToBytes:js,bytesToValue:_c,validate:e=>{if(!je(e))throw new Vt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ve,bytesToValue:Ge,validate:Dr},{code:273,name:"udp",size:16,valueToBytes:ve,bytesToValue:Ge,validate:Dr},{code:33,name:"dccp",size:16,valueToBytes:ve,bytesToValue:Ge,validate:Dr},{code:41,name:"ip6",size:128,valueToBytes:vc,bytesToValue:Ac,stringToValue:Ic,validate:e=>{if(!On(e))throw new Vt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ot},{code:43,name:"ipcidr",size:8,bytesToValue:qs("base10"),valueToBytes:Hs("base10")},{code:53,name:"dns",size:ot},{code:54,name:"dns4",size:ot},{code:55,name:"dns6",size:ot},{code:56,name:"dnsaddr",size:ot},{code:132,name:"sctp",size:16,valueToBytes:ve,bytesToValue:Ge,validate:Dr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ot,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ot,bytesToValue:qs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Hs("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Vs,valueToBytes:Ec},{code:445,name:"onion3",size:296,bytesToValue:Vs,valueToBytes:Sc},{code:446,name:"garlic64",size:ot},{code:447,name:"garlic32",size:ot},{code:448,name:"tls"},{code:449,name:"sni",size:ot},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ot,bytesToValue:Tc(po),valueToBytes:Bc},{code:480,name:"http"},{code:481,name:"http-path",size:ot,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ot}];Gd.forEach(e=>{jt.addProtocol(e)});function Lc(e){let t=[],r=0;for(;r<e.length;){let n=wr(e,r),o=jt.getProtocol(n),s=yt(n),i=Wd(o,e,r+s),a=0;i>0&&o.size===ot&&(a=yt(i));let c=s+a+i,u={code:n,name:o.name,bytes:At(e.subarray(r,r+c))};if(i>0){let l=r+s+a,h=e.subarray(l,l+i);u.value=o.bytesToValue?.(h)??et(h)}t.push(u),r+=c}return t}function Dc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=jt.getProtocol(n.code),s=yt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Y(n.value),a=i.byteLength,o.size===ot&&(c=yt(a)));let u=new Uint8Array(s+c+a),l=0;ze(n.code,u,l),l+=s,i!=null&&(o.size===ot&&(ze(a,u,l),l+=c),u.set(i,l)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Rt(r,t)}function Cc(e){if(e.charAt(0)!=="/")throw new st('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=jt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new st(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new st(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new st("Incomplete multiaddr");return t}function Rc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=jt.getProtocol(t.code);if(r==null)throw new st(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Wd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:wr(t,r)}var Xd=Symbol.for("nodejs.util.inspect.custom"),Zs=Symbol.for("@multiformats/multiaddr");function Qd(e){if(e==null&&(e="/"),Oc(e))return e.getComponents();if(e instanceof Uint8Array)return Lc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Cc(e);if(Array.isArray(e))return e;throw new st("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Un=class e{[Zs]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Qd(t),r.validate!==!1&&Jd(this)}get bytes(){return this.#r==null&&(this.#r=Dc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Rc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new kn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return ct(this.bytes,t.bytes)}[Xd](){return`Multiaddr(${this.toString()})`}};function Jd(e){e.getComponents().forEach(t=>{let r=jt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Oc(e){return!!e?.[Zs]}function Pc(e){return new Un(e)}function We(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Mn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Xe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Mn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new Mn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ys=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function zn(e={}){return th(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function th(e,t){t=t??{};let r=t.onEnd,n=new Xe,o,s,i,a=We(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((w,d)=>{s=m=>{s=null,n.push(m);try{w(e(n))}catch(g){d(g)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=We()})}},u=w=>s!=null?s(w):(n.push(w),o),l=w=>(n=new Xe,s!=null?s({error:w}):(n.push({error:w}),o)),h=w=>{if(i)return o;if(t?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:w})},f=w=>i?o:(i=!0,w!=null?l(w):u({done:!0})),p=()=>(n=new Xe,f(),{done:!0}),S=w=>(f(w),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:S,push:h,end:f,get readableLength(){return n.size},onEmpty:async w=>{let d=w?.signal;if(d?.throwIfAborted(),n.isEmpty())return;let m,g;d!=null&&(m=new Promise((x,v)=>{g=()=>{v(new Ys)},d.addEventListener("abort",g)}));try{await Promise.race([a.promise,m])}finally{g!=null&&d!=null&&d?.removeEventListener("abort",g)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(w){return E.throw(w),r!=null&&(r(w),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(w){return E.end(w),r!=null&&(r(w),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:w=>E.onEmpty(w)},o}var Gs=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},kc=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Ws(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,l=new Promise((h,f)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){f(kc(i));return}if(i&&(c=()=>{f(kc(i))},i.addEventListener("abort",c,{once:!0})),e.then(h,f),r===Number.POSITIVE_INFINITY)return;let p=new Gs;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(S){f(S)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?h():o instanceof Error?f(o):(p.message=o??`Promise timed out after ${r} milliseconds`,f(p))},r)}).finally(()=>{l.clear(),c&&i&&i.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},l}var eh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function rh(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:l}=eh(e),h=async(...p)=>{let S=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(S))return}catch(E){n(),i(E);return}c.push(S),r.count===c.length&&(n(),s(c))},f=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)l(p,h);for(let p of r.rejectionEvents)a.includes(p)||l(p,f)};for(let p of a)u(p,h);for(let p of r.rejectionEvents)a.includes(p)||u(p,f);r.signal&&r.signal.addEventListener("abort",()=>{f(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=Ws(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Qe(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=rh(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Cr(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Kn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},_e=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function nh(e){return e.reason}async function Rr(e,t,r){if(t==null)return e;let n=r?.translateError??nh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var qn=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=We(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Nt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function oh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Hn=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,r){this.id=oh(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Nt),this.cleanup())}async join(t){let r=new qn(t);return this.recipients.push(r),t?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Rr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var Vn=class extends Nr{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=Cr(this.emitEmpty.bind(this),1),this.emitIdle=Cr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Kn;let n=new Hn(t,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Nt)}),this.clear()}async onEmpty(t){this.size!==0&&await Qe(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await Qe(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Qe(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=zn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Nt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function jn(e){let t=new globalThis.AbortController;function r(){let s=e.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let s of e){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}var sh=4194304,$n=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Qs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Js=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ti=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ih(e){return typeof e?.closeRead=="function"}function ah(e){return typeof e?.close=="function"}function Xs(e){return ih(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:ah(e)?e.status!=="open":!1}function ch(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function uh(e,t){let r=t?.maxBufferSize??sh,n=new nt,o,s=!1;if(!ch(e))throw new ht("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}o?.resolve()};e.addEventListener("message",i);let a=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};e.addEventListener("close",a);let c=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(s===!0)throw new $n("Stream was unwrapped");if(Xs(e)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new _e(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let h=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await Rr(o.promise,l?.signal),Xs(e)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let f=l?.bytes??n.byteLength;if(n.byteLength<f){if(Xs(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,f),new _e(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return u.read(l)}let p=n.sublist(0,f);return n.consume(f),p},async write(l,h){if(s===!0)throw new $n("Stream was unwrapped");e.send(l)||await Qe(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n))),e}};return u}function fh(e,t={}){let r=uh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=yt(t.maxDataLength));let n=t?.lengthDecoder??wr,o=t?.lengthEncoder??ka;return{async read(i){let a=-1,c=new nt;for(;;){let l=await r.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Qs("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ti(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Js(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new _e(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new _e(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new nt(o(i.byteLength),i),a)},async writeV(i,a){let c=new nt(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function ei(e,t){let r=fh(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.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:()=>r.unwrap()};return n}var Zn=class extends Vn{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function Nc(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal},l;r?.timeout!=null&&(l=jn([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=l),s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{l!=null&&(l.aborted?l.clear():l.addEventListener("abort",()=>{l.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Cr(i,r?.debounce??100),c=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var ri=class extends Map{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Fc(e){let{name:t,metrics:r}=e,n;return r!=null?n=new ri({name:t,metrics:r}):n=new Map,n}var Uc="libp2p",Mc="autonat",zc="1.0.0";var $;(function(e){let t;(function(f){f.DIAL="DIAL",f.DIAL_RESPONSE="DIAL_RESPONSE"})(t=e.MessageType||(e.MessageType={}));let r;(function(f){f[f.DIAL=0]="DIAL",f[f.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(r||(r={})),(function(f){f.codec=()=>Ke(r)})(t=e.MessageType||(e.MessageType={}));let n;(function(f){f.OK="OK",f.E_DIAL_ERROR="E_DIAL_ERROR",f.E_DIAL_REFUSED="E_DIAL_REFUSED",f.E_BAD_REQUEST="E_BAD_REQUEST",f.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=e.ResponseStatus||(e.ResponseStatus={}));let o;(function(f){f[f.OK=0]="OK",f[f.E_DIAL_ERROR=100]="E_DIAL_ERROR",f[f.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",f[f.E_BAD_REQUEST=200]="E_BAD_REQUEST",f[f.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(f){f.codec=()=>Ke(o)})(n=e.ResponseStatus||(e.ResponseStatus={}));let s;(function(f){let p;f.codec=()=>(p==null&&(p=Kt((d,m,g={})=>{if(g.lengthDelimited!==!1&&m.fork(),d.id!=null&&(m.uint32(10),m.bytes(d.id)),d.addrs!=null&&d.addrs.length>0)for(let x of d.addrs)m.uint32(18),m.bytes(x);g.lengthDelimited!==!1&&m.ldelim()},(d,m,g={})=>{let x={addrs:[]},v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();switch(C>>>3){case 1:{x.id=d.bytes();break}case 2:{if(g.limits?.addrs!=null&&x.addrs.length===g.limits.addrs)throw new vr('Decode error - repeated field "addrs" had too many elements');x.addrs.push(d.bytes());break}default:{d.skipType(C&7);break}}}return x},function*(d,m,g,x={}){let v={addrs:0},C=m==null?d.len:d.pos+m;for(;d.pos<C;){let M=d.uint32();switch(M>>>3){case 1:{yield{field:`${g}.id`,value:d.bytes()};break}case 2:{if(x.limits?.addrs!=null&&v.addrs===x.limits.addrs)throw new vr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${g}.addrs[]`,index:v.addrs,value:d.bytes()},v.addrs++;break}default:{d.skipType(M&7);break}}}})),p);function S(d){return Mt(d,f.codec())}f.encode=S;function E(d,m){return Ut(d,f.codec(),m)}f.decode=E;function w(d,m){return zt(d,f.codec(),m)}f.stream=w})(s=e.PeerInfo||(e.PeerInfo={}));let i;(function(f){let p;f.codec=()=>(p==null&&(p=Kt((d,m,g={})=>{g.lengthDelimited!==!1&&m.fork(),d.peer!=null&&(m.uint32(10),e.PeerInfo.codec().encode(d.peer,m)),g.lengthDelimited!==!1&&m.ldelim()},(d,m,g={})=>{let x={},v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();C>>>3===1?x.peer=e.PeerInfo.codec().decode(d,d.uint32(),{limits:g.limits?.peer}):d.skipType(C&7)}return x},function*(d,m,g,x={}){let v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();C>>>3===1?yield*e.PeerInfo.codec().stream(d,d.uint32(),`${g}.peer`,{limits:x.limits?.peer}):d.skipType(C&7)}})),p);function S(d){return Mt(d,f.codec())}f.encode=S;function E(d,m){return Ut(d,f.codec(),m)}f.decode=E;function w(d,m){return zt(d,f.codec(),m)}f.stream=w})(i=e.Dial||(e.Dial={}));let a;(function(f){let p;f.codec=()=>(p==null&&(p=Kt((d,m,g={})=>{g.lengthDelimited!==!1&&m.fork(),d.status!=null&&(m.uint32(8),e.ResponseStatus.codec().encode(d.status,m)),d.statusText!=null&&(m.uint32(18),m.string(d.statusText)),d.addr!=null&&(m.uint32(26),m.bytes(d.addr)),g.lengthDelimited!==!1&&m.ldelim()},(d,m,g={})=>{let x={},v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();switch(C>>>3){case 1:{x.status=e.ResponseStatus.codec().decode(d);break}case 2:{x.statusText=d.string();break}case 3:{x.addr=d.bytes();break}default:{d.skipType(C&7);break}}}return x},function*(d,m,g,x={}){let v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();switch(C>>>3){case 1:{yield{field:`${g}.status`,value:e.ResponseStatus.codec().decode(d)};break}case 2:{yield{field:`${g}.statusText`,value:d.string()};break}case 3:{yield{field:`${g}.addr`,value:d.bytes()};break}default:{d.skipType(C&7);break}}}})),p);function S(d){return Mt(d,f.codec())}f.encode=S;function E(d,m){return Ut(d,f.codec(),m)}f.decode=E;function w(d,m){return zt(d,f.codec(),m)}f.stream=w})(a=e.DialResponse||(e.DialResponse={}));let c;e.codec=()=>(c==null&&(c=Kt((f,p,S={})=>{S.lengthDelimited!==!1&&p.fork(),f.type!=null&&(p.uint32(8),e.MessageType.codec().encode(f.type,p)),f.dial!=null&&(p.uint32(18),e.Dial.codec().encode(f.dial,p)),f.dialResponse!=null&&(p.uint32(26),e.DialResponse.codec().encode(f.dialResponse,p)),S.lengthDelimited!==!1&&p.ldelim()},(f,p,S={})=>{let E={},w=p==null?f.len:f.pos+p;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{E.type=e.MessageType.codec().decode(f);break}case 2:{E.dial=e.Dial.codec().decode(f,f.uint32(),{limits:S.limits?.dial});break}case 3:{E.dialResponse=e.DialResponse.codec().decode(f,f.uint32(),{limits:S.limits?.dialResponse});break}default:{f.skipType(d&7);break}}}return E},function*(f,p,S,E={}){let w=p==null?f.len:f.pos+p;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{yield{field:`${S}.type`,value:e.MessageType.codec().decode(f)};break}case 2:{yield*e.Dial.codec().stream(f,f.uint32(),`${S}.dial`,{limits:E.limits?.dial});break}case 3:{yield*e.DialResponse.codec().stream(f,f.uint32(),`${S}.dialResponse`,{limits:E.limits?.dialResponse});break}default:{f.skipType(d&7);break}}}})),c);function u(f){return Mt(f,e.codec())}e.encode=u;function l(f,p){return Ut(f,e.codec(),p)}e.decode=l;function h(f,p){return zt(f,e.codec(),p)}e.stream=h})($||($={}));var gh=4,yh=8,Yn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${r.protocolPrefix??Uc}/${Mc}/${zc}`,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.connectionThreshold=r.connectionThreshold??80,this.maxMessageSize=r.maxMessageSize??8192,this.dialResults=Fc({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=Nc(this.findRandomPeers.bind(this),6e4),this.addressFilter=Ls(1024)}[Symbol.toStringTag]="@libp2p/autonat";[si]=["@libp2p/autonat"];get[ii](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,r)=>{this.handleIncomingAutonatStream(t,r).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,r)=>{this.verifyExternalAddresses(r).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let r=jn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:r})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:r})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,r){let n=AbortSignal.timeout(this.timeout);try{let o=ei(t,{maxDataLength:this.maxMessageSize}).pb($),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,r,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,r,n){let o=this.components.addressManager.getAddresses().map(h=>Lt(h).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.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:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let h=ce(a.id);i=In(h)}catch(h){return this.log.error("invalid PeerId - %e",h),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!r.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,r.remotePeer),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(h=>Pc(h)).filter(h=>{try{let f=Lt(h);return zs(h)?!1:f.host!==Lt(r.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",h,r.remoteAddr),!1):o.includes(f.host)?!1:this.components.transportManager.dialTransportForMultiaddr(h)==null?(this.log.trace("not dialing %a - transport unsupported",h),!1):!0}catch{return!1}}).map(h=>(h.getComponents().find(f=>f.code===421)?.value==null&&(h=h.encapsulate(`/p2p/${i.toString()}`)),h));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(h=>h.toString()).join(", "),i);let u="",l=c[0];for(let h of c){let f;l=h;try{if(f=await this.components.connectionManager.openConnection(h,n),!f.remoteAddr.equals(h))throw this.log.error("tried to dial %a but dialed %a",h,f.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,h),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.OK,addr:f.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),u=p.message}finally{f!=null&&await f.close()}}return{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:l.bytes}}}getFirstUnverifiedMultiaddr(t,r){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||Lt(o.multiaddr).type==="ip6"&&(!r||!mc(o.multiaddr))||zs(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:As(),queue:new Zn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>Lt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,r,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=ei(i).pb($),[,c]=await Promise.all([a.write({type:$.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==$.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!==$.ResponseStatus.OK&&u!==$.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(r)){this.log.trace("%a results included network segment %s",n.multiaddr,r);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(r),u===$.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===$.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===gh&&this.confirmAddress(o),o.failure===yh&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let r=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return r/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let r=Lt(t);switch(r.type){case"ip4":return r.host.split(".")[0].padStart(3,"0");case"ip6":return r.host.split(":")[0].padStart(4,"0");default:throw new ht(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function bh(e={}){return t=>new Yn(t,e)}return Wc(wh);})();
|
|
2
|
+
"use strict";var Libp2PAutonat=(()=>{var $c=Object.create;var Or=Object.defineProperty;var Zc=Object.getOwnPropertyDescriptor;var Yc=Object.getOwnPropertyNames;var Gc=Object.getPrototypeOf,Wc=Object.prototype.hasOwnProperty;var Wn=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},bt=(e,t)=>{for(var r in t)Or(e,r,{get:t[r],enumerable:!0})},si=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Yc(t))!Wc.call(e,o)&&o!==r&&Or(e,o,{get:()=>t[o],enumerable:!(n=Zc(t,o))||n.enumerable});return e};var Xc=(e,t,r)=>(r=e!=null?$c(Gc(e)):{},si(t||!e||!e.__esModule?Or(r,"default",{value:e,enumerable:!0}):r,e)),Qc=e=>si(Or({},"__esModule",{value:!0}),e);var ks=Wn(Ze=>{"use strict";Object.defineProperty(Ze,"__esModule",{value:!0});Ze.Netmask4Impl=void 0;Ze.ip2long=$e;Ze.long2ip=kt;function kt(e){let t=(e&-16777216)>>>24,r=(e&255<<16)>>>16,n=(e&65280)>>>8,o=e&255;return[t,r,n,o].join(".")}var Gl=48,Wl=97,Xl=65;function Ql(e){let t=0,r=10,n="9",o=0;e.length>1&&e[o]==="0"&&(e[o+1]==="x"||e[o+1]==="X"?(o+=2,r=16):"0"<=e[o+1]&&e[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<e.length;){if("0"<=e[o]&&e[o]<=n)t=t*r+(e.charCodeAt(o)-Gl)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-Wl)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-Xl)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function $e(e){let t=[];for(let r=0;r<=3&&e.length!==0;r++){if(r>0){if(e[0]!==".")throw new Error("Invalid IP");e=e.substring(1)}let[n,o]=Ql(e);e=e.substring(o),t.push(n)}if(e.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var Ps=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=$e(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=($e(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=kt(this.netLong),this.mask=kt(this.maskLong),this.hostmask=kt(~this.maskLong),this.first=this.bitmask<=30?kt(this.netLong+1):this.base,this.last=this.bitmask<=30?kt(this.netLong+this.size-2):kt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?kt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):($e(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new e(kt(this.netLong+this.size*t),this.mask)}forEach(t){let r=$e(this.first),n=$e(this.last),o=0;for(;r<=n;)t(kt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Ze.Netmask4Impl=Ps});var wc=Wn(Ye=>{"use strict";Object.defineProperty(Ye,"__esModule",{value:!0});Ye.Netmask6Impl=void 0;Ye.ip6bigint=Fs;Ye.bigint2ip6=Se;var Jl=ks(),Ns=(1n<<128n)-1n;function Fs(e){let t=e.indexOf("%");t!==-1&&(e=e.substring(0,t));let r=e.lastIndexOf(":");if(r!==-1&&e.indexOf(".",r)!==-1){let n=e.substring(r+1),o=(0,Jl.ip2long)(n),s=e.substring(0,r+1)+"0:0";return bc(s)&~0xffffffffn|BigInt(o)}return bc(e)}function bc(e){let t=e.indexOf("::"),r;if(t!==-1){let o=e.substring(0,t),s=e.substring(t+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=e.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Se(e){if(e<0n||e>Ns)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(e&0xffffn)),e>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return t.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=t.slice(0,r).map(c=>c.toString(16)),a=t.slice(r+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var Us=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Ns>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Fs(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Se(this.netBigint),this.mask=Se(this.maskBigint),this.hostmask=Se(~this.maskBigint&Ns),this.first=this.base,this.last=Se(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.last):(Fs(t)&this.maskBigint)===this.netBigint}next(t=1){let r=1n<<BigInt(128-this.bitmask);return new e(Se(this.netBigint+r*BigInt(t)),this.bitmask)}forEach(t){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)t(Se(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};Ye.Netmask6Impl=Us});var xc=Wn(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});ie.long2ip=ie.ip2long=ie.Netmask=void 0;var Pn=ks();Object.defineProperty(ie,"ip2long",{enumerable:!0,get:function(){return Pn.ip2long}});Object.defineProperty(ie,"long2ip",{enumerable:!0,get:function(){return Pn.long2ip}});var td=wc(),Ms=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new td.Netmask6Impl(t,r):this._impl=new Pn.Netmask4Impl(t,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Pn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new e(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new e(t))),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let r=this._impl.next(t);return new e(r.base,r.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ie.Netmask=Ms});var Sh={};bt(Sh,{autoNAT:()=>Eh});var Nt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ht=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Pr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var kr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var er=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Xn=Symbol.for("@libp2p/peer-id");function Jc(e){return typeof e?.handleEvent=="function"}function tu(e){return e===!0||e===!1}function eu(e){return tu(e)?e:e?.capture??!1}function Qn(e){let t={capture:eu(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function ii(e,t){return Qn(e).capture===Qn(t).capture}var Nr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let o=Qn(n);if(o?.signal?.aborted===!0)return;let s=u=>{o.once&&this.removeEventListener(t,r,o),Jc(r)?r.handleEvent(u):r(u)},i=this.#t.get(t);if(i==null&&(i=[],this.#t.set(t,i)),i.some(u=>u.callback!==r?!1:ii(u.options,o)))return;super.addEventListener(t,s,o);let c=()=>{this.removeEventListener(t,r,o)};o.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:s,options:o,onAbort:c})}removeEventListener(t,r,n){let o=this.#t.get(t);if(o==null){super.removeEventListener(t,r??null,n);return}this.#t.set(t,o.filter(s=>s.callback===r&&ii(s.options,n)?(super.removeEventListener(t,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var ai=Symbol.for("@libp2p/service-capabilities"),ci=Symbol.for("@libp2p/service-dependencies");var no={};bt(no,{base58btc:()=>tt,base58flickr:()=>uu});var Qh=new Uint8Array(0);function fi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function xt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ae(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ae(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function li(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var ui=4096;function di(e){let t=e.length;if(t<=ui)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=ui));return r}function ru(e){return e?.buffer instanceof ArrayBuffer}function ae(e){return ru(e)?e:e.slice()}function nu(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<e.length;s++){var i=e.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var l=e.length,h=e.charAt(0),f=Math.log(l)/Math.log(256),p=Math.log(256)/Math.log(l);function S(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var m=0,g=0,x=0,v=d.length;x!==v&&d[x]===0;)x++,m++;for(var C=(v-x)*p+1>>>0,M=new Uint8Array(C);x!==v;){for(var N=d[x],P=0,k=C-1;(N!==0||P<g)&&k!==-1;k--,P++)N+=256*M[k]>>>0,M[k]=N%l>>>0,N=N/l>>>0;if(N!==0)throw new Error("Non-zero carry");g=P,x++}for(var z=C-g;z!==C&&M[z]===0;)z++;for(var R=h.repeat(m);z<C;++z)R+=e.charAt(M[z]);return R}function E(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var m=0;if(d[m]!==" "){for(var g=0,x=0;d[m]===h;)g++,m++;for(var v=(d.length-m)*f+1>>>0,C=new Uint8Array(v);d[m];){var M=n[d.charCodeAt(m)];if(M===255)return;for(var N=0,P=v-1;(M!==0||N<x)&&P!==-1;P--,N++)M+=l*C[P]>>>0,C[P]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");x=N,m++}if(d[m]!==" "){for(var k=v-x;k!==v&&C[k]===0;)k++;for(var z=new Uint8Array(g+(v-k)),R=g;k!==v;)z[R++]=C[k++];return z}}}function w(d){var m=E(d);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:S,decodeUnsafe:E,decode:w}}var ou=nu,su=ou,pi=su;var Jn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},to=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return mi(this,t)}},eo=class{decoders;constructor(t){this.decoders=t}or(t){return mi(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function mi(e,t){return new eo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var ro=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Jn(t,r,n),this.decoder=new to(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ie({name:e,prefix:t,encode:r,decode:n}){return new ro(e,t,r,n)}function Zt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=pi(r,e,n);return Ie({prefix:t,name:e,encode:o,decode:i=>xt(s(i))})}function iu(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=t[e[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function au(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function cu(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let o=e[n].toLowerCase(),s=e[n].toUpperCase();o!==e[n]&&(r[o]=n),s!==e[n]&&(r[s]=n)}return r}function J({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=cu(n,o);return Ie({prefix:t,name:e,encode(i){return au(i,n,r)},decode(i){return iu(i,s,r,e)}})}var tt=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),uu=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var oo={};bt(oo,{base32:()=>Yt,base32hex:()=>hu,base32hexpad:()=>mu,base32hexpadupper:()=>gu,base32hexupper:()=>pu,base32pad:()=>lu,base32padupper:()=>du,base32upper:()=>fu,base32z:()=>yu});var Yt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),fu=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),lu=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),du=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),hu=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),pu=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),mu=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),gu=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),yu=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var so={};bt(so,{base36:()=>rr,base36upper:()=>bu});var rr=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),bu=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var wu=bi,gi=128,xu=127,Eu=~xu,Su=Math.pow(2,31);function bi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Su;)t[r++]=e&255|gi,e/=128;for(;e&Eu;)t[r++]=e&255|gi,e>>>=7;return t[r]=e|0,bi.bytes=r-n+1,t}var vu=io,_u=128,yi=127;function io(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw io.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&yi)<<o:(i&yi)*Math.pow(2,o),o+=7}while(i>=_u);return io.bytes=s-n,r}var Au=Math.pow(2,7),Iu=Math.pow(2,14),Bu=Math.pow(2,21),Tu=Math.pow(2,28),Lu=Math.pow(2,35),Du=Math.pow(2,42),Cu=Math.pow(2,49),Ru=Math.pow(2,56),Ou=Math.pow(2,63),Pu=function(e){return e<Au?1:e<Iu?2:e<Bu?3:e<Tu?4:e<Lu?5:e<Du?6:e<Cu?7:e<Ru?8:e<Ou?9:10},ku={encode:wu,decode:vu,encodingLength:Pu},Nu=ku,nr=Nu;function or(e,t=0){let r=nr.decode(e,t),n=nr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Be(e,t,r=0){return nr.encode(e,t,r),t}function Te(e){return nr.encodingLength(e)}function De(e,t){let r=t.byteLength,n=Te(e),o=n+Te(r),s=new Uint8Array(o+r);return Be(e,s,0),Be(r,s,n),s.set(t,o),new Le(e,r,t,s)}function ce(e){let t=xt(e),[r,n]=or(t),[o,s]=or(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(r,o,i,t)}function wi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&fi(e.bytes,r.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=ae(n),this.bytes=ae(o)}};function xi(e,t){let{bytes:r,version:n}=e;return n===0?Uu(r,ao(e),t??tt.encoder):Mu(r,ao(e),t??Yt.encoder)}var Ei=new WeakMap;function ao(e){let t=Ei.get(e);if(t==null){let r=new Map;return Ei.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=ae(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==sr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=De(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&wi(t.multihash,n.multihash)}toString(t){return xi(this,t)}toJSON(){return{"/":xi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Si(n,o,s.bytes))}else if(r[Ku]===!0){let{version:n,multihash:o,code:s}=r,i=ce(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==sr)throw new Error(`Version 0 CID must use dag-pb (code: ${sr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Si(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,sr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=xt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Le(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,f]=or(t.subarray(r));return r+=f,h},o=n(),s=sr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,r){let[n,o]=Fu(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ao(s).set(n,t),s}};function Fu(e,t){switch(e[0]){case"Q":{let r=t??tt;return[tt.prefix,r.decode(`${tt.prefix}${e}`)]}case tt.prefix:{let r=t??tt;return[tt.prefix,r.decode(e)]}case Yt.prefix:{let r=t??Yt;return[Yt.prefix,r.decode(e)]}case rr.prefix:{let r=t??rr;return[rr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Uu(e,t,r){let{prefix:n}=r;if(n!==tt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Mu(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var sr=112,zu=18;function Si(e,t,r){let n=Te(e),o=n+Te(t),s=new Uint8Array(o+r.byteLength);return Be(e,s,0),Be(t,s,n),s.set(r,o),s}var Ku=Symbol.for("@ipld/js-cid/CID");var co={};bt(co,{identity:()=>_t});var vi=0,qu="identity",_i=xt;function Hu(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return De(vi,_i(e))}var _t={code:vi,name:qu,encode:_i,digest:Hu};function ct(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Vu(e){return e.buffer instanceof ArrayBuffer}function At(e){return Vu(e)?e:e.slice()}async function Ai(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,At(t),At(r.subarray()));return n?.signal?.throwIfAborted(),s}function Et(e=0){return new Uint8Array(e)}function ut(e=0){return new Uint8Array(e)}function ju(e){return e?.buffer instanceof ArrayBuffer}function uo(e){if(ju(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Rt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ut(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return uo(r)}var Bi=Symbol.for("@achingbrain/uint8arraylist");function Ii(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Ur(e){return!!e?.[Bi]}var nt=class e{bufs;length;[Bi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ur(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ur(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Ii(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ii(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Ur(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Rt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Rt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=r>a&&r<=c;if(u&&l){if(t===a&&r===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Ur(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let h=r;h<=c;h+=l){l=0;for(let f=u;f>=0;f--){let p=this.get(h+f);if(n[f]!==p){l=Math.max(1,f-a[p]);break}}if(l===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ut(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ut(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ct(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var fo={};bt(fo,{base10:()=>$u});var $u=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var lo={};bt(lo,{base16:()=>Zu,base16upper:()=>Yu});var Zu=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Yu=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ho={};bt(ho,{base2:()=>Gu});var Gu=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var po={};bt(po,{base256emoji:()=>tf});var Ti=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=Ti.reduce((e,t,r)=>(e[r]=t,e),[]),Xu=Ti.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Qu(e){return e.reduce((t,r)=>(t+=Wu[r],t),"")}function Ju(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Xu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var tf=Ie({prefix:"\u{1F680}",name:"base256emoji",encode:Qu,decode:Ju});var go={};bt(go,{base64:()=>ef,base64pad:()=>rf,base64url:()=>mo,base64urlpad:()=>nf});var ef=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),rf=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),mo=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nf=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var yo={};bt(yo,{base8:()=>of});var of=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bo={};bt(bo,{identity:()=>sf});var sf=Ie({prefix:"\0",name:"identity",encode:e=>di(xt(e)),decode:e=>xt(li(e))});var Fp=new TextEncoder,Up=new TextDecoder;var Eo={};bt(Eo,{sha256:()=>ir,sha512:()=>ff});var uf=20;function xo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new wo(e,t,r,n,o)}var wo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??uf,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Li(n,this.code,r?.truncate):n.then(o=>Li(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Li(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return De(t,e)}function Ci(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ir=xo({name:"sha2-256",code:18,encode:Ci("SHA-256")}),ff=xo({name:"sha2-512",code:19,encode:Ci("SHA-512")});var ar={...bo,...ho,...yo,...fo,...lo,...oo,...so,...no,...go,...po},Wp={...Eo,...co};function Oi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ri=Oi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),So=Oi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ut(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),lf={utf8:Ri,"utf-8":Ri,hex:ar.base16,latin1:So,ascii:So,binary:So,...ar},Mr=lf;function Y(e,t="utf8"){let r=Mr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function et(e,t="utf8"){let r=Mr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var df=parseInt("11111",2),vo=parseInt("10000000",2),hf=parseInt("01111111",2),Pi={0:cr,1:cr,2:pf,3:yf,4:bf,5:gf,6:mf,16:cr,22:cr,48:cr};function _o(e,t={offset:0}){let r=e[t.offset]&df;if(t.offset++,Pi[r]!=null)return Pi[r](e,t);throw new Error("No decoder for tag "+r)}function ur(e,t){let r=0;if((e[t.offset]&vo)===vo){let n=e[t.offset]&hf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");o+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function cr(e,t){ur(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=_o(e,t);if(n===null)break;r.push(n)}return r}function pf(e,t){let r=ur(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function mf(e,t){let r=ur(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let h=0;h<c.length;h++)l+=c[h]<<h*7;a+=`.${l}`,c=[]}}return a}function gf(e,t){return t.offset++,null}function yf(e,t){let r=ur(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function bf(e,t){let r=ur(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function wf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new nt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Ao(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=wf(e.byteLength);return new nt(Uint8Array.from([t.byteLength|vo]),t)}function ki(e){let t=new nt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new nt(Uint8Array.from([2]),Ao(t),t)}function Ni(e){let t=Uint8Array.from([0]),r=new nt(t,e);return new nt(Uint8Array.from([3]),Ao(r),r)}function zr(e,t=48){let r=new nt;for(let n of e)r.append(n);return new nt(Uint8Array.from([t]),Ao(r),r)}var xf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ef=Uint8Array.from([6,5,43,129,4,0,34]),Sf=Uint8Array.from([6,5,43,129,4,0,35]),vf={ext:!0,kty:"EC",crv:"P-256"},_f={ext:!0,kty:"EC",crv:"P-384"},Af={ext:!0,kty:"EC",crv:"P-521"},Io=32,Bo=48,To=66;function Fi(e){let t=_o(e);return Ui(t)}function Ui(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Io*2+1)return n=et(t.subarray(r,r+Io),"base64url"),o=et(t.subarray(r+Io),"base64url"),new Ce({...vf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Bo*2+1)return n=et(t.subarray(r,r+Bo),"base64url"),o=et(t.subarray(r+Bo),"base64url"),new Ce({..._f,key_ops:["verify"],x:n,y:o});if(t.byteLength===To*2+1)return n=et(t.subarray(r,r+To),"base64url"),o=et(t.subarray(r+To),"base64url"),new Ce({...Af,key_ops:["verify"],x:n,y:o});throw new ht(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Mi(e){return zr([ki(Uint8Array.from([1])),zr([If(e.crv)],160),zr([Ni(new nt(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function If(e){if(e==="P-256")return xf;if(e==="P-384")return Ef;if(e==="P-521")return Sf;throw new ht(`Invalid curve ${e}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Mi(this.jwk)),this._raw}toMultihash(){return _t.digest(Re(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r,n){return Ai(this.jwk,r,t,n)}};var Kr=BigInt(4294967295),zi=BigInt(32);function Bf(e,t=!1){return t?{h:Number(e&Kr),l:Number(e>>zi&Kr)}:{h:Number(e>>zi&Kr)|0,l:Number(e&Kr)|0}}function Ki(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Bf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Tf=e=>e/2**32|0,Lf=e=>e>>>0;function qi(e,t,r,n){let o=Tf(r),s=Lf(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var Lo=(e,t,r)=>e>>>r,Do=(e,t,r)=>e<<32-r|t>>>r,ue=(e,t,r)=>e>>>r|t<<32-r,fe=(e,t,r)=>e<<32-r|t>>>r,fr=(e,t,r)=>e<<64-r|t>>>r-32,lr=(e,t,r)=>e>>>r-32|t<<64-r;function Ot(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Hi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Vi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ji=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),$i=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Zi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Yi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function qr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Co=e=>e?`"${e}" `:"";function Ft(e,t=""){if(typeof e!="number")throw new TypeError(Co(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Co(t)+"expected integer >= 0, got "+e);return e}function St(e,t,r=""){if(qr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Ft(t,"length");let n=qr(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=Co(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function Hr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ft(e.outputLen),Ft(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Gi=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)};function Oe(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function Vr(e,t){St(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function le(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function jr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var Xi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Cf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $r(e){if(St(e),Xi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Cf[e[r]];return t}function Wi(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Zr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Xi)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Wi(e.charCodeAt(s)),a=Wi(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ro(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];St(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Rf(e,t,r="opts"){return Gi(e,"defaults"),t!==void 0&&Gi(t,r),Object.assign(e,t)}function Oo(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Rf({},t,"info");let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Qi(e=32){Ft(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Po=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Ji(e,t,r){return e&t^~e&r}function ta(e,t,r){return e&t^e&r^t&r}var dr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=jr(this.buffer)}update(t){Oe(this),St(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=jr(t);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){Oe(this),Vr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),qi(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:jr(t),c=this.outputLen,u=c/4,l=this.get();if(c%4||u>l.length)throw new Error("invalid outputLen");for(let h=0;h<u;h++)a.setUint32(4*h,l[h],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(r),t}clone(){return this._cloneInto()}},ea=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ra=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Of=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Wt=new Uint32Array(64),ko=class extends dr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let h=0;h<16;h++,r+=4)Wt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let f=Wt[h-15],p=Wt[h-2],S=It(f,7)^It(f,18)^f>>>3,E=It(p,17)^It(p,19)^p>>>10;Wt[h]=E+Wt[h-7]+S+Wt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let h=0;h<64;h++){let f=It(a,6)^It(a,11)^It(a,25),p=l+f+Ji(a,c,u)+Of[h]+Wt[h]|0,E=(It(n,2)^It(n,13)^It(n,22))+ta(n,o,s)|0;l=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+E|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(){le(Wt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),le(this.buffer)}},No=class extends ko{constructor(){super(32,ea)}};var na=Ki(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Pf=na[0],kf=na[1],Xt=new Uint32Array(80),Qt=new Uint32Array(80),Fo=class extends dr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:h,Fl:f,Gh:p,Gl:S,Hh:E,Hl:w}=this;return[t,r,n,o,s,i,a,c,u,l,h,f,p,S,E,w]}set(t,r,n,o,s,i,a,c,u,l,h,f,p,S,E,w){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=h|0,this.Fl=f|0,this.Gh=p|0,this.Gl=S|0,this.Hh=E|0,this.Hl=w|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let g=0;g<16;g++,r+=4)Xt[g]=t.getUint32(r),Qt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let x=Xt[g-15]|0,v=Qt[g-15]|0,C=ue(x,v,1)^ue(x,v,8)^Lo(x,v,7),M=fe(x,v,1)^fe(x,v,8)^Do(x,v,7),N=Xt[g-2]|0,P=Qt[g-2]|0,k=ue(N,P,19)^fr(N,P,61)^Lo(N,P,6),z=fe(N,P,19)^lr(N,P,61)^Do(N,P,6),R=ji(M,z,Qt[g-7],Qt[g-16]),Z=$i(R,C,k,Xt[g-7],Xt[g-16]);Xt[g]=Z|0,Qt[g]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:h,El:f,Fh:p,Fl:S,Gh:E,Gl:w,Hh:d,Hl:m}=this;for(let g=0;g<80;g++){let x=ue(h,f,14)^ue(h,f,18)^fr(h,f,41),v=fe(h,f,14)^fe(h,f,18)^lr(h,f,41),C=h&p^~h&E,M=f&S^~f&w,N=Zi(m,v,M,kf[g],Qt[g]),P=Yi(N,d,x,C,Pf[g],Xt[g]),k=N|0,z=ue(n,o,28)^fr(n,o,34)^fr(n,o,39),R=fe(n,o,28)^lr(n,o,34)^lr(n,o,39),Z=n&s^n&a^s&a,D=o&i^o&c^i&c;d=E|0,m=w|0,E=p|0,w=S|0,p=h|0,S=f|0,{h,l:f}=Ot(u|0,l|0,P|0,k|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let L=Hi(k,R,D);n=Vi(L,P,z,Z),o=L|0}({h:n,l:o}=Ot(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ot(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ot(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Ot(this.Dh|0,this.Dl|0,u|0,l|0),{h,l:f}=Ot(this.Eh|0,this.El|0,h|0,f|0),{h:p,l:S}=Ot(this.Fh|0,this.Fl|0,p|0,S|0),{h:E,l:w}=Ot(this.Gh|0,this.Gl|0,E|0,w|0),{h:d,l:m}=Ot(this.Hh|0,this.Hl|0,d|0,m|0),this.set(n,o,s,i,a,c,u,l,h,f,p,S,E,w,d,m)}roundClean(){le(Xt,Qt)}destroy(){this.destroyed=!0,le(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Uo=class extends Fo{constructor(){super(64,ra)}};var oa=Oo(()=>new No,Po(1));var Mo=Oo(()=>new Uo,Po(3));function Gr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var H=(e,t,r)=>St(e,t,r),zo=Ft;function ia(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Jt(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function de(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var hr=$r,vt=(...e)=>Ro(...e),Pe=e=>Zr(e),ee=qr,he=e=>Qi(e),Yr=BigInt(0),sa=BigInt(1),Nf=e=>e?`"${e}" `:"";function mt(e,t=""){if(typeof e!="boolean")throw new TypeError(Nf(t)+"expected boolean, got type="+typeof e);return e}function Wr(e){if(typeof e=="bigint"){if(!te(e))throw new RangeError("positive bigint expected, got "+e)}else zo(e);return e}function re(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function pr(e){let t=Wr(e).toString(16);return t.length&1?"0"+t:t}function aa(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Yr:BigInt("0x"+e)}function Pt(e){return aa($r(e))}function pe(e){return aa($r(Qr(St(e)).reverse()))}function Xr(e,t){if(Ft(t),t===0)throw new Error("zero output length is invalid");e=Wr(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Zr(n.padStart(r,"0"))}function Ko(e,t){return Xr(e,t).reverse()}function Qr(e){return Uint8Array.from(H(e))}function te(e){return typeof e=="bigint"&&Yr<=e}function qo(e,t,r){return te(e)&&te(t)&&te(r)&&t<=e&&e<r}function ke(e,t,r,n){if(!qo(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ne(e){if(e<Yr)throw new Error("expected non-negative bigint, got "+e);return e===Yr?0:e.toString(2).length}var mr=e=>(re(e,"n"),(sa<<BigInt(e))-sa);function ca(e,t,r){if(Ft(e,"hashLen"),Ft(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),l=0,h=()=>{c.fill(1),u.fill(0),l=0},f=(...w)=>r(u,vt(c,...w)),p=(w=o)=>{u=f(s,w),c=f(),w.length!==0&&(u=f(i,w),c=f())},S=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,d=[];for(;w<t;){c=f();let m=c.slice();d.push(m),w+=c.length}return vt(...d)};return(w,d)=>{h(),p(w);let m;for(;(m=d(S()))===void 0;)p();return h(),m}}function gt(e,t={},r={},n="object"){Jt(e,n),Jt(t,"fields"),Jt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,l=e[i];if(!Object.hasOwn(e,i)&&(c?l!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&l===void 0)return;let h=typeof l;if(h!==a||l===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${h}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var rt=BigInt(0),V=BigInt(1),ne=BigInt(2),la=BigInt(3),Ho=BigInt(4),da=BigInt(5),Ff=BigInt(7),ha=BigInt(8),Uf=BigInt(9),Mf=BigInt(15),pa=BigInt(16),zf=BigInt("0x10000000000000000");function W(e,t){if(t<=rt)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=rt?r:t+r}function ma(e,t,r){if(r<=V)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<rt)throw new Error("invalid exponent, negatives unsupported");if(t===rt)return V;if(t===V)return e;let n=e%r;if(n<rt&&(n+=r),t<zf){let a=V;for(;t>rt;)t&V&&(a=a*n%r),n=n*n%r,t>>=V;return a}let o=[];for(;t>rt;)o.push(Number(t&Mf)),t>>=Ho;let s=new Array(16);s[0]=V,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function G(e,t,r){if(r<=V)throw new Error("pow2: expected modulus > 1, got "+r);if(t<rt)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >rt;)n*=n,n%=r;return n}function ua(e,t){if(e===rt)throw new Error("invert: expected non-zero number");if(t<=V)throw new Error("invert: expected modulus > 1, got "+t);let r=W(e,t),n=t,o=rt,s=V;for(;r!==rt;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==V)throw new Error("invert: does not exist");return W(o,t)}function ga(e,t){if(t<=V)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=W(e,t);if(r===rt)throw new Error("invertCt: expected non-zero number");let n=ma(r,t-ne,t);if(W(r*n,t)!==V)throw new Error("invertCt: does not exist");return n}function Vo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function jo(e,t){if((e&V)===rt)throw new Error(t+": expected odd modulus, got "+e)}function ya(e,t){let r=e,n=(r.ORDER+V)/Ho,o=r.pow(t,n);return Vo(r,o,t),o}function Kf(e,t){let r=e,n=(r.ORDER-da)/ha,o=r.mul(t,ne),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,ne),s),c=r.mul(i,r.sub(a,r.ONE));return Vo(r,c,t),c}function qf(e){let t=Ue(e),r=ba(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Ff)/pa;return((a,c)=>{let u=a,l=u.pow(c,i),h=u.mul(l,n),f=u.mul(l,o),p=u.mul(l,s),S=u.eql(u.sqr(h),c),E=u.eql(u.sqr(f),c);l=u.cmov(l,h,S),h=u.cmov(p,f,E);let w=u.eql(u.sqr(h),c),d=u.cmov(l,h,w);return Vo(u,d,c),d})}function ba(e){if(e<la)throw new Error("sqrt is not defined for small field");jo(e,"tonelliShanks");let t=e-V,r=0;for(;t%ne===rt;)t/=ne,r++;let n=ne,o=Ue(e);for(;gr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ya;let s=o.pow(n,t),i=(t+V)/ne;return function(c,u){let l=c;if(l.is0(u))return u;if(gr(l,u)!==1)throw new Error("Cannot find square root");let h=r,f=l.mul(l.ONE,s),p=l.pow(u,t),S=l.pow(u,i);for(;!l.eql(p,l.ONE);){if(l.is0(p))throw new Error("Cannot find square root: probably non-prime P");let E=1,w=l.sqr(p);for(;!l.eql(w,l.ONE);)if(E++,w=l.sqr(w),E===h)throw new Error("Cannot find square root");let d=V<<BigInt(h-E-1),m=l.pow(f,d);h=E,f=l.sqr(m),p=l.mul(p,f),S=l.mul(S,m)}return S}}function Hf(e){return jo(e,"Fp.sqrt"),e%Ho===la?ya:e%ha===da?Kf:e%pa===Uf?qf(e):ba(e)}var wa=(e,t)=>(W(e,t)&V)===V,Vf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Fe(e){if(Jt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);re(e.BYTES,"BYTES"),re(e.BITS,"BITS");for(let t of Vf)de(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=V)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function tn(e,t,r=!1){Fe(e),Gr(t,"nums"),mt(r,"passZero");let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function gr(e,t){Fe(e);let r=e;jo(r.ORDER,"FpLegendre");let n=(r.ORDER-V)/ne,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function jf(e,t){if(t!==void 0&&zo(t),e<=rt)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Ne(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var fa=new WeakMap,Jr=class{ORDER;BITS;BYTES;isLE;ZERO=rt;ONE=V;_lengths;_mod;constructor(t,r={}){if(t<=V)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=jf(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return rt<=t&&t<this.ORDER}is0(t){return t===rt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return W(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return W(t*t,this.ORDER)}add(t,r){return W(t+r,this.ORDER)}sub(t,r){return W(t-r,this.ORDER)}mul(t,r){return W(t*r,this.ORDER)}pow(t,r){return ma(t,r,this.ORDER)}div(t,r){return W(t*ua(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return ua(t,this.ORDER)}sqrt(t){let r=fa.get(this);return r||fa.set(this,r=Hf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Ko(t,this.BYTES):Xr(t,this.BYTES)}fromBytes(t,r=!1){H(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?pe(t):Pt(t);if(a&&(c=W(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return tn(this,t,!0)}cmov(t,r,n){return mt(n,"condition"),n?r:t}};function Ue(e,t={}){return Object.freeze(Jr.prototype),new Jr(e,t)}function xa(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=V)throw new Error("field order must be greater than 1");let t=Ne(e-V);return Math.ceil(t/8)}function en(e){let t=xa(e);return t+Math.ceil(t/2)}function rn(e,t,r=!1){H(e);let n=e.length,o=xa(t),s=Math.max(en(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?pe(e):Pt(e),a=W(i,t-V)+V;return r?Ko(a,o):Xr(a,o)}var Yo=BigInt(0),yr=BigInt(1),$f=BigInt(4),$o=16,Ea=128,Zf=5,Sa=2**31;function oe(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);de(t.fromAffine,"Point.fromAffine"),de(t.fromBytes,"Point.fromBytes"),de(t.fromHex,"Point.fromHex"),Jt(t.BASE,"Point.BASE"),Jt(t.ZERO,"Point.ZERO"),Fe(t.Fp),Fe(t.Fn)}function nn(e,t){oe(e),_a(t,e);let r=tn(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Yf(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function Gf(e,t){let r=e*(4*t+128);if(r>Sa)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Sa/2**20+" MiB")}function Go(e,t){if(e!==void 0){de(e,"randomBytes");try{let r=e(t);if(!ee(r)||r.length!==t)return}catch{return}return e}}function _a(e,t){Gr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Wf(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,o)=>{if(!(r===void 0?t.isValid(n):te(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var Aa=new WeakMap;function Zo(e){return Aa.get(e)||1}function Xf(e,t){let r=e.double(),n=[e];for(let o=1;o<t;o++)n.push(n[o-1].add(r));return n}function Qf(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>Yo;){let i=0;e&yr&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=yr}return s}function Jf(e,t,r){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&s);e>>=i,u>o&&(u-=n,e+=yr),a.push(u)}if(e!==Yo)throw new Error("invalid wnaf");return a}function tl(e,t,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=e;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=t[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Me=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){oe(t),this.randomBytes=Go(r,$o),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=t;for(let c=0;c<o;c++){let u=a;for(let l=0;l<s;l++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(t,r){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=Jf(r,n,o),c=this.ZERO,u=this.BASE;for(let l=0;l<o;l++){let h=a[l],f=l*i,p=Math.abs(h)-1,S=s[f];for(let w=1;w<i;w++)S=w===p?s[f+w]:S;let E=S.negate();h===0?u=u.add(s[f]):c=c.add(h<0?E:S)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===t&&a.bits===n);return i||(i=this.buildWnafTable(r,t,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!qo(r,yr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=Zo(t);return s===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Ea,s=this.randomBytes($o);if(!ee(s)||s.length!==$o)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Pt(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,r,n){let o=Zf,s=1<<o,i=mr(o),a=new Array(s);a[0]=this.ZERO;for(let l=1;l<s;l++)a[l]=a[l-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let l=c-1;l>=0;l--){if(l!==c-1)for(let p=0;p<o;p++)u=u.double();let h=Number(r>>BigInt(l*o)&i),f=a[0];for(let p=1;p<s;p++)f=p===h?a[p]:f;u=u.add(f)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===yr?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,o):this.mulCT(t,r,o)}mulUnsafe(t,r,n){if(this.assertPoint(t),!te(r))throw new Error("invalid scalar");let o=Zo(t);if(o===1||r>=this.Point.Fn.ORDER)return on(this.Point,[t],[r],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(t,r){this.assertPoint(t),Yf(r,this.bits);let n=Math.ceil((this.bits+Ea)/r)+1;Gf(n*2**(r-1),this.Point.Fp.BYTES),Aa.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return Zo(t)!==1}};function on(e,t,r,n=!1){if(oe(e),_a(t,e),mt(n,"allowOversized"),Wf(r,e.Fn,n?e.Fn.ORDER**$f:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>Xf(i,4)),s=r.map(i=>Qf(i,4));return tl(e.ZERO,o,s)}function va(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Fe(t),t}else return Ue(e,{isLE:r})}function sn(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);gt(r);for(let c of["p","n","h"]){let u=t[c];if(!(te(u)&&u!==Yo))throw new Error(`CURVE.${c} must be positive bigint`)}let o=va(t.p,r.Fp,n),s=va(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function an(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var cn=BigInt(0),un=BigInt(1),fn=BigInt(2),el=BigInt(4),Ia=BigInt(8);function rl(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function Ba(e,t={}){gt(t,{},{},"extraOpts");let r=t,n=sn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(gr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(gr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");gt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?he:r.randomBytes,u=fn<<BigInt(o.BYTES*8)-un;function l(m){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(m)}let h=r.uvRatio===void 0?(m,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(m,g))}}catch{return{isValid:!1,value:cn}}}:r.uvRatio;if(!rl(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let f=o.eql(i.a,o.neg(o.ONE))?m=>o.neg(m):o.eql(i.a,o.ONE)?m=>m:m=>o.mul(i.a,m);function p(m,g,x=!1){let v=x?un:cn;return ke("coordinate "+m,g,v,u),g}function S(m){if(!(m instanceof E))throw new Error("EdwardsPoint expected")}class E{static BASE=new E(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new E(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(g,x,v,C){this.X=p("x",g),this.Y=p("y",x),this.Z=p("z",v,!0),this.T=p("t",C),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof E)throw new Error("extended point not allowed");let{x,y:v}=g||{};return p("x",x),p("y",v),new E(x,v,o.ONE,o.mul(x,v))}static fromBytes(g,x=!1){let v=o.BYTES,{a:C,d:M}=i;g=Qr(H(g,v,"point")),mt(x,"zip215");let N=Qr(g),P=g[v-1];N[v-1]=P&-129;let k=pe(N),z=x?u:o.ORDER;ke("point.y",k,cn,z);let R=o.sqr(k),Z=o.sub(R,o.ONE),D=o.sub(o.mulN(M,R),C),{isValid:L,value:y}=h(Z,D);if(!L)throw new Error("bad point: invalid y coordinate");let _=l(y),I=(P&128)!==0;if(!x&&o.is0(y)&&I)throw new Error("bad point: x=0 and x_0=1");return I!==_&&(y=o.neg(y)),E.fromAffine({x:y,y:k})}static fromHex(g,x=!1){return E.fromBytes(Pe(g),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,x=!0){return d.setWindowSize(this,g),x||this.multiply(fn),this}assertValidity(){let g=this,{a:x,d:v}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:C,Y:M,Z:N,T:P}=g,k=o.sqr(C),z=o.sqr(M),R=o.sqr(N),Z=o.sqr(R),D=o.mul(k,x),L=o.mul(o.add(D,z),R),y=o.add(Z,o.mul(v,o.mul(k,z)));if(!o.eql(L,y))throw new Error("bad point: equation left != right (1)");let _=o.mul(C,M),I=o.mul(N,P);if(!o.eql(_,I))throw new Error("bad point: equation left != right (2)")}equals(g){S(g);let{X:x,Y:v,Z:C}=this,{X:M,Y:N,Z:P}=g,k=o.mul(x,P),z=o.mul(M,C),R=o.mul(v,P),Z=o.mul(N,C);return o.eql(k,z)&&o.eql(R,Z)}is0(){return this.equals(E.ZERO)}negate(){return new E(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:x,Z:v}=this,C=o.sqr(g),M=o.sqr(x),N=o.mul(o.sqr(v),fn),P=f(C),k=o.addN(g,x),z=o.sub(o.subN(o.sqr(k),C),M),R=o.addN(P,M),Z=o.subN(R,N),D=o.subN(P,M),L=o.mul(z,Z),y=o.mul(R,D),_=o.mul(z,D),I=o.mul(Z,R);return new E(L,y,I,_)}add(g){S(g);let{d:x}=i,{X:v,Y:C,Z:M,T:N}=this,{X:P,Y:k,Z:z,T:R}=g,Z=o.mul(v,P),D=o.mul(C,k),L=o.mul(o.mulN(N,x),R),y=o.mul(M,z),_=o.sub(o.subN(o.mulN(o.addN(v,C),o.addN(P,k)),Z),D),I=o.subN(y,L),O=o.addN(y,L),A=o.sub(D,f(Z)),b=o.mul(_,I),B=o.mul(O,A),T=o.mul(_,A),F=o.mul(I,O);return new E(b,B,F,T)}subtract(g){return S(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:v}=d.mulSecret(this,g,a,w);return w([x,v])[0]}multiplyUnsafe(g){if(!s.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===cn?E.ZERO:this.is0()||g===un?this:d.mulUnsafe(this,g,w)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return d.mulUnsafe(this,i.n).is0()}toAffine(g){let x=this,v=g;if(v!=null&&typeof v!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof v);let{X:C,Y:M,Z:N}=x,P=x.is0();v==null&&(v=P?o.create(Ia):o.inv(N));let k=o.mul(C,v),z=o.mul(M,v),R=o.mul(N,v);if(P)return{x:o.ZERO,y:o.ONE};if(!o.eql(R,o.ONE))throw new Error("invZ was invalid");return{x:k,y:z}}clearCofactor(){return a===un?this:a===fn?this.double():a===el?this.double().double():a===Ia?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:x}=this.toAffine(),v=o.toBytes(x);return v[v.length-1]|=l(g)?128:0,v}toHex(){return hr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let w=m=>nn(E,m),d=new Me(E,c);return d.bits>=6&&E.BASE.precompute(6),Object.freeze(E.prototype),Object.freeze(E),E}function Ta(e,t,r={}){if(oe(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;gt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,l=2*a.BYTES;if(u!==void 0&&(re(u,"hash.outputLen"),u!==l))throw new Error(`hash.outputLen must be ${l}, got ${u}`);let h=o.randomBytes===void 0?he:o.randomBytes,f=o.toMontgomery,p=o.toMontgomerySecret,S=o.adjustScalarBytes===void 0?D=>D:o.adjustScalarBytes,E=o.domain===void 0?(D,L,y)=>{if(mt(y,"phflag"),L.length||y)throw new Error("Contexts/pre-hash are not supported");return D}:o.domain;function w(D){return c.create(pe(D))}function d(D){let L=P.secretKey;H(D,P.secretKey,"secretKey");let y=H(n(D),2*L,"hashedSecretKey"),_=S(y.slice(0,L)),I=y.slice(L,2*L),O=w(_);return{head:_,prefix:I,scalar:O}}function m(D){let{head:L,prefix:y,scalar:_}=d(D),I=i.multiply(_),O=I.toBytes();return{head:L,prefix:y,scalar:_,point:I,pointBytes:O}}function g(D){return m(D).pointBytes}function x(D=Uint8Array.of(),...L){let y=vt(...L);return w(n(E(y,H(D,void 0,"context"),!!s)))}function v(D,L,y={}){gt(y,{},{},"options"),D=H(D,void 0,"message"),s&&(D=s(D));let{prefix:_,scalar:I,pointBytes:O}=m(L),A=x(y.context,_,D),b=i.multiply(A).toBytes(),B=x(y.context,b,O,D),T=c.create(A+B*I);if(!c.isValid(T))throw new Error("sign failed: invalid s");let F=vt(b,c.toBytes(T));return H(F,P.signature,"result")}let C={zip215:o.zip215};function M(D,L,y,_=C){gt(_);let{context:I}=_,O=_.zip215===void 0?!!C.zip215:_.zip215,A=P.signature;D=H(D,A,"signature"),L=H(L,void 0,"message"),y=H(y,P.publicKey,"publicKey"),O!==void 0&&mt(O,"zip215"),s&&(L=s(L));let b=A/2,B=D.subarray(0,b),T=pe(D.subarray(b,A)),F,U,q;try{F=e.fromBytes(y,O),U=e.fromBytes(B,O),q=i.multiplyUnsafe(T)}catch{return!1}if(!O&&F.isSmallOrder())return!1;let K=x(I,B,y,L);return U.add(F.multiplyUnsafe(K)).subtract(q).clearCofactor().is0()}let N=a.BYTES,P={secretKey:N,publicKey:N,signature:2*N,seed:N};function k(D){return D=D===void 0?h(P.seed):D,H(D,P.seed,"seed")}function z(D){return ee(D)&&D.length===P.secretKey}function R(D,L){try{return!!e.fromBytes(D,L===void 0?C.zip215:L)}catch{return!1}}let Z={getExtendedPublicKey:m,randomSecretKey:k,isValidSecretKey:z,isValidPublicKey:R,toMontgomery(D){if(f===void 0)throw new Error("Montgomery conversion is not supported for this curve");return f(e.fromBytes(D))},toMontgomerySecret(D){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(D)}};return Object.freeze(P),Object.freeze(Z),Object.freeze({keygen:an(k,g),getPublicKey:g,sign:v,verify:M,utils:Z,Point:e,lengths:P})}var Wo=BigInt(1),La=BigInt(2);var nl=BigInt(5),ol=BigInt(8),Xo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),sl={p:Xo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ol,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function il(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Xo,a=e*e%s*e%s,c=G(a,La,s)*a%s,u=G(c,Wo,s)*e%s,l=G(u,nl,s)*u%s,h=G(l,t,s)*l%s,f=G(h,r,s)*h%s,p=G(f,n,s)*f%s,S=G(p,o,s)*p%s,E=G(S,o,s)*p%s,w=G(E,t,s)*l%s;return{pow_p_5_8:G(w,La,s)*e%s,b2:a}}function Ra(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Da=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function al(e,t){let r=Xo,n=W(t*t*t,r),o=W(n*n*t,r),s=il(e*o).pow_p_5_8,i=W(e*n*s,r),a=W(t*i*i,r),c=i,u=W(i*Da,r),l=a===e,h=a===W(-e,r),f=a===W(-e*Da,r);return l&&(i=c),(h||f)&&(i=u),wa(i,r)&&(i=W(-i,r)),{isValid:l||h,value:i}}var Qo=Ba(sl,{uvRatio:al}),Ca=Qo.Fp;function cl(e){let{y:t}=e;return Ca.toBytes(Ca.div(Wo+t,Wo-t))}function ul(e){let t=Qo.Fp.BYTES;return St(e,t),Ra(Mo(e.subarray(0,t))).subarray(0,t)}function fl(e){return Ta(Qo,Mo,Object.assign({adjustScalarBytes:Ra,toMontgomery:cl,toMontgomerySecret:ul,zip215:!0},e))}var Oa=fl({});var br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},ln=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var dn={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new ln("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var hn=32;var Jo,ll=(async()=>{try{return await dn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function dl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await dn.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await dn.get().subtle.verify({name:"Ed25519"},n,At(t),At(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function hl(e,t,r){return Oa.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Pa(e,t,r){return Jo==null&&(Jo=await ll),Jo?dl(e,t,r):hl(e,t,r)}function pn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var mn=class{type="Ed25519";raw;constructor(t){this.raw=ts(t,hn)}toMultihash(){return _t.digest(Re(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Pa(this.raw,r,t);return pn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Na(e){return e=ts(e,hn),new mn(e)}function ts(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ht(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ml=Math.pow(2,7),gl=Math.pow(2,14),yl=Math.pow(2,21),es=Math.pow(2,28),rs=Math.pow(2,35),ns=Math.pow(2,42),os=Math.pow(2,49),j=128,ft=127;function yt(e){if(e<ml)return 1;if(e<gl)return 2;if(e<yl)return 3;if(e<es)return 4;if(e<rs)return 5;if(e<ns)return 6;if(e<os)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ze(e,t,r=0){switch(yt(e)){case 8:t[r++]=e&255|j,e/=128;case 7:t[r++]=e&255|j,e/=128;case 6:t[r++]=e&255|j,e/=128;case 5:t[r++]=e&255|j,e/=128;case 4:t[r++]=e&255|j,e>>>=7;case 3:t[r++]=e&255|j,e>>>=7;case 2:t[r++]=e&255|j,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function bl(e,t,r=0){switch(yt(e)){case 8:t.set(r++,e&255|j),e/=128;case 7:t.set(r++,e&255|j),e/=128;case 6:t.set(r++,e&255|j),e/=128;case 5:t.set(r++,e&255|j),e/=128;case 4:t.set(r++,e&255|j),e>>>=7;case 3:t.set(r++,e&255|j),e>>>=7;case 2:t.set(r++,e&255|j),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ss(e,t){let r=e[t],n=0;if(n+=r&ft,r<j||(r=e[t+1],n+=(r&ft)<<7,r<j)||(r=e[t+2],n+=(r&ft)<<14,r<j)||(r=e[t+3],n+=(r&ft)<<21,r<j)||(r=e[t+4],n+=(r&ft)*es,r<j)||(r=e[t+5],n+=(r&ft)*rs,r<j)||(r=e[t+6],n+=(r&ft)*ns,r<j)||(r=e[t+7],n+=(r&ft)*os,r<j))return n;throw new RangeError("Could not decode varint")}function wl(e,t){let r=e.get(t),n=0;if(n+=r&ft,r<j||(r=e.get(t+1),n+=(r&ft)<<7,r<j)||(r=e.get(t+2),n+=(r&ft)<<14,r<j)||(r=e.get(t+3),n+=(r&ft)<<21,r<j)||(r=e.get(t+4),n+=(r&ft)*es,r<j)||(r=e.get(t+5),n+=(r&ft)*rs,r<j)||(r=e.get(t+6),n+=(r&ft)*ns,r<j)||(r=e.get(t+7),n+=(r&ft)*os,r<j))return n;throw new RangeError("Could not decode varint")}function Fa(e,t,r=0){return t==null&&(t=ut(yt(e))),t instanceof Uint8Array?ze(e,t,r):bl(e,t,r)}function wr(e,t=0){return e instanceof Uint8Array?ss(e,t):wl(e,t)}var is=new Float32Array([-0]),se=new Uint8Array(is.buffer);function Ma(e,t,r){is[0]=e,t[r]=se[0],t[r+1]=se[1],t[r+2]=se[2],t[r+3]=se[3]}function za(e,t){return se[0]=e[t],se[1]=e[t+1],se[2]=e[t+2],se[3]=e[t+3],is[0]}var as=new Float64Array([-0]),lt=new Uint8Array(as.buffer);function Ka(e,t,r){as[0]=e,t[r]=lt[0],t[r+1]=lt[1],t[r+2]=lt[2],t[r+3]=lt[3],t[r+4]=lt[4],t[r+5]=lt[5],t[r+6]=lt[6],t[r+7]=lt[7]}function qa(e,t){return lt[0]=e[t],lt[1]=e[t+1],lt[2]=e[t+2],lt[3]=e[t+3],lt[4]=e[t+4],lt[5]=e[t+5],lt[6]=e[t+6],lt[7]=e[t+7],as[0]}var xl=BigInt(Number.MAX_SAFE_INTEGER),El=BigInt(Number.MIN_SAFE_INTEGER),wt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return me;if(t<xl&&t>El)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Ha&&(o=0n,++n>Ha&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return me;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):me}},me=new wt(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var Ha=4294967296n;function Va(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ja(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function cs(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Bt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function gn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var us=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=At(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Bt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Bt(this,4);return gn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return gn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=za(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=qa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ja(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new wt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=gn(this.buf,this.pos+=4),r=gn(this.buf,this.pos+=4);return new wt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ss(this.buf,this.pos);return this.pos+=yt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function xr(e){return new us(e instanceof Uint8Array?e:e.subarray())}function Ut(e,t,r){let n=xr(e);return t.decode(n,void 0,r)}function fs(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ut(i);o+i>t&&(n=ut(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ge=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function ls(){}var hs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Sl=fs();function vl(e){return globalThis.Buffer!=null?ut(e):Sl(e)}var Sr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ge(ls,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ge(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ps((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(yn,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=wt.fromBigInt(t);return this._push(yn,r.length(),r)}uint64Number(t){return this._push(ze,yt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=wt.fromBigInt(t).zzEncode();return this._push(yn,r.length(),r)}sint64Number(t){let r=wt.fromNumber(t).zzEncode();return this._push(yn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ds,1,t?1:0)}fixed32(t){return this._push(Er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=wt.fromBigInt(t);return this._push(Er,4,r.lo)._push(Er,4,r.hi)}fixed64Number(t){let r=wt.fromNumber(t);return this._push(Er,4,r.lo)._push(Er,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ma,4,t)}double(t){return this._push(Ka,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ds,1,0):this.uint32(r)._push(Al,r,t)}string(t){let r=Va(t);return r!==0?this.uint32(r)._push(cs,r,t):this._push(ds,1,0)}fork(){return this.states=new hs(this),this.head=this.tail=new ge(ls,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 ge(ls,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=vl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ds(e,t,r){t[r]=e&255}function _l(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ps=class extends ge{next;constructor(t,r){super(_l,t,r),this.next=void 0}};function yn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Er(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Al(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Sr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Il,t,e),this},Sr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Bl,t,e),this});function Il(e,t,r){t.set(e,r)}function Bl(e,t,r){e.length<40?cs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Y(e),r)}function ms(){return new Sr}function Mt(e,t){let r=ms();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*zt(e,t,r){let n=xr(e);yield*t.stream(n,void 0,"$",r)}var bn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function wn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Ke(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return wn("enum",bn.VARINT,r,n,o)}function Kt(e,t,r){return wn("message",bn.LENGTH_DELIMITED,e,t,r)}var vr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var pt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(pt||(pt={}));var gs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(gs||(gs={}));(function(e){e.codec=()=>Ke(gs)})(pt||(pt={}));var _r;(function(e){let t;e.codec=()=>(t==null&&(t=Kt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return Mt(s,e.codec())}e.encode=r;function n(s,i){return Ut(s,e.codec(),i)}e.decode=n;function o(s,i){return zt(s,e.codec(),i)}e.stream=o})(_r||(_r={}));var ys;(function(e){let t;e.codec=()=>(t==null&&(t=Kt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return Mt(s,e.codec())}e.encode=r;function n(s,i){return Ut(s,e.codec(),i)}e.decode=n;function o(s,i){return zt(s,e.codec(),i)}e.stream=o})(ys||(ys={}));var xn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Hr(t),St(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),le(o)}update(t){return Oe(this),this.iHash.update(t),this}digestInto(t){Oe(this),Vr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.canXOF=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Za=(()=>{let e=((t,r,n)=>new xn(t,r).update(n).digest());return e.create=(t,r)=>new xn(t,r),e})();var Ll=BigInt(0),bs=class extends Error{constructor(t=""){super(t)}},qt={Err:bs,_tlv:{encode:(e,t)=>{let{Err:r}=qt;if(re(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(ia(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=pr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?pr(o.length/2|128):"";return pr(e)+s+o+t},decode(e,t){let{Err:r}=qt;t=H(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=qt;if(Wr(e),e<Ll)throw new t("integer: negative integers are not allowed");let r=pr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=qt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Pt(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=qt,o=H(e,void 0,"signature"),{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:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=qt;gt(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},ws=(Object.freeze(qt._tlv),Object.freeze(qt._int),Object.freeze(qt));var Ya=(e,t)=>(e+(e>=0?t:-t)/Ga)/t;function Dl(e,t,r){ke("scalar",e,Ht,r);let[[n,o],[s,i]]=t,a=Ya(i*e,r),c=Ya(-o*e,r),u=e-a*n-c*s,l=-a*o-c*i,h=u<Ht,f=l<Ht;h&&(u=-u),f&&(l=-l);let p=mr(Math.ceil(Ne(r)/2))+ye;if(u<Ht||u>=p||l<Ht||l>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:u,k2neg:f,k2:l}}function Ss(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function xs(e,t){gt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return mt(r.lowS,"lowS"),mt(r.prehash,"prehash"),r.format!==void 0&&Ss(r.format),r}var Ht=BigInt(0),ye=BigInt(1),Ga=BigInt(2),Es=BigInt(3),Cl=BigInt(4);function Wa(e,t={}){let r=sn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;gt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u}=t,l=t.randomBytes===void 0?he:t.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let h=Qa(n,o);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(L,y,_){if(u&&y.is0())return Uint8Array.of(0);let{x:I,y:O}=y.toAffine(),A=n.toBytes(I);if(mt(_,"isCompressed"),_){f();let b=!n.isOdd(O);return vt(Xa(b),A)}else return vt(Uint8Array.of(4),A,n.toBytes(O))}function S(L){H(L,void 0,"Point");let{publicKey:y,publicKeyUncompressed:_}=h,I=L.length,O=L[0],A=L.subarray(1);if(u&&I===1&&O===0)return{x:n.ZERO,y:n.ZERO};if(I===y&&(O===2||O===3)){let b=n.fromBytes(A);if(!n.isValid(b))throw new Error("bad point: is not on curve, wrong x");let B=g(b),T;try{T=n.sqrt(B)}catch(q){let K=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+K)}f();let F=n.isOdd(T);return(O&1)===1!==F&&(T=n.neg(T)),{x:b,y:T}}else if(I===_&&O===4){let b=n.BYTES,B=n.fromBytes(A.subarray(0,b)),T=n.fromBytes(A.subarray(b,b*2));if(!x(B,T))throw new Error("bad point: is not on curve");return{x:B,y:T}}else throw new Error(`bad point: got length ${I}, expected compressed=${y} or uncompressed=${_}`)}let E=t.toBytes===void 0?p:t.toBytes,w=t.fromBytes===void 0?S:t.fromBytes,d=n.mul(s.b,Es),m=n.is0(s.a)?L=>n.ZERO:L=>n.mul(s.a,L);function g(L){let y=n.sqr(L),_=n.mul(y,L);return n.add(n.add(_,n.mul(L,s.a)),s.b)}function x(L,y){let _=n.sqr(y),I=g(L);return n.eql(_,I)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,Es),Cl),C=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,C)))throw new Error("bad curve params: a or b");function M(L,y,_=!1){if(!n.isValid(y)||_&&n.is0(y))throw new Error(`bad point coordinate ${L}`);return y}function N(L){if(!(L instanceof R))throw new Error("Weierstrass Point expected")}function P(L){if(!c||!c.basises)throw new Error("no endo");return Dl(L,c.basises,o.ORDER)}function k(L,y,_,I){if(!o.isValid(I))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:O,k1:A,k2neg:b,k2:B}=P(I),T=new R(n.mul(_.X,c.beta),_.Y,_.Z);L.push(O?_.negate():_,b?T.negate():T),y.push(A,B)}else L.push(_),y.push(I)}let z=new WeakSet;class R{static BASE=new R(s.Gx,s.Gy,n.ONE);static ZERO=new R(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,_,I){this.X=M("x",y),this.Y=M("y",_,!0),this.Z=M("z",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:_,y:I}=y||{};if(!y||!n.isValid(_)||!n.isValid(I))throw new Error("invalid affine point");if(y instanceof R)throw new Error("projective point not allowed");return n.is0(_)&&n.is0(I)?R.ZERO:new R(_,I,n.ONE)}static fromBytes(y){let _=R.fromAffine(w(H(y,void 0,"point")));return _.assertValidity(),_}static fromHex(y){return R.fromBytes(Pe(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,_=!0){return D.setWindowSize(this,y),_||this.multiply(Es),this}assertValidity(){let y=this;if(y.is0()){if(t.allowInfinityPoint&&n.is0(y.X)&&n.eql(y.Y,n.ONE)&&n.is0(y.Z))return;throw new Error("bad point: ZERO")}if(z.has(y))return;let{x:_,y:I}=y.toAffine();if(!n.isValid(_)||!n.isValid(I))throw new Error("bad point: x or y not field elements");if(!x(_,I))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");z.add(y)}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){N(y);let{X:_,Y:I,Z:O}=this,{X:A,Y:b,Z:B}=y,T=n.eql(n.mul(_,B),n.mul(A,O)),F=n.eql(n.mul(I,B),n.mul(b,O));return T&&F}negate(){return new R(this.X,n.neg(this.Y),this.Z)}double(){let{X:y,Y:_,Z:I}=this,O=n.ZERO,A=n.ZERO,b=n.ZERO,B=n.mul(y,y),T=n.mul(_,_),F=n.mul(I,I),U=n.mul(y,_);return U=n.add(U,U),b=n.mul(y,I),b=n.add(b,b),O=m(b),A=n.mul(d,F),A=n.add(O,A),O=n.sub(T,A),A=n.add(T,A),A=n.mul(O,A),O=n.mul(U,O),b=n.mul(d,b),F=m(F),U=n.sub(B,F),U=m(U),U=n.add(U,b),b=n.add(B,B),B=n.add(b,B),B=n.add(B,F),B=n.mul(B,U),A=n.add(A,B),F=n.mul(_,I),F=n.add(F,F),B=n.mul(F,U),O=n.sub(O,B),b=n.mul(F,T),b=n.add(b,b),b=n.add(b,b),new R(O,A,b)}add(y){N(y);let{X:_,Y:I,Z:O}=this,{X:A,Y:b,Z:B}=y,T=n.ZERO,F=n.ZERO,U=n.ZERO,q=n.mul(_,A),K=n.mul(I,b),X=n.mul(O,B),dt=n.add(_,I),Q=n.add(A,b);dt=n.mul(dt,Q),Q=n.add(q,K),dt=n.sub(dt,Q),Q=n.add(_,O);let it=n.add(A,B);return Q=n.mul(Q,it),it=n.add(q,X),Q=n.sub(Q,it),it=n.add(I,O),T=n.add(b,B),it=n.mul(it,T),T=n.add(K,X),it=n.sub(it,T),U=m(Q),T=n.mul(d,X),U=n.add(T,U),T=n.sub(K,U),U=n.add(K,U),F=n.mul(T,U),K=n.add(q,q),K=n.add(K,q),X=m(X),Q=n.mul(d,Q),K=n.add(K,X),X=n.sub(q,X),X=m(X),Q=n.add(Q,X),q=n.mul(K,Q),F=n.add(F,q),q=n.mul(it,Q),T=n.mul(dt,T),T=n.sub(T,q),q=n.mul(dt,K),U=n.mul(it,U),U=n.add(U,q),new R(T,F,U)}subtract(y){return N(y),this.add(y.negate())}is0(){return this.equals(R.ZERO)}multiply(y){if(!o.isValidNot0(y))throw new RangeError("invalid scalar: out of range");let{p:_,f:I}=D.mulSecret(this,y,i,Z);return Z([_,I])[0]}multiplyUnsafe(y){let _=this,I=y;if(!o.isValid(I))throw new RangeError("invalid scalar: out of range");if(I===Ht||_.is0())return R.ZERO;if(I===ye)return _;if(D.hasWindowSize(this))return D.mulUnsafe(_,I,Z);let O=[],A=[];return k(O,A,_,I),on(R,O,A)}mulAddUnsafe(y,_,I){N(_);let O=[],A=[];return k(O,A,this,y),k(O,A,_,I),on(R,O,A)}toAffine(y){let _=this,I=y;if(I!=null&&!n.isValid(I))throw new RangeError('"invertedZ" expected valid field element');let{X:O,Y:A,Z:b}=_;if(n.eql(b,n.ONE))return{x:O,y:A};let B=_.is0();I==null&&(I=B?n.ONE:n.inv(b));let T=n.mul(O,I),F=n.mul(A,I),U=n.mul(b,I);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(U,n.ONE))throw new Error("invZ was invalid");return{x:T,y:F}}isTorsionFree(){let{isTorsionFree:y}=t;return i===ye?!0:y?y(R,this):D.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=t;return i===ye?this:y?y(R,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ye?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return mt(y,"isCompressed"),this.assertValidity(),E(R,this,y)}toHex(y=!0){return hr(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Z=L=>nn(R,L),D=new Me(R,l);return D.bits>=6&&R.BASE.precompute(6),Object.freeze(R.prototype),Object.freeze(R),R}function Xa(e){return Uint8Array.of(e?2:3)}function Qa(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Rl(e,t={}){oe(e);let{Fn:r}=e,n=t.randomBytes===void 0?he:t.randomBytes,o=Object.assign(Qa(e.Fp,r),{seed:Math.max(en(r.ORDER),16)});function s(p){try{let S=r.fromBytes(p);return r.isValidNot0(S)}catch{return!1}}function i(p,S){let{publicKey:E,publicKeyUncompressed:w}=o;try{let d=p.length;return S===!0&&d!==E||S===!1&&d!==w?!1:!!e.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,rn(H(p,o.seed,"seed"),r.ORDER)}function c(p,S=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(S)}function u(p){let{secretKey:S,publicKey:E,publicKeyUncompressed:w}=o,d=r._lengths;if(!ee(p))return;let m=H(p,void 0,"key").length,g=m===E||m===w,x=m===S||!!d?.includes(m);if(!(g&&x))return g}function l(p,S,E=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(S)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(p);return e.fromBytes(S).multiply(w).toBytes(E)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},f=an(a,c);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:f,Point:e,utils:h,lengths:o})}function Ja(e,t,r={}){oe(e);let n=t;Hr(n),gt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?he:o.randomBytes,i=o.hmac===void 0?(A,b)=>Za(n,A,b):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:l}=c,h=en(u),f=Go(s,h),{keygen:p,getPublicKey:S,getSharedSecret:E,utils:w,lengths:d}=Rl(e,o),m={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*Ga+ye<a.ORDER;function x(A){let b=u>>ye;return A>b}function v(A,b){if(!c.isValidNot0(b))throw new Error(`invalid signature ${A}: out of range 1..Point.Fn.ORDER`);return b}function C(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(A,b,B){return C(),(A===B?0:2)|Number(a.isOdd(b))}function N(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function P(A,b){Ss(b);let B=d.signature,T=b==="compact"?B:b==="recovered"?B+1:void 0;return H(A,T)}class k{r;s;recovery;constructor(b,B,T){if(this.r=v("r",b),this.s=v("s",B),T!=null){if(N(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(b,B=m.format){P(b,B);let T;if(B==="der"){let{r:K,s:X}=ws.toSig(H(b));return new k(K,X)}B==="recovered"&&(T=b[0],B="compact",b=b.subarray(1));let F=d.signature/2,U=b.subarray(0,F),q=b.subarray(F,F*2);return new k(c.fromBytes(U),c.fromBytes(q),T)}static fromHex(b,B){return this.fromBytes(Pe(b),B)}assertRecovery(){let{recovery:b}=this;if(b==null)throw new Error("invalid recovery id: must be present");return b}addRecoveryBit(b){return new k(this.r,this.s,b)}recoverPublicKey(b){let{r:B,s:T}=this,F=this.assertRecovery(),U=F===2||F===3?B+u:B;if(!a.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let q=a.toBytes(U),K=e.fromBytes(vt(Xa((F&1)===0),q)),X=c.inv(U),dt=R(H(b,void 0,"msgHash")),Q=c.create(-dt*X),it=c.create(T*X),Dt=e.BASE.mulAddUnsafe(Q,K,it);if(Dt.is0())throw new Error("invalid recovery: point at infinify");return Dt.assertValidity(),Dt}hasHighS(){return x(this.s)}toBytes(b=m.format){if(Ss(b),b==="der")return Pe(ws.hexFromSig(this));let{r:B,s:T}=this,F=c.toBytes(B),U=c.toBytes(T);return b==="recovered"?(N(),vt(Uint8Array.of(this.assertRecovery()),F,U)):vt(F,U)}toHex(b){return hr(this.toBytes(b))}}Object.freeze(k.prototype),Object.freeze(k);let z=o.bits2int===void 0?function(b){if(b.length>8192)throw new Error("input is too large");let B=Pt(b),T=b.length*8-l;return T>0?B>>BigInt(T):B}:o.bits2int,R=o.bits2int_modN===void 0?function(b){return c.create(z(b))}:o.bits2int_modN,Z=mr(l);function D(A){return ke("num < 2^"+l,A,Ht,Z),c.toBytes(A)}function L(A,b){return H(A,void 0,"message"),b?H(n(A),void 0,"prehashed message"):A}function y(A,b,B){let{lowS:T,prehash:F,extraEntropy:U}=xs(B,m);A=L(A,F);let q=R(A),K=c.fromBytes(b);if(!c.isValidNot0(K))throw new Error("invalid private key");let X=[D(K),D(q)];if(U!=null&&U!==!1){let Dt=U===!0?s(d.secretKey):U;X.push(H(Dt,void 0,"extraEntropy"))}let dt=vt(...X),Q=q;function it(Dt){let Ae=z(Dt);if(!c.isValidNot0(Ae))return;let Je=e.BASE.multiply(Ae).toAffine(),$t=c.create(Je.x);if($t===Ht)return;let Ct;if(f!==void 0){let tr=Pt(rn(f(h),u)),Hc=c.inv(c.mul(tr,Ae)),Vc=c.mul(tr,Q),jc=c.mul(tr,K);Ct=c.create(Hc*c.create(Vc+jc*$t))}else{let tr=ga(Ae,u);Ct=c.create(tr*c.create(Q+$t*K))}if(Ct===Ht)return;let Gn=M(Je.x,Je.y,$t),oi=Ct;return T&&x(Ct)&&(oi=c.neg(Ct),Gn^=1),new k($t,oi,g?void 0:Gn)}return{seed:dt,k2sig:it}}function _(A,b,B={}){let{seed:T,k2sig:F}=y(A,b,B);return ca(n.outputLen,c.BYTES,i)(T,F).toBytes(B.format)}function I(A,b,B,T={}){let{lowS:F,prehash:U,format:q}=xs(T,m);if(B=H(B,void 0,"publicKey"),b=L(b,U),!ee(A)){let K=A instanceof k?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}P(A,q);try{let K=k.fromBytes(A,q),X=e.fromBytes(B);if(F&&K.hasHighS())return!1;let{r:dt,s:Q}=K,it=R(b),Dt=c.inv(Q),Ae=c.create(it*Dt),Je=c.create(dt*Dt),$t=e.BASE.mulAddUnsafe(Ae,X,Je);if($t.is0())return!1;let Ct=$t.toAffine();return!(c.create(Ct.x)!==dt||q==="recovered"&&K.recovery!==M(Ct.x,Ct.y,dt))}catch{return!1}}function O(A,b,B={}){let{prehash:T}=xs(B,m);return b=L(b,T),k.fromBytes(A,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:p,getPublicKey:S,getSharedSecret:E,utils:w,lengths:d,Point:e,sign:_,verify:I,recoverPublicKey:O,Signature:k,hash:n})}var _s={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ol={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var tc=BigInt(2);function Pl(e){let t=_s.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,h=G(l,r,t)*l%t,f=G(h,r,t)*l%t,p=G(f,tc,t)*u%t,S=G(p,o,t)*p%t,E=G(S,s,t)*S%t,w=G(E,a,t)*E%t,d=G(w,c,t)*w%t,m=G(d,a,t)*E%t,g=G(m,r,t)*l%t,x=G(g,i,t)*S%t,v=G(x,n,t)*u%t,C=G(v,tc,t);if(!vs.eql(vs.sqr(C),e))throw new Error("Cannot find square root");return C}var vs=Ue(_s.p,{sqrt:Pl}),kl=Wa(_s,{Fp:vs,endo:Ol}),qe=Ja(kl,oa);function ec(e,t,r,n){let o=ir.digest(r instanceof Uint8Array?r:r.subarray());if(pn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),qe.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new br(String(s))});try{return n?.signal?.throwIfAborted(),qe.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new br(String(s))}}var En=class{type="secp256k1";raw;_key;constructor(t){this._key=nc(t),this.raw=rc(this._key)}toMultihash(){return _t.digest(Re(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return ec(this._key,r,t,n)}};function oc(e){return new En(e)}function rc(e){return qe.Point.fromBytes(e).toBytes()}function nc(e){try{return qe.Point.fromBytes(e),e}catch(t){throw new Pr(String(t))}}function sc(e){let{Type:t,Data:r}=_r.decode(e.digest),n=r??new Uint8Array;switch(t){case pt.Ed25519:return Na(n);case pt.secp256k1:return oc(n);case pt.ECDSA:return Fi(n);default:throw new er}}function Re(e){return _r.encode({Type:pt[e.type],Data:e.raw})}var ic=Symbol.for("nodejs.util.inspect.custom"),Nl=114,Ar=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()})`}[Xn]=!0;toString(){return this.string==null&&(this.string=tt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Nl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ct(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ct(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ic](){return`PeerId(${this.toString()})`}},Sn=class extends Ar{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},vn=class extends Ar{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},_n=class extends Ar{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Fl=2336,An=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(Y(this.url))}[ic](){return`PeerId(${this.url})`}[Xn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Fl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};function In(e){if(Ml(e))return new Sn({multihash:e});if(Ul(e))try{let t=sc(e);if(t.type==="Ed25519")return new vn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new _n({multihash:e,publicKey:t})}catch{let r=et(e.digest);return new An(new URL(r))}throw new kr("Supplied PeerID Multihash is invalid")}function Ul(e){return e.code===_t.code}function Ml(e){return e.code===ir.code}function As(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function Bn(e){let t=ce(tt.decode(`z${e}`));return In(t)}var Tn=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return As(this.set.entries(),t=>{let r=Bn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=Bn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return As(this.set.values(),t=>Bn(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function Is(){return new Tn}var Bs={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ac={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},cc=new globalThis.TextEncoder;function zl(e,t){let r=Bs[t],n=ac[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function Kl(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Bs[t],o=ac[t],s=e;for(;s.length>0;){let i=cc.encodeInto(s,r);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(t,o*n)}return o}function Ts(e,{size:t=32,utf8Buffer:r}={}){if(!Bs[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof e=="string"){if(r)return Kl(e,t,r);e=cc.encode(e)}return zl(e,t)}var Ir={hash:e=>Number(Ts(e,{size:32})),hashV:(e,t)=>ql(Ir.hash(e,t))};function ql(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),Y(t,"base16")}var Ls=64,Tt=class{fp;h;seed;constructor(t,r,n,o=2){if(o>Ls)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=Et(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ct(this.fp,t.fp):!1}};function be(e,t){return Math.floor(Math.random()*(t-e))+e}var we=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=t,!0;return!0}swap(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let r=be(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=t,n}remove(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var Hl=500,Br=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??Ir,this.seed=t.seed??be(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=Y(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new we(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new we(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[be(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new we(this.bucketSize));for(let a=0;a<Hl;a++){let c=this.buckets[i].swap(r);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new we(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=Y(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(t){typeof t=="string"&&(t=Y(t));let r=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Vl={1:.5,2:.84,4:.95,8:.98};function jl(e=.001){return e>.002?2:e>1e-5?4:8}function uc(e,t=.001){let r=jl(t),n=Vl[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),Ls);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var Ln=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??Ir,this.seed=t.seed??be(0,Math.pow(2,10)),this.filterSeries=[new Br({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=Y(t)),this.has(t))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new Br({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(t)}has(t){typeof t=="string"&&(t=Y(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=Y(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,r)=>t+r.count,0)}};function Ds(e,t=.001,r){return new Ln({...uc(e,t),...r??{}})}function $l(e){let t=e.getComponents(),r={},n=0;return t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r)}function Lt(e){let t=$l(e);if(t==null)throw new ht(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var Dn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let f=Number.parseInt(h,t);if(!Number.isNaN(f))return f});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var fc=45,Zl=15,He=new Dn;function Cn(e){if(!(e.length>Zl))return He.new(e).parseWith(()=>He.readIPv4Addr())}function Rn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>fc))return He.new(e).parseWith(()=>He.readIPv6Addr())}function Ve(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>fc)return;let r=He.new(e).parseWith(()=>He.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function lc(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function dc(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function Cs(e){switch(e.length){case xe:return e.join(".");case Ee:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function hc(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function pc(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var xe=4,Ee=16,ab=parseInt("0xFFFF",16),Yl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Tr(e,t){t.length===Ee&&e.length===xe&&lc(t,0,11)&&(t=t.slice(12)),t.length===xe&&e.length===Ee&&dc(e,Yl,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function mc(e,t){if(typeof t=="string"&&(t=Ve(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function Rs(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=xe,o=Cn(t);if(o==null&&(n=Ee,o=Rn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+e);let i=Os(s,8*n);return{network:Tr(o,i),mask:i}}function Os(e,t){if(t!==8*xe&&t!==8*Ee)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var Lr=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=Rs(t));else{let n=Ve(t);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Ve(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Os(o,8*n.length);this.network=Tr(n,this.mask)}}contains(t){return mc({network:this.network,mask:this.mask},t)}toString(){let t=hc(this.mask),r=t!==-1?String(t):pc(this.mask);return Cs(this.network)+"/"+r}};function gc(e,t){return new Lr(e).contains(t)}function yc(e){try{let t=Lt(e);return t.type==="ip6"?gc("2000::/3",t.host):!1}catch{return!1}}function je(e){return!!Cn(e)}function On(e){return!!Rn(e)}var Ec=Xc(xc(),1),ed=["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"],rd=ed.map(e=>new Ec.Netmask(e));function zs(e){for(let t of rd)if(t.contains(e))return!0;return!1}function nd(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function od(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return zs(o)}function sd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function id(e){let t=e.split(":"),r=t[t.length-1];return zs(r)}function ad(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function Sc(e){if(je(e))return zs(e);if(nd(e))return od(e);if(sd(e))return id(e);if(On(e))return ad(e)}function Ks(e){try{let t=Lt(e);switch(t.type){case"ip4":case"ip6":return Sc(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var st=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Vt=class extends Error{static name="ValidationError";name="ValidationError"},kn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Nn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Hs(e){return t=>et(t,e)}function Vs(e){return t=>Y(t,e)}function Ge(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function ve(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function vc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=Y(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ve(n);return Rt([r,o],r.length+o.length)}function _c(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Yt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ve(n);return Rt([r,o],r.length+o.length)}function js(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=et(t,"base32"),o=Ge(r);return`${n}:${o}`}var $s=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new st("Invalid byte value in IP address");t[n]=o}),t},Ac=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=je(r[n]),i;s&&(i=$s(r[n]),r[n]=et(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,et(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new st("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ic=function(e){if(e.byteLength!==4)throw new st("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Bc=function(e){if(e.byteLength!==16)throw new st("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${r}"`)}};function Tc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${e}"`)}}var qs=Object.values(ar).map(e=>e.decoder),cd=(function(){let e=qs[0].or(qs[1]);return qs.slice(2).forEach(t=>e=e.or(t)),e})();function Lc(e){return cd.decode(e)}function Dc(e){return t=>e.encoder.encode(t)}function ud(e){if(parseInt(e).toString()!==e)throw new Vt("Value must be an integer")}function fd(e){if(e<0)throw new Vt("Value must be a positive integer, or zero")}function ld(e){return t=>{if(t>e)throw new Vt(`Value must be smaller than or equal to ${e}`)}}function dd(...e){return t=>{for(let r of e)r(t)}}var Dr=dd(ud,fd,ld(65535));var ot=-1,Zs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Nn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},jt=new Zs,Qd=[{code:4,name:"ip4",size:32,valueToBytes:$s,bytesToValue:Ic,validate:e=>{if(!je(e))throw new Vt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ve,bytesToValue:Ge,validate:Dr},{code:273,name:"udp",size:16,valueToBytes:ve,bytesToValue:Ge,validate:Dr},{code:33,name:"dccp",size:16,valueToBytes:ve,bytesToValue:Ge,validate:Dr},{code:41,name:"ip6",size:128,valueToBytes:Ac,bytesToValue:Bc,stringToValue:Tc,validate:e=>{if(!On(e))throw new Vt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ot},{code:43,name:"ipcidr",size:8,bytesToValue:Hs("base10"),valueToBytes:Vs("base10")},{code:53,name:"dns",size:ot},{code:54,name:"dns4",size:ot},{code:55,name:"dns6",size:ot},{code:56,name:"dnsaddr",size:ot},{code:132,name:"sctp",size:16,valueToBytes:ve,bytesToValue:Ge,validate:Dr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ot,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ot,bytesToValue:Hs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Vs("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:js,valueToBytes:vc},{code:445,name:"onion3",size:296,bytesToValue:js,valueToBytes:_c},{code:446,name:"garlic64",size:ot},{code:447,name:"garlic32",size:ot},{code:448,name:"tls"},{code:449,name:"sni",size:ot},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ot,bytesToValue:Dc(mo),valueToBytes:Lc},{code:480,name:"http"},{code:481,name:"http-path",size:ot,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ot}];Qd.forEach(e=>{jt.addProtocol(e)});function Cc(e){let t=[],r=0;for(;r<e.length;){let n=wr(e,r),o=jt.getProtocol(n),s=yt(n),i=Jd(o,e,r+s),a=0;i>0&&o.size===ot&&(a=yt(i));let c=s+a+i,u={code:n,name:o.name,bytes:At(e.subarray(r,r+c))};if(i>0){let l=r+s+a,h=e.subarray(l,l+i);u.value=o.bytesToValue?.(h)??et(h)}t.push(u),r+=c}return t}function Rc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=jt.getProtocol(n.code),s=yt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Y(n.value),a=i.byteLength,o.size===ot&&(c=yt(a)));let u=new Uint8Array(s+c+a),l=0;ze(n.code,u,l),l+=s,i!=null&&(o.size===ot&&(ze(a,u,l),l+=c),u.set(i,l)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Rt(r,t)}function Oc(e){if(e.charAt(0)!=="/")throw new st('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=jt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new st(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new st(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new st("Incomplete multiaddr");return t}function Pc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=jt.getProtocol(t.code);if(r==null)throw new st(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Jd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:wr(t,r)}var th=Symbol.for("nodejs.util.inspect.custom"),Ys=Symbol.for("@multiformats/multiaddr");function eh(e){if(e==null&&(e="/"),kc(e))return e.getComponents();if(e instanceof Uint8Array)return Cc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Oc(e);if(Array.isArray(e))return e;throw new st("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Un=class e{[Ys]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=eh(t),r.validate!==!1&&rh(this)}get bytes(){return this.#r==null&&(this.#r=Rc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Pc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new kn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return ct(this.bytes,t.bytes)}[th](){return`Multiaddr(${this.toString()})`}};function rh(e){e.getComponents().forEach(t=>{let r=jt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function kc(e){return!!e?.[Ys]}function Nc(e){return new Un(e)}function We(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Mn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Xe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Mn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new Mn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Gs=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function zn(e={}){return nh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function nh(e,t){t=t??{};let r=t.onEnd,n=new Xe,o,s,i,a=We(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((w,d)=>{s=m=>{s=null,n.push(m);try{w(e(n))}catch(g){d(g)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=We()})}},u=w=>s!=null?s(w):(n.push(w),o),l=w=>(n=new Xe,s!=null?s({error:w}):(n.push({error:w}),o)),h=w=>{if(i)return o;if(t?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:w})},f=w=>i?o:(i=!0,w!=null?l(w):u({done:!0})),p=()=>(n=new Xe,f(),{done:!0}),S=w=>(f(w),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:S,push:h,end:f,get readableLength(){return n.size},onEmpty:async w=>{let d=w?.signal;if(d?.throwIfAborted(),n.isEmpty())return;let m,g;d!=null&&(m=new Promise((x,v)=>{g=()=>{v(new Gs)},d.addEventListener("abort",g)}));try{await Promise.race([a.promise,m])}finally{g!=null&&d!=null&&d?.removeEventListener("abort",g)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(w){return E.throw(w),r!=null&&(r(w),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(w){return E.end(w),r!=null&&(r(w),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:w=>E.onEmpty(w)},o}var Ws=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Fc=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Xs(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,l=new Promise((h,f)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){f(Fc(i));return}if(i&&(c=()=>{f(Fc(i))},i.addEventListener("abort",c,{once:!0})),e.then(h,f),r===Number.POSITIVE_INFINITY)return;let p=new Ws;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(S){f(S)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?h():o instanceof Error?f(o):(p.message=o??`Promise timed out after ${r} milliseconds`,f(p))},r)}).finally(()=>{l.clear(),c&&i&&i.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},l}var oh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function sh(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:l}=oh(e),h=async(...p)=>{let S=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(S))return}catch(E){n(),i(E);return}c.push(S),r.count===c.length&&(n(),s(c))},f=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)l(p,h);for(let p of r.rejectionEvents)a.includes(p)||l(p,f)};for(let p of a)u(p,h);for(let p of r.rejectionEvents)a.includes(p)||u(p,f);r.signal&&r.signal.addEventListener("abort",()=>{f(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=Xs(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Qe(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=sh(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Cr(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Kn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},_e=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function ih(e){return e.reason}async function Rr(e,t,r){if(t==null)return e;let n=r?.translateError??ih;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var qn=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=We(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Nt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function ah(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Hn=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,r){this.id=ah(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Nt),this.cleanup())}async join(t){let r=new qn(t);return this.recipients.push(r),t?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Rr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var Vn=class extends Nr{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=Cr(this.emitEmpty.bind(this),1),this.emitIdle=Cr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Kn;let n=new Hn(t,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Nt)}),this.clear()}async onEmpty(t){this.size!==0&&await Qe(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await Qe(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Qe(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=zn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Nt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function jn(e){let t=new globalThis.AbortController;function r(){let s=e.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let s of e){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}var ch=4194304,$n=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Js=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ti=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ei=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function uh(e){return typeof e?.closeRead=="function"}function fh(e){return typeof e?.close=="function"}function Qs(e){return uh(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:fh(e)?e.status!=="open":!1}function lh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function dh(e,t){let r=t?.maxBufferSize??ch,n=new nt,o,s=!1;if(!lh(e))throw new ht("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}o?.resolve()};e.addEventListener("message",i);let a=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};e.addEventListener("close",a);let c=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(s===!0)throw new $n("Stream was unwrapped");if(Qs(e)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new _e(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let h=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await Rr(o.promise,l?.signal),Qs(e)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let f=l?.bytes??n.byteLength;if(n.byteLength<f){if(Qs(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,f),new _e(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return u.read(l)}let p=n.sublist(0,f);return n.consume(f),p},async write(l,h){if(s===!0)throw new $n("Stream was unwrapped");e.send(l)||await Qe(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n))),e}};return u}function hh(e,t={}){let r=dh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=yt(t.maxDataLength));let n=t?.lengthDecoder??wr,o=t?.lengthEncoder??Fa;return{async read(i){let a=-1,c=new nt;for(;;){let l=await r.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Js("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ei(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ti(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new _e(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new _e(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new nt(o(i.byteLength),i),a)},async writeV(i,a){let c=new nt(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function ri(e,t){let r=hh(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.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:()=>r.unwrap()};return n}var Zn=class extends Vn{has(t){return this.find(t)!=null}find(t){return this.queue.find(r=>t.equals(r.options.peerId))}};function Uc(e,t,r){let n,o,s=!1;function i(){let u={signal:o.signal},l;r?.timeout!=null&&(l=jn([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=l),s=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{l!=null&&(l.aborted?l.clear():l.addEventListener("abort",()=>{l.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=Cr(i,r?.debounce??100),c=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var ni=class extends Map{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Mc(e){let{name:t,metrics:r}=e,n;return r!=null?n=new ni({name:t,metrics:r}):n=new Map,n}var zc="libp2p",Kc="autonat",qc="1.0.0";var $;(function(e){let t;(function(f){f.DIAL="DIAL",f.DIAL_RESPONSE="DIAL_RESPONSE"})(t=e.MessageType||(e.MessageType={}));let r;(function(f){f[f.DIAL=0]="DIAL",f[f.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(r||(r={})),(function(f){f.codec=()=>Ke(r)})(t=e.MessageType||(e.MessageType={}));let n;(function(f){f.OK="OK",f.E_DIAL_ERROR="E_DIAL_ERROR",f.E_DIAL_REFUSED="E_DIAL_REFUSED",f.E_BAD_REQUEST="E_BAD_REQUEST",f.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=e.ResponseStatus||(e.ResponseStatus={}));let o;(function(f){f[f.OK=0]="OK",f[f.E_DIAL_ERROR=100]="E_DIAL_ERROR",f[f.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",f[f.E_BAD_REQUEST=200]="E_BAD_REQUEST",f[f.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(f){f.codec=()=>Ke(o)})(n=e.ResponseStatus||(e.ResponseStatus={}));let s;(function(f){let p;f.codec=()=>(p==null&&(p=Kt((d,m,g={})=>{if(g.lengthDelimited!==!1&&m.fork(),d.id!=null&&(m.uint32(10),m.bytes(d.id)),d.addrs!=null&&d.addrs.length>0)for(let x of d.addrs)m.uint32(18),m.bytes(x);g.lengthDelimited!==!1&&m.ldelim()},(d,m,g={})=>{let x={addrs:[]},v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();switch(C>>>3){case 1:{x.id=d.bytes();break}case 2:{if(g.limits?.addrs!=null&&x.addrs.length===g.limits.addrs)throw new vr('Decode error - repeated field "addrs" had too many elements');x.addrs.push(d.bytes());break}default:{d.skipType(C&7);break}}}return x},function*(d,m,g,x={}){let v={addrs:0},C=m==null?d.len:d.pos+m;for(;d.pos<C;){let M=d.uint32();switch(M>>>3){case 1:{yield{field:`${g}.id`,value:d.bytes()};break}case 2:{if(x.limits?.addrs!=null&&v.addrs===x.limits.addrs)throw new vr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${g}.addrs[]`,index:v.addrs,value:d.bytes()},v.addrs++;break}default:{d.skipType(M&7);break}}}})),p);function S(d){return Mt(d,f.codec())}f.encode=S;function E(d,m){return Ut(d,f.codec(),m)}f.decode=E;function w(d,m){return zt(d,f.codec(),m)}f.stream=w})(s=e.PeerInfo||(e.PeerInfo={}));let i;(function(f){let p;f.codec=()=>(p==null&&(p=Kt((d,m,g={})=>{g.lengthDelimited!==!1&&m.fork(),d.peer!=null&&(m.uint32(10),e.PeerInfo.codec().encode(d.peer,m)),g.lengthDelimited!==!1&&m.ldelim()},(d,m,g={})=>{let x={},v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();C>>>3===1?x.peer=e.PeerInfo.codec().decode(d,d.uint32(),{limits:g.limits?.peer}):d.skipType(C&7)}return x},function*(d,m,g,x={}){let v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();C>>>3===1?yield*e.PeerInfo.codec().stream(d,d.uint32(),`${g}.peer`,{limits:x.limits?.peer}):d.skipType(C&7)}})),p);function S(d){return Mt(d,f.codec())}f.encode=S;function E(d,m){return Ut(d,f.codec(),m)}f.decode=E;function w(d,m){return zt(d,f.codec(),m)}f.stream=w})(i=e.Dial||(e.Dial={}));let a;(function(f){let p;f.codec=()=>(p==null&&(p=Kt((d,m,g={})=>{g.lengthDelimited!==!1&&m.fork(),d.status!=null&&(m.uint32(8),e.ResponseStatus.codec().encode(d.status,m)),d.statusText!=null&&(m.uint32(18),m.string(d.statusText)),d.addr!=null&&(m.uint32(26),m.bytes(d.addr)),g.lengthDelimited!==!1&&m.ldelim()},(d,m,g={})=>{let x={},v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();switch(C>>>3){case 1:{x.status=e.ResponseStatus.codec().decode(d);break}case 2:{x.statusText=d.string();break}case 3:{x.addr=d.bytes();break}default:{d.skipType(C&7);break}}}return x},function*(d,m,g,x={}){let v=m==null?d.len:d.pos+m;for(;d.pos<v;){let C=d.uint32();switch(C>>>3){case 1:{yield{field:`${g}.status`,value:e.ResponseStatus.codec().decode(d)};break}case 2:{yield{field:`${g}.statusText`,value:d.string()};break}case 3:{yield{field:`${g}.addr`,value:d.bytes()};break}default:{d.skipType(C&7);break}}}})),p);function S(d){return Mt(d,f.codec())}f.encode=S;function E(d,m){return Ut(d,f.codec(),m)}f.decode=E;function w(d,m){return zt(d,f.codec(),m)}f.stream=w})(a=e.DialResponse||(e.DialResponse={}));let c;e.codec=()=>(c==null&&(c=Kt((f,p,S={})=>{S.lengthDelimited!==!1&&p.fork(),f.type!=null&&(p.uint32(8),e.MessageType.codec().encode(f.type,p)),f.dial!=null&&(p.uint32(18),e.Dial.codec().encode(f.dial,p)),f.dialResponse!=null&&(p.uint32(26),e.DialResponse.codec().encode(f.dialResponse,p)),S.lengthDelimited!==!1&&p.ldelim()},(f,p,S={})=>{let E={},w=p==null?f.len:f.pos+p;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{E.type=e.MessageType.codec().decode(f);break}case 2:{E.dial=e.Dial.codec().decode(f,f.uint32(),{limits:S.limits?.dial});break}case 3:{E.dialResponse=e.DialResponse.codec().decode(f,f.uint32(),{limits:S.limits?.dialResponse});break}default:{f.skipType(d&7);break}}}return E},function*(f,p,S,E={}){let w=p==null?f.len:f.pos+p;for(;f.pos<w;){let d=f.uint32();switch(d>>>3){case 1:{yield{field:`${S}.type`,value:e.MessageType.codec().decode(f)};break}case 2:{yield*e.Dial.codec().stream(f,f.uint32(),`${S}.dial`,{limits:E.limits?.dial});break}case 3:{yield*e.DialResponse.codec().stream(f,f.uint32(),`${S}.dialResponse`,{limits:E.limits?.dialResponse});break}default:{f.skipType(d&7);break}}}})),c);function u(f){return Mt(f,e.codec())}e.encode=u;function l(f,p){return Ut(f,e.codec(),p)}e.decode=l;function h(f,p){return zt(f,e.codec(),p)}e.stream=h})($||($={}));var wh=4,xh=8,Yn=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,r){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${r.protocolPrefix??zc}/${Kc}/${qc}`,this.timeout=r.timeout??3e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??20,this.connectionThreshold=r.connectionThreshold??80,this.maxMessageSize=r.maxMessageSize??8192,this.dialResults=Mc({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=Uc(this.findRandomPeers.bind(this),6e4),this.addressFilter=Ds(1024)}[Symbol.toStringTag]="@libp2p/autonat";[ai]=["@libp2p/autonat"];get[ci](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,r)=>{this.handleIncomingAutonatStream(t,r).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,r)=>{this.verifyExternalAddresses(r).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let r=jn([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:r})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:r})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,r){let n=AbortSignal.timeout(this.timeout);try{let o=ri(t,{maxDataLength:this.maxMessageSize}).pb($),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,r,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,r,n){let o=this.components.addressManager.getAddresses().map(h=>Lt(h).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.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:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let h=ce(a.id);i=In(h)}catch(h){return this.log.error("invalid PeerId - %e",h),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!r.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,r.remotePeer),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(h=>Nc(h)).filter(h=>{try{let f=Lt(h);return Ks(h)?!1:f.host!==Lt(r.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",h,r.remoteAddr),!1):o.includes(f.host)?!1:this.components.transportManager.dialTransportForMultiaddr(h)==null?(this.log.trace("not dialing %a - transport unsupported",h),!1):!0}catch{return!1}}).map(h=>(h.getComponents().find(f=>f.code===421)?.value==null&&(h=h.encapsulate(`/p2p/${i.toString()}`)),h));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(h=>h.toString()).join(", "),i);let u="",l=c[0];for(let h of c){let f;l=h;try{if(f=await this.components.connectionManager.openConnection(h,n),!f.remoteAddr.equals(h))throw this.log.error("tried to dial %a but dialed %a",h,f.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,h),{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.OK,addr:f.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),u=p.message}finally{f!=null&&await f.close()}}return{type:$.MessageType.DIAL_RESPONSE,dialResponse:{status:$.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:l.bytes}}}getFirstUnverifiedMultiaddr(t,r){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||Lt(o.multiaddr).type==="ip6"&&(!r||!yc(o.multiaddr))||Ks(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let 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:Is(),queue:new Zn({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:r})=>r<Date.now()).map(({multiaddr:r})=>r.toString()));for(let r of this.dialResults.keys())t.has(r)||(this.log.trace("remove results for %a",r),this.dialResults.delete(r))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>Lt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,r,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=ri(i).pb($),[,c]=await Promise.all([a.write({type:$.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==$.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!==$.ResponseStatus.OK&&u!==$.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(r)){this.log.trace("%a results included network segment %s",n.multiaddr,r);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(r),u===$.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===$.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===wh&&this.confirmAddress(o),o.failure===xh&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let r=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return r/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let r=Lt(t);switch(r.type){case"ip4":return r.host.split(".")[0].padStart(3,"0");case"ip6":return r.host.split(":")[0].padStart(4,"0");default:throw new ht(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function Eh(e={}){return t=>new Yn(t,e)}return Qc(Sh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|