@libp2p/webtransport 6.0.44-0d3ca9f0c → 6.0.44-3c9142a7c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PWebtransport = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PWebtransport=(()=>{var Gs=Object.defineProperty;var rl=Object.getOwnPropertyDescriptor;var nl=Object.getOwnPropertyNames;var sl=Object.prototype.hasOwnProperty;var Re=(t,e)=>{for(var r in e)Gs(t,r,{get:e[r],enumerable:!0})},ol=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of nl(e))!sl.call(t,s)&&s!==r&&Gs(t,s,{get:()=>e[s],enumerable:!(n=rl(e,s))||n.enumerable});return t};var il=t=>ol(Gs({},"__esModule",{value:!0}),t);var vm={};Re(vm,{webTransport:()=>Sm});var An=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},ir=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},se=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ot=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Bn=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Ln=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var yt=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Pt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var _n=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},Tn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Cn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Ut=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var In=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},ar=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Dn=class extends ar{constructor(e,r){super(!0,e,r)}},Rn=class extends ar{constructor(e,r){super(!1,e,r)}};var Zs=Symbol.for("@libp2p/peer-id");var Ha=Symbol.for("@libp2p/transport");var Fa;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(Fa||(Fa={}));function al(t){return typeof t?.handleEvent=="function"}function cl(t){return t===!0||t===!1}function ul(t){return cl(t)?t:t?.capture??!1}function Xs(t){let e={capture:ul(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function qa(t,e){return Xs(t).capture===Xs(e).capture}var cr=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let s=Xs(n);if(s?.signal?.aborted===!0)return;let o=u=>{s.once&&this.removeEventListener(e,r,s),al(r)?r.handleEvent(u):r(u)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(u=>u.callback!==r?!1:qa(u.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,r,s)};s.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:o,options:s,onAbort:c})}removeEventListener(e,r,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,s.filter(o=>o.callback===r&&qa(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var On=Symbol.for("@libp2p/service-capabilities");function be(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function fl(t){return t?.buffer instanceof ArrayBuffer}function Qs(t){if(fl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Me(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=Se(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return Qs(r)}function we(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var $a=Symbol.for("@achingbrain/uint8arraylist");function za(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let s=r+n.byteLength;if(e<s)return{buf:n,index:e-r};r=s}throw new RangeError("index is out of bounds")}function Pn(t){return!!t?.[$a]}var Q=class t{bufs;length;[$a]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Pn(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Pn(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(e){let r=za(this.bufs,e);return r.buf[r.index]}set(e,r){let n=za(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Pn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:s}=this._subList(e,r);return Me(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:Me(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Pn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let l=0;l<o;l++)i[l]=-1;for(let l=0;l<s;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){f=Math.max(1,d-a[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let s=be(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let s=be(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!we(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var no={};Re(no,{base10:()=>bl});var l0=new Uint8Array(0);function ja(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ke(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Nt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Nt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Wa(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Va=4096;function Ya(t){let e=t.length;if(e<=Va)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Va));return r}function ll(t){return t?.buffer instanceof ArrayBuffer}function Nt(t){return ll(t)?t:t.slice()}function hl(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),u!==a&&(n[u]=o)}}var f=t.length,l=t.charAt(0),d=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function g(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var E=0,w=0,A=0,L=x.length;A!==L&&x[A]===0;)A++,E++;for(var R=(L-A)*p+1>>>0,M=new Uint8Array(R);A!==L;){for(var U=x[A],I=0,D=R-1;(U!==0||I<w)&&D!==-1;D--,I++)U+=256*M[D]>>>0,M[D]=U%f>>>0,U=U/f>>>0;if(U!==0)throw new Error("Non-zero carry");w=I,A++}for(var F=R-w;F!==R&&M[F]===0;)F++;for(var K=l.repeat(E);F<R;++F)K+=t.charAt(M[F]);return K}function b(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var E=0;if(x[E]!==" "){for(var w=0,A=0;x[E]===l;)w++,E++;for(var L=(x.length-E)*d+1>>>0,R=new Uint8Array(L);x[E];){var M=n[x.charCodeAt(E)];if(M===255)return;for(var U=0,I=L-1;(M!==0||U<A)&&I!==-1;I--,U++)M+=f*R[I]>>>0,R[I]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");A=U,E++}if(x[E]!==" "){for(var D=L-A;D!==L&&R[D]===0;)D++;for(var F=new Uint8Array(w+(L-D)),K=w;D!==L;)F[K++]=R[D++];return F}}}function m(x){var E=b(x);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:g,decodeUnsafe:b,decode:m}}var dl=hl,pl=dl,Za=pl;var Js=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},eo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xa(this,e)}},to=class{decoders;constructor(e){this.decoders=e}or(e){return Xa(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xa(t,e){return new to({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ro=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new Js(e,r,n),this.decoder=new eo(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ur({name:t,prefix:e,encode:r,decode:n}){return new ro(t,e,r,n)}function gt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=Za(r,t,n);return ur({prefix:e,name:t,encode:s,decode:i=>Ke(o(i))})}function ml(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function yl(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function gl(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let s=t[n].toLowerCase(),o=t[n].toUpperCase();s!==t[n]&&(r[s]=n),o!==t[n]&&(r[o]=n)}return r}function pe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=gl(n,s);return ur({prefix:e,name:t,encode(i){return yl(i,n,r)},decode(i){return ml(i,o,r,t)}})}var bl=gt({prefix:"9",name:"base10",alphabet:"0123456789"});var so={};Re(so,{base16:()=>wl,base16upper:()=>xl});var wl=pe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),xl=pe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var oo={};Re(oo,{base2:()=>El});var El=pe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var io={};Re(io,{base256emoji:()=>Ll});var Qa=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}"),Sl=Qa.reduce((t,e,r)=>(t[r]=e,t),[]),vl=Qa.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Al(t){return t.reduce((e,r)=>(e+=Sl[r],e),"")}function Bl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=vl[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var Ll=ur({prefix:"\u{1F680}",name:"base256emoji",encode:Al,decode:Bl});var ao={};Re(ao,{base32:()=>bt,base32hex:()=>Il,base32hexpad:()=>Rl,base32hexpadupper:()=>Ol,base32hexupper:()=>Dl,base32pad:()=>Tl,base32padupper:()=>Cl,base32upper:()=>_l,base32z:()=>Pl});var bt=pe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),_l=pe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Tl=pe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Cl=pe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Il=pe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Dl=pe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Rl=pe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Ol=pe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Pl=pe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var co={};Re(co,{base36:()=>kr,base36upper:()=>Ul});var kr=gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Ul=gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var uo={};Re(uo,{base58btc:()=>me,base58flickr:()=>Nl});var me=gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nl=gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lo={};Re(lo,{base64:()=>kl,base64pad:()=>Ml,base64url:()=>fo,base64urlpad:()=>Kl});var kl=pe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ml=pe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fo=pe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kl=pe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ho={};Re(ho,{base8:()=>Fl});var Fl=pe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var po={};Re(po,{identity:()=>Hl});var Hl=ur({prefix:"\0",name:"identity",encode:t=>Ya(Ke(t)),decode:t=>Ke(Wa(t))});var _0=new TextEncoder,T0=new TextDecoder;var go={};Re(go,{identity:()=>je});var ot={};Re(ot,{Digest:()=>kt,create:()=>Ve,decode:()=>hr,equals:()=>yo,hasCode:()=>ch});var $l=tc,Ja=128,Vl=127,jl=~Vl,Wl=Math.pow(2,31);function tc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Wl;)e[r++]=t&255|Ja,t/=128;for(;t&jl;)e[r++]=t&255|Ja,t>>>=7;return e[r]=t|0,tc.bytes=r-n+1,e}var Yl=mo,Gl=128,ec=127;function mo(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw mo.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&ec)<<s:(i&ec)*Math.pow(2,s),s+=7}while(i>=Gl);return mo.bytes=o-n,r}var Zl=Math.pow(2,7),Xl=Math.pow(2,14),Ql=Math.pow(2,21),Jl=Math.pow(2,28),eh=Math.pow(2,35),th=Math.pow(2,42),rh=Math.pow(2,49),nh=Math.pow(2,56),sh=Math.pow(2,63),oh=function(t){return t<Zl?1:t<Xl?2:t<Ql?3:t<Jl?4:t<eh?5:t<th?6:t<rh?7:t<nh?8:t<sh?9:10},ih={encode:$l,decode:Yl,encodingLength:oh},ah=ih,Mr=ah;function Kr(t,e=0){let r=Mr.decode(t,e),n=Mr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function fr(t,e,r=0){return Mr.encode(t,e,r),e}function lr(t){return Mr.encodingLength(t)}function Ve(t,e){let r=e.byteLength,n=lr(t),s=n+lr(r),o=new Uint8Array(s+r);return fr(t,o,0),fr(r,o,n),o.set(e,s),new kt(t,r,e,o)}function hr(t){let e=Ke(t),[r,n]=Kr(e),[s,o]=Kr(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new kt(r,s,i,e)}function yo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ja(t.bytes,r.bytes)}}var kt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=Nt(n),this.bytes=Nt(s)}};function ch(t,e){return t.code===e}var rc=0,uh="identity",nc=Ke;function fh(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ve(rc,nc(t))}var je={code:rc,name:uh,encode:nc,digest:fh};var xo={};Re(xo,{sha256:()=>Fr,sha512:()=>hh});var lh=20;function wo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new bo(t,e,r,n,s)}var bo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??lh,this.maxDigestLength=o}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?sc(n,this.code,r?.truncate):n.then(s=>sc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function sc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ve(e,t)}function ic(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Fr=wo({name:"sha2-256",code:18,encode:ic("SHA-256")}),hh=wo({name:"sha2-512",code:19,encode:ic("SHA-512")});function ac(t,e){let{bytes:r,version:n}=t;return n===0?ph(r,Eo(t),e??me.encoder):mh(r,Eo(t),e??bt.encoder)}var cc=new WeakMap;function Eo(t){let e=cc.get(t);if(e==null){let r=new Map;return cc.set(t,r),r}return e}var xe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=Nt(s),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:e,multihash:r}=this;if(e!==Hr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==yh)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=Ve(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&yo(e.multihash,n.multihash)}toString(e){return ac(this,e)}toJSON(){return{"/":ac(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new t(n,s,o,i??uc(n,s,o.bytes))}else if(r[gh]===!0){let{version:n,multihash:s,code:o}=r,i=hr(s);return t.create(n,o,i)}else return null}static create(e,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(e){case 0:{if(r!==Hr)throw new Error(`Version 0 CID must use dag-pb (code: ${Hr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=uc(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Hr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Ke(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new kt(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,d]=Kr(e.subarray(r));return r+=d,l},s=n(),o=Hr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,s]=dh(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Eo(o).set(n,e),o}};function dh(t,e){switch(t[0]){case"Q":{let r=e??me;return[me.prefix,r.decode(`${me.prefix}${t}`)]}case me.prefix:{let r=e??me;return[me.prefix,r.decode(t)]}case bt.prefix:{let r=e??bt;return[bt.prefix,r.decode(t)]}case kr.prefix:{let r=e??kr;return[kr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function ph(t,e,r){let{prefix:n}=r;if(n!==me.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function mh(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var Hr=112,yh=18;function uc(t,e,r){let n=lr(t),s=n+lr(e),o=new Uint8Array(s+r.byteLength);return fr(t,o,0),fr(e,o,n),o.set(r,s),o}var gh=Symbol.for("@ipld/js-cid/CID");var Mt={...po,...oo,...ho,...no,...so,...ao,...co,...uo,...lo,...io},Z0={...xo,...go};function lc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var fc=lc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),So=lc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),bh={utf8:fc,"utf-8":fc,hex:Mt.base16,latin1:So,ascii:So,binary:So,...Mt},Nn=bh;function ee(t,e="utf8"){let r=Nn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function wh(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function hc(t){let e=wh(t);if(e==null)throw new se(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var kn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();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(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(f===void 0)break;if(o*=e,o+=f,o>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let s=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[s]=i[0],r[s+1]=i[1],r[s+2]=i[2],r[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];r[s]=o>>8,r[s+1]=o&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,s]=e(r);if(n===16)return r;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=e(o.subarray(0,i));return r.set(o.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var xh=45,Eh=15,Mn=new kn;function dc(t){if(!(t.length>Eh))return Mn.new(t).parseWith(()=>Mn.readIPv4Addr())}function pc(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>xh))return Mn.new(t).parseWith(()=>Mn.readIPv6Addr())}function Kn(t){return!!dc(t)}function mc(t){return!!pc(t)}var Sh=Math.pow(2,7),vh=Math.pow(2,14),Ah=Math.pow(2,21),vo=Math.pow(2,28),Ao=Math.pow(2,35),Bo=Math.pow(2,42),Lo=Math.pow(2,49),te=128,_e=127;function Te(t){if(t<Sh)return 1;if(t<vh)return 2;if(t<Ah)return 3;if(t<vo)return 4;if(t<Ao)return 5;if(t<Bo)return 6;if(t<Lo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function dr(t,e,r=0){switch(Te(t)){case 8:e[r++]=t&255|te,t/=128;case 7:e[r++]=t&255|te,t/=128;case 6:e[r++]=t&255|te,t/=128;case 5:e[r++]=t&255|te,t/=128;case 4:e[r++]=t&255|te,t>>>=7;case 3:e[r++]=t&255|te,t>>>=7;case 2:e[r++]=t&255|te,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Bh(t,e,r=0){switch(Te(t)){case 8:e.set(r++,t&255|te),t/=128;case 7:e.set(r++,t&255|te),t/=128;case 6:e.set(r++,t&255|te),t/=128;case 5:e.set(r++,t&255|te),t/=128;case 4:e.set(r++,t&255|te),t>>>=7;case 3:e.set(r++,t&255|te),t>>>=7;case 2:e.set(r++,t&255|te),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function _o(t,e){let r=t[e],n=0;if(n+=r&_e,r<te||(r=t[e+1],n+=(r&_e)<<7,r<te)||(r=t[e+2],n+=(r&_e)<<14,r<te)||(r=t[e+3],n+=(r&_e)<<21,r<te)||(r=t[e+4],n+=(r&_e)*vo,r<te)||(r=t[e+5],n+=(r&_e)*Ao,r<te)||(r=t[e+6],n+=(r&_e)*Bo,r<te)||(r=t[e+7],n+=(r&_e)*Lo,r<te))return n;throw new RangeError("Could not decode varint")}function Lh(t,e){let r=t.get(e),n=0;if(n+=r&_e,r<te||(r=t.get(e+1),n+=(r&_e)<<7,r<te)||(r=t.get(e+2),n+=(r&_e)<<14,r<te)||(r=t.get(e+3),n+=(r&_e)<<21,r<te)||(r=t.get(e+4),n+=(r&_e)*vo,r<te)||(r=t.get(e+5),n+=(r&_e)*Ao,r<te)||(r=t.get(e+6),n+=(r&_e)*Bo,r<te)||(r=t.get(e+7),n+=(r&_e)*Lo,r<te))return n;throw new RangeError("Could not decode varint")}function yc(t,e,r=0){return e==null&&(e=Se(Te(t))),e instanceof Uint8Array?dr(t,e,r):Bh(t,e,r)}function Kt(t,e=0){return t instanceof Uint8Array?_o(t,e):Lh(t,e)}function _h(t){return t.buffer instanceof ArrayBuffer}function Ae(t){return _h(t)?t:t.slice()}function W(t,e="utf8"){let r=Nn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},it=class extends Error{static name="ValidationError";name="ValidationError"},Fn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Hn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Io(t){return e=>W(e,t)}function Do(t){return e=>ee(e,t)}function pr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ft(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function gc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=ee(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Ft(n);return Me([r,s],r.length+s.length)}function bc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=bt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Ft(n);return Me([r,s],r.length+s.length)}function Ro(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=W(e,"base32"),s=pr(r);return`${n}:${s}`}var Oo=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let s=parseInt(r,10);if(isNaN(s)||s<0||s>255)throw new Be("Invalid byte value in IP address");e[n]=s}),e},wc=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let o=Kn(r[n]),i;o&&(i=Oo(r[n]),r[n]=W(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,W(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 o=[n,1];for(n=9-r.length;n>0;n--)o.push("0");r.splice.apply(r,o)}let s=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let o=parseInt(r[n],16);if(isNaN(o)||o<0||o>65535)throw new Be("Invalid byte value in IP address");s[e++]=o>>8&255,s[e++]=o&255}return s},xc=function(t){if(t.byteLength!==4)throw new Be("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Ec=function(t){if(t.byteLength!==16)throw new Be("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let s=t[n],o=t[n+1],i=`${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Be(`Invalid IPv6 address "${r}"`)}};function Sc(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Be(`Invalid IPv6 address "${t}"`)}}var Co=Object.values(Mt).map(t=>t.decoder),Th=(function(){let t=Co[0].or(Co[1]);return Co.slice(2).forEach(e=>t=t.or(e)),t})();function vc(t){return Th.decode(t)}function Ac(t){return e=>t.encoder.encode(e)}function Ch(t){if(parseInt(t).toString()!==t)throw new it("Value must be an integer")}function Ih(t){if(t<0)throw new it("Value must be a positive integer, or zero")}function Dh(t){return e=>{if(e>t)throw new it(`Value must be smaller than or equal to ${t}`)}}function Rh(...t){return e=>{for(let r of t)r(e)}}var qr=Rh(Ch,Ih,Dh(65535));var ve=-1,Po=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Hn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ct=new Po,jh=[{code:4,name:"ip4",size:32,valueToBytes:Oo,bytesToValue:xc,validate:t=>{if(!Kn(t))throw new it(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ft,bytesToValue:pr,validate:qr},{code:273,name:"udp",size:16,valueToBytes:Ft,bytesToValue:pr,validate:qr},{code:33,name:"dccp",size:16,valueToBytes:Ft,bytesToValue:pr,validate:qr},{code:41,name:"ip6",size:128,valueToBytes:wc,bytesToValue:Ec,stringToValue:Sc,validate:t=>{if(!mc(t))throw new it(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ve},{code:43,name:"ipcidr",size:8,bytesToValue:Io("base10"),valueToBytes:Do("base10")},{code:53,name:"dns",size:ve},{code:54,name:"dns4",size:ve},{code:55,name:"dns6",size:ve},{code:56,name:"dnsaddr",size:ve},{code:132,name:"sctp",size:16,valueToBytes:Ft,bytesToValue:pr,validate:qr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ve,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:ve,bytesToValue:Io("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?Do("base58btc")(t):xe.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ro,valueToBytes:gc},{code:445,name:"onion3",size:296,bytesToValue:Ro,valueToBytes:bc},{code:446,name:"garlic64",size:ve},{code:447,name:"garlic32",size:ve},{code:448,name:"tls"},{code:449,name:"sni",size:ve},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ve,bytesToValue:Ac(fo),valueToBytes:vc},{code:480,name:"http"},{code:481,name:"http-path",size:ve,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.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:ve}];jh.forEach(t=>{ct.addProtocol(t)});function Bc(t){let e=[],r=0;for(;r<t.length;){let n=Kt(t,r),s=ct.getProtocol(n),o=Te(n),i=Wh(s,t,r+o),a=0;i>0&&s.size===ve&&(a=Te(i));let c=o+a+i,u={code:n,name:s.name,bytes:Ae(t.subarray(r,r+c))};if(i>0){let f=r+o+a,l=t.subarray(f,f+i);u.value=s.bytesToValue?.(l)??W(l)}e.push(u),r+=c}return e}function Lc(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let s=ct.getProtocol(n.code),o=Te(n.code),i,a=0,c=0;n.value!=null&&(i=s.valueToBytes?.(n.value)??ee(n.value),a=i.byteLength,s.size===ve&&(c=Te(a)));let u=new Uint8Array(o+c+a),f=0;dr(n.code,u,f),f+=o,i!=null&&(s.size===ve&&(dr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Me(r,e)}function _c(t){if(t.charAt(0)!=="/")throw new Be('String multiaddr must start with "/"');let e=[],r="protocol",n="",s="";for(let o=1;o<t.length;o++){let i=t.charAt(o);i!=="/"&&(r==="protocol"?s+=t.charAt(o):n+=t.charAt(o));let a=o===t.length-1;if(i==="/"||a){let c=ct.getProtocol(s);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",s="",r="protocol";continue}else if(a)throw new Be(`Component ${s} 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 Be(`Component ${s} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",s="",r="protocol"}}}if(s!==""&&n!=="")throw new Be("Incomplete multiaddr");return e}function Tc(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ct.getProtocol(e.code);if(r==null)throw new Be(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Wh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Kt(e,r)}var Yh=Symbol.for("nodejs.util.inspect.custom"),Qo=Symbol.for("@multiformats/multiaddr");function Gh(t){if(t==null&&(t="/"),Cc(t))return t.getComponents();if(t instanceof Uint8Array)return Bc(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),_c(t);if(Array.isArray(t))return t;throw new Be("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Xo=class t{[Qo]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Gh(e),r.validate!==!1&&Zh(this)}get bytes(){return this.#r==null&&(this.#r=Lc(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Tc(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),s=n.lastIndexOf(r);if(s<0)throw new Fn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,s),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return we(this.bytes,e.bytes)}[Yh](){return`Multiaddr(${this.toString()})`}};function Zh(t){t.getComponents().forEach(e=>{let r=ct.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Cc(t){return!!t?.[Qo]}var ue=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),V=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Ic=t=>({match:e=>t.match(e)===!1?e:!1}),G=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Ce=(...t)=>({match:e=>{let r;for(let n of t){let s=n.match(e);s!==!1&&(r==null||s.length<r.length)&&(r=s)}return r??!1}}),J=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function fe(...t){function e(s){if(s==null)return!1;let o=s.getComponents();for(let i of t){let a=i.match(o);if(a===!1)return!1;o=a}return o}function r(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matchers:t,matches:r,exactMatch:n}}var Xh=V(421),wg=fe(Xh),Yn=V(54),Gn=V(55),Zn=V(56),ei=V(53),xg=fe(Yn,G(V(421))),Eg=fe(Gn,G(V(421))),Sg=fe(Zn,G(V(421))),vg=fe(Ce(ei,Zn,Yn,Gn),G(V(421))),Dc=J(V(4),G(V(43))),Rc=J(G(V(42)),V(41),G(V(43))),ti=Ce(Dc,Rc),br=Ce(ti,ei,Yn,Gn,Zn),Ag=fe(Ce(ti,J(Ce(ei,Zn,Yn,Gn),G(V(421))))),Bg=fe(Dc),Lg=fe(Rc),_g=fe(ti),ri=J(br,V(6)),zr=J(br,V(273)),Tg=fe(J(ri,G(V(421)))),Cg=fe(zr),ni=J(zr,ue(460),G(V(421))),Xn=J(zr,ue(461),G(V(421))),Qh=Ce(ni,Xn),Ig=fe(ni),Dg=fe(Xn),Jo=Ce(br,ri,zr,ni,Xn),Oc=Ce(J(Jo,ue(477),G(V(421)))),Rg=fe(Oc),Pc=Ce(J(Jo,ue(478),G(V(421))),J(Jo,ue(448),G(V(449)),ue(477),G(V(421)))),Og=fe(Pc),Uc=J(zr,ue(280),G(V(466)),G(V(466)),G(V(421))),Pg=fe(Uc),Nc=J(Xn,ue(465),G(V(466)),G(V(466)),G(V(421))),Qn=fe(Nc),Wn=Ce(Oc,Pc,J(ri,G(V(421))),J(Qh,G(V(421))),J(br,G(V(421))),Uc,Nc,V(421)),Ug=fe(Wn),Jh=J(G(Wn),ue(290),Ic(ue(281)),G(V(421))),Ng=fe(Jh),ed=Ce(J(Wn,ue(290),ue(281),G(V(421))),J(Wn,ue(281),G(V(421))),J(ue(281),G(V(421)))),kg=fe(ed),td=J(br,Ce(J(V(6,"80")),J(V(6),ue(480)),ue(480)),G(V(481)),G(V(421))),Mg=fe(td),rd=J(br,Ce(J(V(6,"443")),J(V(6,"443"),ue(480)),J(V(6),ue(443)),J(V(6),ue(448),ue(480)),J(ue(448),ue(480)),ue(448),ue(443)),G(V(481)),G(V(421))),Kg=fe(rd),nd=Ce(J(V(777),G(V(421)))),Fg=fe(nd),sd=Ce(J(V(400),G(V(421)))),Hg=fe(sd);function Jn(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var es=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},wr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new es(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new es(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var si=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ts(t={}){return od(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}},t)}function od(t,e){e=e??{};let r=e.onEnd,n=new wr,s,o,i,a=Jn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,x)=>{o=E=>{o=null,n.push(E);try{m(t(n))}catch(w){x(w)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Jn()})}},u=m=>o!=null?o(m):(n.push(m),s),f=m=>(n=new wr,o!=null?o({error:m}):(n.push({error:m}),s)),l=m=>{if(i)return s;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:m})},d=m=>i?s:(i=!0,m!=null?f(m):u({done:!0})),p=()=>(n=new wr,d(),{done:!0}),g=m=>(d(m),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:p,throw:g,push:l,end:d,get readableLength(){return n.size},onEmpty:async m=>{let x=m?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,w;x!=null&&(E=new Promise((A,L)=>{w=()=>{L(new si)},x.addEventListener("abort",w)}));try{await Promise.race([a.promise,E])}finally{w!=null&&x!=null&&x?.removeEventListener("abort",w)}}},r==null)return s;let b=s;return s={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(m){return b.throw(m),r!=null&&(r(m),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(m){return b.end(m),r!=null&&(r(m),r=void 0),s},get readableLength(){return b.readableLength},onEmpty:m=>b.onEmpty(m)},s}var oi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},kc=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function ii(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){d(kc(i)),t.then(l,d);return}if(i&&(c=()=>{d(kc(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,d),r===Number.POSITIVE_INFINITY)return;let p=new oi;a=o.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(g){d(g)}return}typeof t.cancel=="function"&&t.cancel(),s===!1?l():s instanceof Error?d(s):(p.message=s??`Promise timed out after ${r} milliseconds`,d(p))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var Mc=t=>typeof t=="function"?{filter:t}:{...t},id=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,ad=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],cd=t=>{for(let[e,r]of ad){let n=t?.[e],s=t?.[r];if(typeof n=="function"&&typeof s=="function")return{addListener:n.bind(t),removeListener:s.bind(t)}}throw new TypeError("Emitter is not compatible")},ud=t=>{let e=new Map;for(let[r,n]of t)for(let s of Array.isArray(r)?r:[r])e.has(s)||e.set(s,n);return e},fd=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:s,isDone:o})=>{n?.addEventListener("abort",s,{once:!0});for(let[i,a]of r)if(t(i,a),o()){e(i,a);return}},ld=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[s,o]of e)t(s,o);r?.removeEventListener("abort",n)},hd=(t,e,r)=>{let n=Promise.resolve();return(s,o)=>{n=n.then(async()=>{if(e())return;let i;try{i=t?await t(s):!0}catch(a){e()||r(a);return}e()||o(i)})}};function dd(t,e,r){let n=()=>{},s=!1,o,i=new Promise((a,c)=>{r=Mc(r);let{filter:u}=r;if(!id(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:l}=cd(t);if(r.count===0){a([]);return}let d=[],p=A=>{n(),c(A)},g=hd(u,()=>s,p),b=A=>{d.push(A),r.count===d.length&&(n(),a(d))},m=(...A)=>{if(s)return;let L=r.multiArgs?A:A[0];if(!u){b(L);return}g(L,R=>{R&&b(L)})},x=(...A)=>{p(r.rejectionMultiArgs?A:A[0])},E=()=>{p(r.signal.reason)},w={addListener:f,removeListener:l,handlers:ud([[e,m],[r.rejectionEvents??["error"],x]]),signal:r.signal,abortHandler:E,isDone:()=>s};n=()=>{s=!0,clearTimeout(o),ld(w)},fd(w),!(s||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&(o=setTimeout(n,r.timeout)),a(d))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=ii(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function wt(t,e,r){let n=dd(t,e,{...Mc(r),count:1,resolveImmediately:!1}),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var qt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},rs=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},ns=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function pd(t){return t.reason}function Fe(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??pd;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let s;return Promise.race([t,new Promise((o,i)=>{s=()=>{i(n(e))},e.addEventListener("abort",s)})]).finally(()=>{s!=null&&e.removeEventListener("abort",s)})}var md=Math.pow(2,20)*4,Xe=class extends cr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;#t;#r=new Set;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??md,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new Q,this.writeBuffer=new Q,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=s=>{this.onDrainPromise?.reject(s.error??new ns)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Fe(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){let e=ts(),r,n=o=>{e.push(o.data)};this.addEventListener("message",n);let s=()=>{this.#r.delete(s),this.removeEventListener("message",n),r=this.#t,e.end()};this.#r.add(s),this.readableDone()&&s();try{if(yield*e,r!=null)throw r}finally{this.removeEventListener("message",n),this.#r.delete(s)}}readableDone(){return this.readBuffer.byteLength===0&&(this.remoteWriteStatus==="closed"||this.readStatus==="closing"||this.readStatus==="closed")}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new yt(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(this.status==="aborted"||this.status==="reset"||this.status==="closed"){this.readBuffer.byteLength>0&&(this.#t??=e,this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closed",this.maybeDispatchEnd());return}this.log.error("abort with error - %e",e),this.status="aborted",this.#t=e,this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(r){this.log.error("failed to send reset to remote - %e",r)}this.dispatchEvent(new Dn(e))}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){if(this.status==="aborted"||this.status==="reset"||this.status==="closed")return;this.log("remote reset");let e=new Ln;this.#t=e,this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new Rn(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.maybeDispatchEnd(),this.dispatchEvent(new ar))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),i=new Q(o);this.writeBuffer.consume(o.byteLength);let a;try{a=this.sendData(o)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}maybeDispatchEnd(){this.readableDone()&&(this.#r.forEach(e=>{e()}),!this.#e&&(this.#e=!0,this.safeDispatchEvent("end")))}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new In(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed",this.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Pt(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new Pt(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var ss=class extends Xe{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await wt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await wt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Kc(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var os=class extends cr{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let s=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",s);let o=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",o)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await Fe(Promise.all([...this.streams].map(async r=>{await r.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(r=>{r.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(r=>{r.onTransportClosed(e)})}catch(r){this.abort(r)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new Bn;let r=this.onCreateStream({...this.streamOptions,...e});return Kc(r)&&(r=await r),this.streams.push(r),this.cleanUpStream(r),r}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new rs(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let r=n=>{let s=this.streams.findIndex(o=>o===e);s!==-1&&this.streams.splice(s,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",r),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(r=>{this.safeDispatchEvent("stream",{detail:r})}),this.earlyStreams=[]})}};var is=class extends Xe{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await wt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await wt(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){if(!(this.readStatus==="closing"||this.readStatus==="closed")){this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",this.maybeDispatchEnd();try{await this.sendCloseRead(e)}catch(r){throw this.log.error("failed to close readable end - %e",r),r}finally{this.readStatus="closed"}this.log("closed readable end gracefully")}}};var yd=4194304,as=class extends Error{static name="UnwrappedError";name="UnwrappedError"},$r=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ci=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ui=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function gd(t){return typeof t?.closeRead=="function"}function bd(t){return typeof t?.close=="function"}function ai(t){return gd(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:bd(t)?t.status!=="open":!1}function wd(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function xd(t,e){let r=e?.maxBufferSize??yd,n=new Q,s,o=!1,i;if(!wd(t))throw new se("Argument should be a Stream or a Multiaddr");let a=l=>{if(!o&&i==null){if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(d);let p=new Pt(`Read buffer overflow - ${d} > ${r}`);i=p,s?.reject(p),queueMicrotask(()=>{t.abort(p)});return}s?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?s?.reject(l.error):s?.resolve()};t.addEventListener("close",c);let u=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(o===!0)throw new as("Stream was unwrapped");if(i!=null)throw i;if(ai(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new qt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=d){s.resolve();break}if(await Fe(s.promise,l?.signal),ai(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}s=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(ai(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new qt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let g=n.sublist(0,p);return n.consume(p),g},async write(l,d){if(o===!0)throw new as("Stream was unwrapped");t.send(l)||await wt(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return f}function fi(t,e={}){let r=xd(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Te(e.maxDataLength));let n=e?.lengthDecoder??Kt,s=e?.lengthEncoder??yc;return{async read(i){let a=-1,c=new Q;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new $r("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ui(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ci(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new qt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new qt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new Q(s(i.byteLength),i),a)},async writeV(i,a){let c=new Q(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var Ed=1024*1024*4,Sd=1024*1024*4,cs=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new Q,this.maxBufferSize=e.maxBufferSize??Ed,this.maxDataLength=e.maxDataLength??Sd,this.lengthDecoder=e.lengthDecoder??Kt,this.encodingLength=e.encodingLength??Te}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new se(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(o){if(o instanceof RangeError)break;throw o}if(r<0||r>this.maxDataLength)throw new $r("Invalid message length");let n=this.encodingLength(r),s=n+r;if(this.buffer.byteLength>=s){let o=this.buffer.sublist(n,s);this.buffer.consume(s),o.byteLength>0&&(yield o)}else break}}};var xr=!!globalThis.process?.env?.DUMP_SESSION_KEYS,li=16;function hi(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var us=t=>t?`"${t}" `:"";function fs(t,e=""){if(typeof t!="boolean")throw new TypeError(us(e)+"expected boolean, got type="+typeof t);return t}function zt(t,e=""){if(typeof t!="number")throw new TypeError(us(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(us(e)+"expected integer >= 0, got "+t);return t}function ge(t,e,r=""){if(hi(t)&&(e===void 0||t.length===e))return t;e!==void 0&&zt(e,"length");let n=hi(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=us(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}var Fc=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`)};function di(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Hc(t,e){ge(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Qe(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function We(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function vd(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var xt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ad(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Bd(t){for(let e=0;e<t.length;e++)t[e]=Ad(t[e]);return t}var ut=xt?t=>t:Bd;function Ld(t,e){return!t.byteLength||!e.byteLength?!1:t.buffer===e.buffer&&t.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<t.byteOffset+t.byteLength}function qc(t,e){if(Ld(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function zc(t,e){return Fc(t,"defaults"),Fc(e,"opts"),Object.assign(t,e)}function $c(t,e){if(t=ge(t),e=ge(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Vc(t,e,r){let n=e,s=r||(()=>[]),o=(a,c)=>n(c,...s(a)).update(a).digest(),i=n(new Uint8Array(t),...s(new Uint8Array(0)));return o.outputLen=i.outputLen,o.blockLen=i.blockLen,o.create=(a,...c)=>n(a,...c),o}var jc=(t,e)=>{function r(n,...s){if(ge(n,void 0,"key"),t.nonceLength!==void 0){let l=s[0];ge(l,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let o=t.tagLength,i=t.nonceLength!==void 0?1:0;if(!t.withAAD){for(let l=i;l<s.length;l++)if(hi(s[l]))throw new Error("AAD not supported")}t.withAAD&&s[i]!==void 0&&ge(s[i],void 0,"AAD");let a=e(n,...s),c=(l,d)=>{if(d!==void 0){if(l!==2)throw new Error("cipher output not supported");ge(d,void 0,"output")}},u=!1;return{encrypt(l,d){if(u)throw new Error("cannot encrypt() twice with same key + nonce");return u=!0,ge(l,void 0,"data"),c(a.encrypt.length,d),a.encrypt(l,d)},decrypt(l,d){if(ge(l,void 0,"data"),o&&l.length<o)throw new Error('"ciphertext" expected length >= tagLength='+o);return c(a.decrypt.length,d),a.decrypt(l,d)}}}return Object.assign(r,t),r};function Vr(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(ge(e,t,"output"),r&&!jr(e))throw new Error("invalid output, must be aligned");return e}function Wc(t,e,r){zt(t),zt(e),fs(r);let n=new Uint8Array(16),s=vd(n);return s.setBigUint64(0,BigInt(e),r),s.setBigUint64(8,BigInt(t),r),n}function jr(t){return t.byteOffset%4===0}function Er(t){return Uint8Array.from(ge(t))}var Gc=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),_d=ut(Qe(Gc("expand 16-byte k"))),Td=ut(Qe(Gc("expand 32-byte k")));function X(t,e){return t<<e|t>>>32-e}var Wr=64,Cd=16,pi=2**32-1,Yc=Uint32Array.of();function Id(t,e,r,n,s,o,i,a){let c=s.length,u=new Uint8Array(Wr),f=Qe(u),l=xt&&jr(s)&&jr(o),d=l?Qe(s):Yc,p=l?Qe(o):Yc;if(!xt){for(let g=0;g<c;i++){if(t(e,r,n,f,i,a),ut(f),i>=pi)throw new Error("arx: counter overflow");let b=Math.min(Wr,c-g);for(let m=0,x;m<b;m++)x=g+m,o[x]=s[x]^u[m];g+=b}return}for(let g=0;g<c;i++){if(t(e,r,n,f,i,a),i>=pi)throw new Error("arx: counter overflow");let b=Math.min(Wr,c-g);if(l&&b===Wr){let m=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let x=0,E;x<Cd;x++)E=m+x,p[E]=d[E]^f[x];g+=Wr;continue}for(let m=0,x;m<b;m++)x=g+m,o[x]=s[x]^u[m];g+=b}}function Zc(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=zc({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return zt(s),zt(i),fs(o),fs(r),(a,c,u,f,l=0)=>{ge(a,void 0,"key"),ge(c,void 0,"nonce"),ge(u,void 0,"data");let d=u.length,p=f!==void 0;if(f=Vr(d,f,!1),p&&qc(u,f),zt(l),l<0||l>=pi)throw new Error("arx: counter overflow");let g=[],b=a.length,m,x;if(b===32)g.push(m=Er(a)),x=Td;else if(b===16&&r)m=new Uint8Array(32),m.set(a),m.set(a,16),x=_d,g.push(m);else throw ge(a,32,"arx key"),new Error("invalid key size");(!xt||!jr(c))&&g.push(c=Er(c));let E=Qe(m);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let L=c.subarray(0,16);if(xt)n(x,E,Qe(L),E);else{let R=ut(Uint32Array.from(x));n(R,E,Qe(L),E),We(R),ut(E)}c=c.subarray(16)}else xt||ut(E);let w=16-s;if(w!==c.length)throw new Error(`arx: nonce must be ${w} or 16 bytes`);if(w!==12){let L=new Uint8Array(12);L.set(c,o?0:12-c.length),c=L,g.push(c)}let A=ut(Qe(c));try{return Id(t,x,E,A,u,f,l,i),f}finally{We(...g)}}}function Le(t,e){return t[e++]&255|(t[e++]&255)<<8}var mi=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=Er(ge(e,32,"key"));let r=Le(e,0),n=Le(e,2),s=Le(e,4),o=Le(e,6),i=Le(e,8),a=Le(e,10),c=Le(e,12),u=Le(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=Le(e,16+2*f)}process(e,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],f=i[3],l=i[4],d=i[5],p=i[6],g=i[7],b=i[8],m=i[9],x=Le(e,r+0),E=Le(e,r+2),w=Le(e,r+4),A=Le(e,r+6),L=Le(e,r+8),R=Le(e,r+10),M=Le(e,r+12),U=Le(e,r+14),I=o[0]+(x&8191),D=o[1]+((x>>>13|E<<3)&8191),F=o[2]+((E>>>10|w<<6)&8191),K=o[3]+((w>>>7|A<<9)&8191),$=o[4]+((A>>>4|L<<12)&8191),_=o[5]+(L>>>1&8191),P=o[6]+((L>>>14|R<<2)&8191),T=o[7]+((R>>>11|M<<5)&8191),B=o[8]+((M>>>8|U<<8)&8191),H=o[9]+(U>>>5|s),C=0,S=C+I*a+D*(5*m)+F*(5*b)+K*(5*g)+$*(5*p);C=S>>>13,S&=8191,S+=_*(5*d)+P*(5*l)+T*(5*f)+B*(5*u)+H*(5*c),C+=S>>>13,S&=8191;let h=C+I*c+D*a+F*(5*m)+K*(5*b)+$*(5*g);C=h>>>13,h&=8191,h+=_*(5*p)+P*(5*d)+T*(5*l)+B*(5*f)+H*(5*u),C+=h>>>13,h&=8191;let y=C+I*u+D*c+F*a+K*(5*m)+$*(5*b);C=y>>>13,y&=8191,y+=_*(5*g)+P*(5*p)+T*(5*d)+B*(5*l)+H*(5*f),C+=y>>>13,y&=8191;let v=C+I*f+D*u+F*c+K*a+$*(5*m);C=v>>>13,v&=8191,v+=_*(5*b)+P*(5*g)+T*(5*p)+B*(5*d)+H*(5*l),C+=v>>>13,v&=8191;let O=C+I*l+D*f+F*u+K*c+$*a;C=O>>>13,O&=8191,O+=_*(5*m)+P*(5*b)+T*(5*g)+B*(5*p)+H*(5*d),C+=O>>>13,O&=8191;let N=C+I*d+D*l+F*f+K*u+$*c;C=N>>>13,N&=8191,N+=_*a+P*(5*m)+T*(5*b)+B*(5*g)+H*(5*p),C+=N>>>13,N&=8191;let k=C+I*p+D*d+F*l+K*f+$*u;C=k>>>13,k&=8191,k+=_*c+P*a+T*(5*m)+B*(5*b)+H*(5*g),C+=k>>>13,k&=8191;let q=C+I*g+D*p+F*d+K*l+$*f;C=q>>>13,q&=8191,q+=_*u+P*c+T*a+B*(5*m)+H*(5*b),C+=q>>>13,q&=8191;let z=C+I*b+D*g+F*p+K*d+$*l;C=z>>>13,z&=8191,z+=_*f+P*u+T*c+B*a+H*(5*m),C+=z>>>13,z&=8191;let j=C+I*m+D*b+F*g+K*p+$*d;C=j>>>13,j&=8191,j+=_*l+P*f+T*u+B*c+H*a,C+=j>>>13,j&=8191,C=(C<<2)+C|0,C=C+S|0,S=C&8191,C=C>>>13,h+=C,o[0]=S,o[1]=h,o[2]=y,o[3]=v,o[4]=O,o[5]=N,o[6]=k,o[7]=q,o[8]=z,o[9]=j}finalize(){let{h:e,pad:r}=this,n=new Uint16Array(10),s=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=s,s=e[a]>>>13,e[a]&=8191;e[0]+=s*5,s=e[0]>>>13,e[0]&=8191,e[1]+=s,s=e[1]>>>13,e[1]&=8191,e[2]+=s,n[0]=e[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)e[a]=e[a]&o|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+r[0];e[0]=i&65535;for(let a=1;a<8;a++)i=(e[a]+r[a]|0)+(i>>>16)|0,e[a]=i&65535;We(n)}update(e){di(this),ge(e),e=Er(e);let{buffer:r,blockLen:n}=this,s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(e,o);continue}r.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,We(this.h,this.r,this.buffer,this.pad)}digestInto(e){di(this),Hc(e,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:s}=this;if(s){for(r[s++]=1;s<16;s++)r[s]=0;this.process(r,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)e[o++]=n[i]>>>0,e[o++]=n[i]>>>8}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}},Xc=Vc(32,t=>new mi(t));function Dd(t,e,r,n,s,o=20){let i=t[0],a=t[1],c=t[2],u=t[3],f=e[0],l=e[1],d=e[2],p=e[3],g=e[4],b=e[5],m=e[6],x=e[7],E=s,w=r[0],A=r[1],L=r[2],R=i,M=a,U=c,I=u,D=f,F=l,K=d,$=p,_=g,P=b,T=m,B=x,H=E,C=w,S=A,h=L;for(let v=0;v<o;v+=2)R=R+D|0,H=X(H^R,16),_=_+H|0,D=X(D^_,12),R=R+D|0,H=X(H^R,8),_=_+H|0,D=X(D^_,7),M=M+F|0,C=X(C^M,16),P=P+C|0,F=X(F^P,12),M=M+F|0,C=X(C^M,8),P=P+C|0,F=X(F^P,7),U=U+K|0,S=X(S^U,16),T=T+S|0,K=X(K^T,12),U=U+K|0,S=X(S^U,8),T=T+S|0,K=X(K^T,7),I=I+$|0,h=X(h^I,16),B=B+h|0,$=X($^B,12),I=I+$|0,h=X(h^I,8),B=B+h|0,$=X($^B,7),R=R+F|0,h=X(h^R,16),T=T+h|0,F=X(F^T,12),R=R+F|0,h=X(h^R,8),T=T+h|0,F=X(F^T,7),M=M+K|0,H=X(H^M,16),B=B+H|0,K=X(K^B,12),M=M+K|0,H=X(H^M,8),B=B+H|0,K=X(K^B,7),U=U+$|0,C=X(C^U,16),_=_+C|0,$=X($^_,12),U=U+$|0,C=X(C^U,8),_=_+C|0,$=X($^_,7),I=I+D|0,S=X(S^I,16),P=P+S|0,D=X(D^P,12),I=I+D|0,S=X(S^I,8),P=P+S|0,D=X(D^P,7);let y=0;n[y++]=i+R|0,n[y++]=a+M|0,n[y++]=c+U|0,n[y++]=u+I|0,n[y++]=f+D|0,n[y++]=l+F|0,n[y++]=d+K|0,n[y++]=p+$|0,n[y++]=g+_|0,n[y++]=b+P|0,n[y++]=m+T|0,n[y++]=x+B|0,n[y++]=E+H|0,n[y++]=w+C|0,n[y++]=A+S|0,n[y++]=L+h|0}var Rd=Zc(Dd,{counterRight:!1,counterLength:4,allowShortKeys:!1});var Od=new Uint8Array(16),Qc=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(Od.subarray(r))},Pd=new Uint8Array(32);function Jc(t,e,r,n,s){s!==void 0&&ge(s,void 0,"AAD");let o=t(e,r,Pd),i=Wc(n.length,s?s.length:0,!0),a=Xc.create(o);s&&Qc(a,s),Qc(a,n),a.update(i);let c=a.digest();return We(o,i),c}var Ud=t=>(e,r,n)=>({encrypt(o,i){let a=o.length;i=Vr(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);t(e,r,c,c,1);let u=Jc(t,e,r,c,n);return i.set(u,a),We(u),i},decrypt(o,i){i=Vr(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),u=Jc(t,e,r,a,n);if(!$c(c,u))throw We(u),new Error("invalid tag");return i.set(o.subarray(0,-16)),t(e,r,i,i,1),We(u),i}}),yi=jc({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},Ud(Rd));var ls=BigInt(4294967295),eu=BigInt(32);function Nd(t,e=!1){return e?{h:Number(t&ls),l:Number(t>>eu&ls)}:{h:Number(t>>eu&ls)|0,l:Number(t&ls)|0}}function tu(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Nd(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var kd=t=>t/2**32|0,Md=t=>t>>>0;function ru(t,e,r,n){let s=kd(r),o=Md(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}var gi=(t,e,r)=>t>>>r,bi=(t,e,r)=>t<<32-r|e>>>r,$t=(t,e,r)=>t>>>r|e<<32-r,Vt=(t,e,r)=>t<<32-r|e>>>r,Yr=(t,e,r)=>t<<64-r|e>>>r-32,Gr=(t,e,r)=>t>>>r-32|e<<64-r;function Je(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var nu=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),su=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ou=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),iu=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,au=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),cu=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;function hs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var wi=t=>t?`"${t}" `:"";function Ye(t,e=""){if(typeof t!="number")throw new TypeError(wi(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(wi(e)+"expected integer >= 0, got "+t);return t}function Oe(t,e,r=""){if(hs(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Ye(e,"length");let n=hs(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=wi(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}function jt(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ye(t.outputLen),Ye(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Fd=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},uu=(t,e)=>{Fd(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Sr(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function ds(t,e){Oe(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function He(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function ps(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ge(t,e){return t<<32-e|t>>>e}var lu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Hd=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ms(t){if(Oe(t),lu)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Hd[t[r]];return e}function fu(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function ys(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(lu)try{return Uint8Array.fromHex(t)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=fu(t.charCodeAt(o)),a=fu(t.charCodeAt(o+1));if(i===void 0||a===void 0){let c=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function xi(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Oe(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function qd(t,e,r="opts"){return uu(t,"defaults"),e!==void 0&&uu(e,r),Object.assign(Object.create(null),t,e)}function Ei(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=qd({},e,"info");let r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function hu(t=32){Ye(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Si=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function du(t,e,r){return t&e^~t&r}function pu(t,e,r){return t&e^t&r^e&r}var Zr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=ps(this.buffer)}update(e){Sr(this),Oe(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length,i=!1;for(let a=0;a<o;){let c=Math.min(s-this.pos,o-a);if(c===s){let u=ps(e);for(;s<=o-a;a+=s)this.process(u,a);i=!0;continue}n.set(a===0&&c===o?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Sr(this),ds(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>s-i&&(this.process(n,0),r.fill(0)),ru(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let a=e===r?n:ps(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:s,destroyed:o,pos:i}=this;return e.destroyed=o,e.finished=s,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},mu=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var yu=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var zd=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]),Et=new Uint32Array(64),vi=class extends Zr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,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:e,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,r,n,s,o,i,a,c]}set(e,r,n,s,o,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)Et[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let d=Et[l-15],p=Et[l-2],g=Ge(d,7)^Ge(d,18)^d>>>3,b=Ge(p,17)^Ge(p,19)^p>>>10;Et[l]=b+Et[l-7]+g+Et[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Ge(a,6)^Ge(a,11)^Ge(a,25),p=f+d+du(a,c,u)+zd[l]+Et[l]|0,b=(Ge(n,2)^Ge(n,13)^Ge(n,22))+pu(n,s,o)|0;f=u,u=c,c=a,a=i+p|0,i=o,o=s,s=n,n=p+b|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){He(Et)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),He(this.buffer)}},Ai=class extends vi{constructor(){super(32,mu)}};var gu=tu(["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(t=>BigInt(t))),$d=gu[0],Vd=gu[1],St=new Uint32Array(80),vt=new Uint32Array(80),Bi=class extends Zr{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(e,r){super(128,e,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:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:p,Gl:g,Hh:b,Hl:m}=this;return[e,r,n,s,o,i,a,c,u,f,l,d,p,g,b,m]}set(e,r,n,s,o,i,a,c,u,f,l,d,p,g,b,m){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=g|0,this.Hh=b|0,this.Hl=m|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let w=0;w<16;w++,r+=4)St[w]=e.getUint32(r),vt[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let A=St[w-15]|0,L=vt[w-15]|0,R=$t(A,L,1)^$t(A,L,8)^gi(A,L,7),M=Vt(A,L,1)^Vt(A,L,8)^bi(A,L,7),U=St[w-2]|0,I=vt[w-2]|0,D=$t(U,I,19)^Yr(U,I,61)^gi(U,I,6),F=Vt(U,I,19)^Gr(U,I,61)^bi(U,I,6),K=ou(M,F,vt[w-7],vt[w-16]),$=iu(K,R,D,St[w-7],St[w-16]);St[w]=$|0,vt[w]=K|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:g,Gh:b,Gl:m,Hh:x,Hl:E}=this;for(let w=0;w<80;w++){let A=$t(l,d,14)^$t(l,d,18)^Yr(l,d,41),L=Vt(l,d,14)^Vt(l,d,18)^Gr(l,d,41),R=l&p^~l&b,M=d&g^~d&m,U=au(E,L,M,Vd[w],vt[w]),I=cu(U,x,A,R,$d[w],St[w]),D=U|0,F=$t(n,s,28)^Yr(n,s,34)^Yr(n,s,39),K=Vt(n,s,28)^Gr(n,s,34)^Gr(n,s,39),$=n&o^n&a^o&a,_=s&i^s&c^i&c;x=b|0,E=m|0,b=p|0,m=g|0,p=l|0,g=d|0,{h:l,l:d}=Je(u|0,f|0,I|0,D|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let P=nu(D,K,_);n=su(P,I,F,$),s=P|0}({h:n,l:s}=Je(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Je(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Je(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Je(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Je(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:g}=Je(this.Fh|0,this.Fl|0,p|0,g|0),{h:b,l:m}=Je(this.Gh|0,this.Gl|0,b|0,m|0),{h:x,l:E}=Je(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,o,i,a,c,u,f,l,d,p,g,b,m,x,E)}roundClean(){He(St,vt)}destroy(){this.destroyed=!0,He(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Li=class extends Bi{constructor(){super(64,yu)}};var et=Ei(()=>new Ai,Si(1));var _i=Ei(()=>new Li,Si(3));function bs(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var Z=(t,e,r)=>Oe(t,e,r),Ti=Ye;function wu(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function At(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Wt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Xr=ms,qe=(...t)=>xi(...t),vr=t=>ys(t),Lt=hs,ft=t=>hu(t),gs=BigInt(0),bu=BigInt(1),jd=t=>t?`"${t}" `:"";function Ue(t,e=""){if(typeof t!="boolean")throw new TypeError(jd(e)+"expected boolean, got type="+typeof t);return t}function ws(t){if(typeof t=="bigint"){if(!Bt(t))throw new RangeError("positive bigint expected, got "+t)}else Ti(t);return t}function lt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Qr(t){let e=ws(t).toString(16);return e.length&1?"0"+e:e}function xu(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?gs:BigInt("0x"+t)}function tt(t){return xu(ms(t))}function rt(t){return xu(ms(_t(Oe(t)).reverse()))}function xs(t,e){if(Ye(e),e===0)throw new Error("zero output length is invalid");t=ws(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return ys(n.padStart(r,"0"))}function Jr(t,e){return xs(t,e).reverse()}function _t(t){return Uint8Array.from(Z(t))}function Bt(t){return typeof t=="bigint"&&gs<=t}function Ci(t,e,r){return Bt(t)&&Bt(e)&&Bt(r)&&e<=t&&t<r}function nt(t,e,r,n){if(!Ci(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Ar(t){if(t<gs)throw new Error("expected non-negative bigint, got "+t);return t===gs?0:t.toString(2).length}var en=t=>(lt(t,"n"),(bu<<BigInt(t))-bu);function Eu(t,e,r){if(Ye(t,"hashLen"),Ye(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...m)=>r(u,qe(c,...m)),p=(m=s)=>{u=d(o,m),c=d(),m.length!==0&&(u=d(i,m),c=d())},g=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,x=[];for(;m<e;){c=d();let E=c.slice();x.push(E),m+=c.length}return qe(...x)};return(m,x)=>{l(),p(m);let E;for(;(E=x(g()))===void 0;)p();return l(),E}}function Ie(t,e={},r={},n="object"){At(t,n),At(e,"fields"),At(r,"optFields");function s(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let o=(i,a)=>Object.entries(i).forEach(([c,u])=>s(c,u,a));o(e,!1),o(r,!0)}var Ee=BigInt(0),re=BigInt(1),Tt=BigInt(2),Au=BigInt(3),Ii=BigInt(4),Bu=BigInt(5),Wd=BigInt(7),Lu=BigInt(8),Yd=BigInt(9),Gd=BigInt(15),_u=BigInt(16),Zd=BigInt("0x10000000000000000");function ne(t,e){if(e<=Ee)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=Ee?r:e+r}function Tu(t,e,r){if(r<=re)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<Ee)throw new Error("invalid exponent, negatives unsupported");if(e===Ee)return re;if(e===re)return t;let n=t%r;if(n<Ee&&(n+=r),e<Zd){let a=re;for(;e>Ee;)e&re&&(a=a*n%r),n=n*n%r,e>>=re;return a}let s=[];for(;e>Ee;)s.push(Number(e&Gd)),e>>=Ii;let o=new Array(16);o[0]=re,o[1]=n;for(let a=2;a<16;a++)o[a]=o[a-1]*n%r;let i=o[s[s.length-1]];for(let a=s.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=s[a];c!==0&&(i=i*o[c]%r)}return i}function le(t,e,r){if(r<=re)throw new Error("pow2: expected modulus > 1, got "+r);if(e<Ee)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >Ee;)n*=n,n%=r;return n}function Su(t,e){if(t===Ee)throw new Error("invert: expected non-zero number");if(e<=re)throw new Error("invert: expected modulus > 1, got "+e);let r=ne(t,e),n=e,s=Ee,o=re;for(;r!==Ee;){let a=n/r,c=n-r*a,u=s-o*a;n=r,r=c,s=o,o=u}if(n!==re)throw new Error("invert: does not exist");return ne(s,e)}function Cu(t,e){if(e<=re)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ne(t,e);if(r===Ee)throw new Error("invertCt: expected non-zero number");let n=Tu(r,e-Tt,e);if(ne(r*n,e)!==re)throw new Error("invertCt: does not exist");return n}function Di(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Ri(t,e){if((t&re)===Ee)throw new Error(e+": expected odd modulus, got "+t)}function Iu(t,e){let r=t,n=(r.ORDER+re)/Ii,s=r.pow(e,n);return Di(r,s,e),s}function Xd(t,e){let r=t,n=(r.ORDER-Bu)/Lu,s=r.mul(e,Tt),o=r.pow(s,n),i=r.mul(e,o),a=r.mul(r.mul(i,Tt),o),c=r.mul(i,r.sub(a,r.ONE));return Di(r,c,e),c}function Qd(t){let e=Lr(t),r=Du(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Wd)/_u;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,s),p=u.mul(f,o),g=u.eql(u.sqr(l),c),b=u.eql(u.sqr(d),c);f=u.cmov(f,l,g),l=u.cmov(p,d,b);let m=u.eql(u.sqr(l),c),x=u.cmov(f,l,m);return Di(u,x,c),x})}function Du(t){if(t<Au)throw new Error("sqrt is not defined for small field");Ri(t,"tonelliShanks");let e=t-re,r=0;for(;e%Tt===Ee;)e/=Tt,r++;let n=Tt,s=Lr(t);for(;tn(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Iu;let o=s.pow(n,e),i=(e+re)/Tt;return function(c,u){let f=c;if(f.is0(u))return u;if(tn(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,o),p=f.pow(u,e),g=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let b=1,m=f.sqr(p);for(;!f.eql(m,f.ONE);)if(b++,m=f.sqr(m),b===l)throw new Error("Cannot find square root");let x=re<<BigInt(l-b-1),E=f.pow(d,x);l=b,d=f.sqr(E),p=f.mul(p,d),g=f.mul(g,E)}return g}}function Jd(t){return Ri(t,"Fp.sqrt"),t%Ii===Au?Iu:t%Lu===Bu?Xd:t%_u===Yd?Qd(t):Du(t)}var Ru=(t,e)=>(ne(t,e)&re)===re,ep=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Br(t){if(At(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);lt(t.BYTES,"BYTES"),lt(t.BITS,"BITS");for(let e of ep)Wt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=re)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Ss(t,e,r=!1){Br(t),bs(e,"nums"),Ue(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),i),s}function tn(t,e){Br(t);let r=t;Ri(r.ORDER,"FpLegendre");let n=(r.ORDER-re)/Tt,s=r.pow(e,n),o=r.eql(s,r.ONE),i=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!o&&!i&&!a)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function tp(t,e){if(e!==void 0&&Ti(e),t<=Ee)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Ar(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var vu=new WeakMap,Es=class{ORDER;BITS;BYTES;isLE;ZERO=Ee;ONE=re;_lengths;_mod;constructor(e,r={}){if(e<=re)throw new Error("invalid field: expected ORDER > 1, got "+e);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:s,nByteLength:o}=tp(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(e){return ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return Ee<=e&&e<this.ORDER}is0(e){return e===Ee}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&re)===re}neg(e){return ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ne(e*e,this.ORDER)}add(e,r){return ne(e+r,this.ORDER)}sub(e,r){return ne(e-r,this.ORDER)}mul(e,r){return ne(e*r,this.ORDER)}pow(e,r){return Tu(e,r,this.ORDER)}div(e,r){return ne(e*Su(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Su(e,this.ORDER)}sqrt(e){let r=vu.get(this);return r||vu.set(this,r=Jd(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Jr(e,this.BYTES):xs(e,this.BYTES)}fromBytes(e,r=!1){Z(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(s);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?rt(e):tt(e);if(a&&(c=ne(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Ss(this,e,!0)}cmov(e,r,n){return Ue(n,"condition"),n?r:e}};function Lr(t,e={}){return Object.freeze(Es.prototype),new Es(t,e)}function Ou(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=re)throw new Error("field order must be greater than 1");let e=Ar(t-re);return Math.ceil(e/8)}function vs(t){let e=Ou(t);return e+Math.ceil(e/2)}function As(t,e,r=!1){Z(t);let n=t.length,s=Ou(e),o=Math.max(vs(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?rt(t):tt(t),a=ne(i,e-re)+re;return r?Jr(a,s):xs(a,s)}var Ui=BigInt(0),rn=BigInt(1),rp=BigInt(4),Oi=16,Pu=128,np=5,Uu=2**31;function Ct(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Wt(e.fromAffine,"Point.fromAffine"),Wt(e.fromBytes,"Point.fromBytes"),Wt(e.fromHex,"Point.fromHex"),At(e.BASE,"Point.BASE"),At(e.ZERO,"Point.ZERO"),Br(e.Fp),Br(e.Fn)}function Bs(t,e){Ct(t),ku(e,t);let r=Ss(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function sp(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function op(t,e){let r=t*(4*e+128);if(r>Uu)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Uu/2**20+" MiB")}function Ni(t,e){if(t!==void 0){Wt(t,"randomBytes");try{let r=t(e);if(!Lt(r)||r.length!==e)return}catch{return}return t}}function ku(t,e){bs(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function ip(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,s)=>{if(!(r===void 0?e.isValid(n):Bt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var Mu=new WeakMap;function Pi(t){return Mu.get(t)||1}function ap(t,e){let r=t.double(),n=[t];for(let s=1;s<e;s++)n.push(n[s-1].add(r));return n}function cp(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>Ui;){let i=0;t&rn&&(i=Number(t&s),i>=n&&(i-=r),t-=BigInt(i)),o.push(i),t>>=rn}return o}function up(t,e,r){let n=2**e,s=n/2,o=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&o);t>>=i,u>s&&(u-=n,t+=rn),a.push(u)}if(t!==Ui)throw new Error("invalid wnaf");return a}function fp(t,e,r){let n=0;for(let o of r)n=Math.max(n,o.length);let s=t;for(let o=n-1;o>=0;o--){o!==n-1&&(s=s.double());for(let i=0;i<r.length;i++){let a=r[i][o];if(a){let c=e[i][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var _r=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Ct(e),this.randomBytes=Ni(r,Oi),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let s=Math.ceil(n/r)+1,o=2**(r-1),i=[],a=e;for(let c=0;c<s;c++){let u=a;for(let f=0;f<o;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:s,comp:i}}wnafCachedCT(e,r){let{W:n,windows:s,comp:o}=e,i=2**(n-1),a=up(r,n,s),c=this.ZERO,u=this.BASE;for(let f=0;f<s;f++){let l=a[f],d=f*i,p=Math.abs(l)-1,g=o[d];for(let m=1;m<i;m++)g=m===p?o[d+m]:g;let b=g.negate();l===0?u=u.add(o[d]):c=c.add(l<0?b:g)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,s){let o=this.wnafPrecomputes.get(r),i=o?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof s=="function"&&(i={...i,comp:s(i.comp)}),o||(o=[],this.wnafPrecomputes.set(r,o)),o.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!Ci(r,rn,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Pi(e);return o===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(o,e,n,s),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+Pu,o=this.randomBytes(Oi);if(!Lt(o)||o.length!==Oi)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let i=r+tt(o)*this.Point.Fn.ORDER;return this.runCT(e,i,s,n)}fixedWindowCT(e,r,n){let s=np,o=1<<s,i=en(s),a=new Array(o);a[0]=this.ZERO;for(let f=1;f<o;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/s),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<s;p++)u=u.double();let l=Number(r>>BigInt(f*s)&i),d=a[0];for(let p=1;p<o;p++)d=p===l?a[p]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===rn?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,s){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,s):this.mulCT(e,r,s)}mulUnsafe(e,r,n){if(this.assertPoint(e),!Bt(r))throw new Error("invalid scalar");let s=Pi(e);if(s===1||r>=this.Point.Fn.ORDER)return Ls(this.Point,[e],[r],!0);let o=this.getWnafPrecomputes(s,e,this.bits,n);return this.wnafCachedCT(o,r).p}setWindowSize(e,r){this.assertPoint(e),sp(r,this.bits);let n=Math.ceil((this.bits+Pu)/r)+1;op(n*2**(r-1),this.Point.Fp.BYTES),Mu.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Pi(e)!==1}};function Ls(t,e,r,n=!1){if(Ct(t),ku(e,t),Ue(n,"allowOversized"),ip(r,t.Fn,n?t.Fn.ORDER**rp:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(i=>ap(i,4)),o=r.map(i=>cp(i,4));return fp(t.ZERO,s,o)}function Nu(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Br(e),e}else return Lr(t,{isLE:r})}function _s(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Ie(r);for(let c of["p","n","h"]){let u=e[c];if(!(Bt(u)&&u!==Ui))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Nu(e.p,r.Fp,n),o=Nu(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function Tr(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var Ts=BigInt(0),Cs=BigInt(1),Is=BigInt(2),lp=BigInt(4),Ku=BigInt(8);function hp(t,e,r,n){let s=t.sqr(r),o=t.sqr(n),i=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(i,a)}function Fu(t,e={}){Ie(e,{},{},"extraOpts");let r=e,n=_s("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;if(tn(s,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(tn(s,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Ie(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?ft:r.randomBytes,u=Is<<BigInt(s.BYTES*8)-Cs;function f(E){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(E)}let l=r.uvRatio===void 0?(E,w)=>{try{return{isValid:!0,value:s.sqrt(s.div(E,w))}}catch{return{isValid:!1,value:Ts}}}:r.uvRatio;if(!hp(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=s.eql(i.a,s.neg(s.ONE))?E=>s.neg(E):s.eql(i.a,s.ONE)?E=>E:E=>s.mul(i.a,E);function p(E,w,A=!1){let L=A?Cs:Ts;return nt("coordinate "+E,w,L,u),w}function g(E){if(!(E instanceof b))throw new Error("EdwardsPoint expected")}class b{static BASE=new b(i.Gx,i.Gy,s.ONE,s.mul(i.Gx,i.Gy));static ZERO=new b(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=o;X;Y;Z;T;constructor(w,A,L,R){this.X=p("x",w),this.Y=p("y",A),this.Z=p("z",L,!0),this.T=p("t",R),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:A,y:L}=w||{};return p("x",A),p("y",L),new b(A,L,s.ONE,s.mul(A,L))}static fromBytes(w,A=!1){let L=s.BYTES,{a:R,d:M}=i;w=_t(Z(w,L,"point")),Ue(A,"zip215");let U=_t(w),I=w[L-1];U[L-1]=I&-129;let D=rt(U),F=A?u:s.ORDER;nt("point.y",D,Ts,F);let K=s.sqr(D),$=s.sub(K,s.ONE),_=s.sub(s.mulN(M,K),R),{isValid:P,value:T}=l($,_);if(!P)throw new Error("bad point: invalid y coordinate");let B=f(T),H=(I&128)!==0;if(!A&&s.is0(T)&&H)throw new Error("bad point: x=0 and x_0=1");return H!==B&&(T=s.neg(T)),b.fromAffine({x:T,y:D})}static fromHex(w,A=!1){return b.fromBytes(vr(w),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=6,A=!0){return x.setWindowSize(this,w),A||this.multiply(Is),this}assertValidity(){let w=this,{a:A,d:L}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:R,Y:M,Z:U,T:I}=w,D=s.sqr(R),F=s.sqr(M),K=s.sqr(U),$=s.sqr(K),_=s.mul(D,A),P=s.mul(s.add(_,F),K),T=s.add($,s.mul(L,s.mul(D,F)));if(!s.eql(P,T))throw new Error("bad point: equation left != right (1)");let B=s.mul(R,M),H=s.mul(U,I);if(!s.eql(B,H))throw new Error("bad point: equation left != right (2)")}equals(w){g(w);let{X:A,Y:L,Z:R}=this,{X:M,Y:U,Z:I}=w,D=s.mul(A,I),F=s.mul(M,R),K=s.mul(L,I),$=s.mul(U,R);return s.eql(D,F)&&s.eql(K,$)}is0(){return this.equals(b.ZERO)}negate(){return new b(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:w,Y:A,Z:L}=this,R=s.sqr(w),M=s.sqr(A),U=s.mul(s.sqr(L),Is),I=d(R),D=s.addN(w,A),F=s.sub(s.subN(s.sqr(D),R),M),K=s.addN(I,M),$=s.subN(K,U),_=s.subN(I,M),P=s.mul(F,$),T=s.mul(K,_),B=s.mul(F,_),H=s.mul($,K);return new b(P,T,H,B)}add(w){g(w);let{d:A}=i,{X:L,Y:R,Z:M,T:U}=this,{X:I,Y:D,Z:F,T:K}=w,$=s.mul(L,I),_=s.mul(R,D),P=s.mul(s.mulN(U,A),K),T=s.mul(M,F),B=s.sub(s.subN(s.mulN(s.addN(L,R),s.addN(I,D)),$),_),H=s.subN(T,P),C=s.addN(T,P),S=s.sub(_,d($)),h=s.mul(B,H),y=s.mul(C,S),v=s.mul(B,S),O=s.mul(H,C);return new b(h,y,O,v)}subtract(w){return g(w),this.add(w.negate())}multiply(w){if(!o.isValidNot0(w))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:L}=x.mulSecret(this,w,a,m);return m([A,L])[0]}multiplyUnsafe(w){if(!o.isValid(w))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return w===Ts?b.ZERO:this.is0()||w===Cs?this:x.mulUnsafe(this,w,m)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(w){let A=this,L=w;if(L!=null&&typeof L!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof L);let{X:R,Y:M,Z:U}=A,I=A.is0();L==null&&(L=I?s.create(Ku):s.inv(U));let D=s.mul(R,L),F=s.mul(M,L),K=s.mul(U,L);if(I)return{x:s.ZERO,y:s.ONE};if(!s.eql(K,s.ONE))throw new Error("invZ was invalid");return{x:D,y:F}}clearCofactor(){return a===Cs?this:a===Is?this.double():a===lp?this.double().double():a===Ku?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:w,y:A}=this.toAffine(),L=s.toBytes(A);return L[L.length-1]|=f(w)?128:0,L}toHex(){return Xr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=E=>Bs(b,E),x=new _r(b,c);return x.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function Hu(t,e,r={}){if(Ct(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;Ie(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(lt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=s.randomBytes===void 0?ft:s.randomBytes,d=s.toMontgomery,p=s.toMontgomerySecret,g=s.adjustScalarBytes===void 0?_=>_:s.adjustScalarBytes,b=s.domain===void 0?(_,P,T)=>{if(Ue(T,"phflag"),P.length||T)throw new Error("Contexts/pre-hash are not supported");return _}:s.domain;function m(_){return c.create(rt(_))}function x(_){let P=I.secretKey;Z(_,I.secretKey,"secretKey");let T=Z(n(_),2*P,"hashedSecretKey"),B=g(T.slice(0,P)),H=T.slice(P,2*P),C=m(B);return{head:B,prefix:H,scalar:C}}function E(_){let{head:P,prefix:T,scalar:B}=x(_),H=i.multiply(B),C=H.toBytes();return{head:P,prefix:T,scalar:B,point:H,pointBytes:C}}function w(_){return E(_).pointBytes}function A(_=Uint8Array.of(),...P){let T=qe(...P);return m(n(b(T,Z(_,void 0,"context"),!!o)))}function L(_,P,T={}){Ie(T,{},{},"options"),_=_t(Z(_,void 0,"message")),o&&(_=o(_));let{prefix:B,scalar:H,pointBytes:C}=E(P),S=A(T.context,B,_),h=i.multiply(S).toBytes(),y=A(T.context,h,C,_),v=c.create(S+y*H);if(!c.isValid(v))throw new Error("sign failed: invalid s");let O=qe(h,c.toBytes(v));return Z(O,I.signature,"result")}let R={zip215:s.zip215};function M(_,P,T,B=R){Ie(B);let{context:H}=B,C=B.zip215===void 0?!!R.zip215:B.zip215,S=I.signature;_=Z(_,S,"signature"),P=Z(P,void 0,"message"),T=Z(T,I.publicKey,"publicKey"),C!==void 0&&Ue(C,"zip215"),o&&(P=o(P));let h=S/2,y=_.subarray(0,h),v=rt(_.subarray(h,S)),O,N,k;try{O=t.fromBytes(T,C),N=t.fromBytes(y,C),k=i.multiplyUnsafe(v)}catch{return!1}if(!C&&O.isSmallOrder())return!1;let q=A(H,y,T,P);return N.add(O.multiplyUnsafe(q)).subtract(k).clearCofactor().is0()}let U=a.BYTES,I={secretKey:U,publicKey:U,signature:2*U,seed:U};function D(_){return _=_===void 0?l(I.seed):_,Z(_,I.seed,"seed")}function F(_){return Lt(_)&&_.length===I.secretKey}function K(_,P){try{return!!t.fromBytes(_,P===void 0?R.zip215:P)}catch{return!1}}let $={getExtendedPublicKey:E,randomSecretKey:D,isValidSecretKey:F,isValidPublicKey:K,toMontgomery(_){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(t.fromBytes(_))},toMontgomerySecret(_){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(_)}};return Object.freeze(I),Object.freeze($),Object.freeze({keygen:Tr(D,w),getPublicKey:w,sign:L,verify:M,utils:$,Point:t,lengths:I})}var Yt=BigInt(0),ze=BigInt(1),Ds=BigInt(2);function qu(t,e){return t+e-(e>>ze<<ze)}function dp(t){let e=BigInt(6)*t;return(r,n,s)=>{let o=n+s,a=((e+s-n)*r+n)%t;return{x_2:a,x_3:o-a}}}function pp(t){return Ie(t,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function",scalarMultBase:"function"}),Object.freeze({...t})}function zu(t){let e=pp(t),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=e,a=e.scalarMultBase,c=n==="x25519";if(!c&&n!=="x448")throw new Error("invalid type");let u=i===void 0?ft:i,f=c?255:448,l=dp(r),d=c?32:56,p=BigInt(c?9:5),g=BigInt(c?121665:39081),b=c?Ds**BigInt(254):Ds**BigInt(447),m=c?BigInt(8)*(Ds**BigInt(251)-ze):BigInt(4)*(Ds**BigInt(445)-ze),x=b+m+ze,E=T=>ne(T,r),w=A(p);function A(T){return Jr(E(T),d)}function L(T){let B=_t(Z(T,d,"uCoordinate"));return c&&(B[31]&=127),E(rt(B))}function R(T){return rt(s(_t(Z(T,d,"scalar"))))}let M=new Set(c?[Yt,ze,r-ze,BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")]:[Yt,ze,r-ze]);function U(T,B){let H=L(B);if(M.has(H))throw new Error("invalid private or public key received");let C=K(H,R(T));if(C===Yt)throw new Error("invalid private or public key received");return A(C)}function I(T){if(a===void 0)return U(T,w);let B=R(T);nt("scalar",B,b,x);let H=E(a(B));if(H===Yt)throw new Error("invalid private or public key received");return A(H)}let D=I,F=U;function K(T,B){nt("u",T,Yt,r),nt("scalar",B,b,x);let H=B,C=T,S=ze,h=Yt,y=T,v=ze,O=H^H>>ze;for(let q=BigInt(f-1);q>=Yt;q--){let z=qu(r,O>>q);({x_2:S,x_3:y}=l(z,S,y)),{x_2:h,x_3:v}=l(z,h,v);let j=S+h,Y=E(j*j),ce=S-h,ie=E(ce*ce),ye=Y-ie,Pe=y+v,ae=y-v,he=E(ae*j),or=E(Pe*ce),Nr=he+or,mt=he-or;y=E(Nr*Nr),v=E(C*E(mt*mt)),S=E(Y*ie),h=E(ye*(Y+E(g*ye)))}let N=qu(r,H);({x_2:S,x_3:y}=l(N,S,y)),{x_2:h,x_3:v}=l(N,h,v);let k=o(h);return E(S*k)}let $={secretKey:d,publicKey:d,seed:d},_=T=>(T=T===void 0?u(d):T,Z(T,$.seed,"seed"),T),P={randomSecretKey:_};return Object.freeze($),Object.freeze(P),Object.freeze({keygen:Tr(_,D),getSharedSecret:F,getPublicKey:D,scalarMult:U,scalarMultBase:I,utils:P,GuBytes:w.slice(),lengths:$})}var $u=BigInt(0),ki=BigInt(1),Vu=BigInt(2),mp=BigInt(3),yp=BigInt(5),gp=BigInt(8),Rs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),bp={p:Rs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:gp,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Yu(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=Rs,a=t*t%o*t%o,c=le(a,Vu,o)*a%o,u=le(c,ki,o)*t%o,f=le(u,yp,o)*u%o,l=le(f,e,o)*f%o,d=le(l,r,o)*l%o,p=le(d,n,o)*d%o,g=le(p,s,o)*p%o,b=le(g,s,o)*p%o,m=le(b,e,o)*f%o;return{pow_p_5_8:le(m,Vu,o)*t%o,b2:a}}function Mi(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var ju=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function wp(t,e){let r=Rs,n=ne(e*e*e,r),s=ne(n*n*e,r),o=Yu(t*s).pow_p_5_8,i=ne(t*n*o,r),a=ne(e*i*i,r),c=i,u=ne(i*ju,r),f=a===t,l=a===ne(-t,r),d=a===ne(-t*ju,r);return f&&(i=c),(l||d)&&(i=u),Ru(i,r)&&(i=ne(-i,r)),{isValid:f||l,value:i}}var nn=Fu(bp,{uvRatio:wp}),Wu=nn.Fp;function xp(t){let{y:e}=t;return Wu.toBytes(Wu.div(ki+e,ki-e))}function Ep(t){let e=nn.Fp.BYTES;return Oe(t,e),Mi(_i(t.subarray(0,e))).subarray(0,e)}function Sp(t){return Hu(nn,_i,Object.assign({adjustScalarBytes:Mi,toMontgomery:xp,toMontgomerySecret:Ep,zip215:!0},t))}var Gu=Sp({});var sn=(()=>{let t=Rs,e=r=>{let{pow_p_5_8:n,b2:s}=Yu(r);return ne(le(n,mp,t)*s,t)};return zu({P:t,type:"x25519",powPminus2:e,adjustScalarBytes:Mi,scalarMultBase:r=>{let n=ne(r,nn.Fn.ORDER);if(n===$u)return $u;let s=nn.BASE.multiply(n);return ne((s.Z+s.Y)*e(ne(s.Z-s.Y,t)),t)}})})();var Os=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(jt(e),Oe(r,void 0,"key"),this.iHash=e.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,s=new Uint8Array(n);s.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),He(s)}update(e){return Sr(this),this.iHash.update(e),this}digestInto(e){Sr(this),ds(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},on=(()=>{let t=((e,r,n)=>new Os(e,r).update(n).digest());return t.create=(e,r)=>new Os(e,r),t})();function Zu(t,e,r){return jt(t),r===void 0&&(r=new Uint8Array(t.outputLen)),on(t,r,e)}var an=Uint8Array.of(0),vp=Uint8Array.of();function Xu(t,e,r,n=32,s){jt(t),Ye(n,"length"),Oe(e,void 0,"prk");let o=t.outputLen;if(e.length<o)throw new Error('"prk" must be at least HashLen octets');if(n>255*o)throw new Error("Length must be <= 255*HashLen");let i=Math.ceil(n/o);if(r===void 0?r=vp:Oe(r,void 0,"info"),!i)return s&&He(e),new Uint8Array;let a=s&&i===1?e:new Uint8Array(i*o),{iHash:c,oHash:u}=on.create(t,e),f=s?e:new Uint8Array(o),l=i>1?s?.iHash||t.create():void 0;for(let p=0;p<i-1;p++){an[0]=p+1;let g=c._cloneInto(l);p&&g.update(f),g.update(r).update(an).digestInto(f),u._cloneInto(l).update(f).digestInto(f),a.set(f,o*p)}if(an[0]=i,i>1&&c.update(f),c.update(r).update(an).digestInto(f),u.update(f).digestInto(f),a.set(f,o*(i-1)),c.destroy(),u.destroy(),l?.destroy(),f!==a&&He(f),He(an),n===a.length)return a;let d=a.slice(0,n);return He(a),d}var Qu={hashSHA256(t){return et(t.subarray())},getHKDF(t,e){let r=Zu(et,e,t),s=Xu(et,r,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let t=sn.utils.randomSecretKey();return{publicKey:sn.getPublicKey(t),privateKey:t}},generateX25519KeyPairFromSeed(t){return{publicKey:sn.getPublicKey(t),privateKey:t}},generateX25519SharedKey(t,e){return sn.getSharedSecret(t.subarray(),e.subarray())},chaCha20Poly1305Encrypt(t,e,r,n){return yi(n,e,r).encrypt(t.subarray())},chaCha20Poly1305Decrypt(t,e,r,n,s){return yi(n,e,r).decrypt(t.subarray(),s)}};var Ju=Qu;function ef(t){return{generateKeypair:t.generateX25519KeyPair,dh:(e,r)=>t.generateX25519SharedKey(e.privateKey,r).subarray(0,32),encrypt:t.chaCha20Poly1305Encrypt,decrypt:t.chaCha20Poly1305Decrypt,hash:t.hashSHA256,hkdf:t.getHKDF}}var Cr=t=>{let e=Se(2);return e[0]=t>>8,e[1]=t,e};Cr.bytes=2;var Ir=t=>{if(t.length<2)throw RangeError("Could not decode int16BE");if(t instanceof Uint8Array){let e=0;return e+=t[0]<<8,e+=t[1],e}return t.getUint16(0)};Ir.bytes=2;function tf(t){return{xxHandshakeSuccesses:t.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:t.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:t.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:t.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:t.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Ki(t,e){!e.enabled||!xr||(t?(e(`LOCAL_STATIC_PUBLIC_KEY ${W(t.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${W(t.privateKey,"hex")}`)):e("Missing local static keys."))}function Fi(t,e){!e.enabled||!xr||(t?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${W(t.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${W(t.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function rf(t,e){!e.enabled||!xr||e(t?`REMOTE_STATIC_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote static public key.")}function Hi(t,e){!e.enabled||!xr||e(t?`REMOTE_EPHEMERAL_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function qi(t,e,r){!r.enabled||!xr||(r(`CIPHER_STATE_1 ${t.n.getUint64()} ${t.k&&W(t.k,"hex")}`),r(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&W(e.k,"hex")}`))}var Dr=class t extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=t.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Ap=0,Bp=4294967295,Lp="Cipherstate has reached maximum n, a new handshake must be performed",Ps=class{n;bytes;view;constructor(e=Ap){this.n=e,this.bytes=be(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Bp)throw new Error(Lp)}};var Gt=be(0),Rr=class{k;n;crypto;constructor(e,r=void 0,n=0){this.crypto=e,this.k=r,this.n=new Ps(n)}hasKey(){return!!this.k}encryptWithAd(e,r){if(!this.hasKey())return r;this.n.assertValue();let n=this.crypto.encrypt(r,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,r,n){if(!this.hasKey())return r;this.n.assertValue();let s=this.crypto.decrypt(r,this.n.getBytes(),e,this.k,n);return this.n.increment(),s}},zi=class{cs;ck;h;crypto;constructor(e,r){this.crypto=e;let n=ee(r,"utf-8");this.h=_p(e,n),this.ck=this.h,this.cs=new Rr(e)}mixKey(e){let[r,n]=this.crypto.hkdf(this.ck,e);this.ck=r,this.cs=new Rr(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new Q(this.h,e))}encryptAndHash(e){let r=this.cs.encryptWithAd(this.h,e);return this.mixHash(r),r}decryptAndHash(e){let r=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),r}split(){let[e,r]=this.crypto.hkdf(this.ck,Gt);return[new Rr(this.crypto,e),new Rr(this.crypto,r)]}},$i=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=e;this.crypto=r,this.ss=new zi(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<r+32)throw new Error("message is not long enough");this.re=e.sublist(r,r+32),this.ss.mixHash(this.re)}readS(e,r=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<r+n)throw new Error("message is not long enough");let s=e.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},cn=class extends $i{writeMessageA(e){return new Q(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new Q(r,n,this.ss.encryptAndHash(e))}writeMessageC(e){let r=this.writeS();return this.writeSE(),new Q(r,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(r){throw new Dr(`handshake stage 0 validation fail: ${r.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let r=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+r))}catch(r){throw new Dr(`handshake stage 1 validation fail: ${r.message}`)}}readMessageC(e){try{let r=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(r))}catch(r){throw new Dr(`handshake stage 2 validation fail: ${r.message}`)}}};function _p(t,e){if(e.length<=32){let r=be(32);return r.set(e),r}else return t.hash(e)}async function nf(t,e,r,n){let s=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,Ae(e),Ae(r.subarray()));return n?.signal?.throwIfAborted(),o}var Tp=parseInt("11111",2),Vi=parseInt("10000000",2),Cp=parseInt("01111111",2),sf={0:un,1:un,2:Ip,3:Op,4:Pp,5:Rp,6:Dp,16:un,22:un,48:un};function ht(t,e={offset:0}){let r=t[e.offset]&Tp;if(e.offset++,sf[r]!=null)return sf[r](t,e);throw new Error("No decoder for tag "+r)}function fn(t,e){let r=0;if((t[e.offset]&Vi)===Vi){let n=t[e.offset]&Cp,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");s+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function un(t,e){fn(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=ht(t,e);if(n===null)break;r.push(n)}return r}function Ip(t,e){let r=fn(t,e),n=e.offset,s=e.offset+r,o=[];for(let i=n;i<s;i++)i===n&&t[i]===0||o.push(t[i]);return e.offset+=r,Uint8Array.from(o)}function Dp(t,e){let r=fn(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Rp(t,e){return e.offset++,null}function Op(t,e){let r=fn(t,e),n=t[e.offset];e.offset++;let s=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Pp(t,e){let r=fn(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Up(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Q;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function ji(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Up(t.byteLength);return new Q(Uint8Array.from([e.byteLength|Vi]),e)}function Ne(t){let e=new Q,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Q(Uint8Array.from([2]),ji(e),e)}function Us(t){let e=Uint8Array.from([0]),r=new Q(e,t);return new Q(Uint8Array.from([3]),ji(r),r)}function It(t,e=48){let r=new Q;for(let n of t)r.append(n);return new Q(Uint8Array.from([e]),ji(r),r)}var Np=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),kp=Uint8Array.from([6,5,43,129,4,0,34]),Mp=Uint8Array.from([6,5,43,129,4,0,35]),Kp={ext:!0,kty:"EC",crv:"P-256"},Fp={ext:!0,kty:"EC",crv:"P-384"},Hp={ext:!0,kty:"EC",crv:"P-521"},Wi=32,Yi=48,Gi=66;function Zi(t){let e=ht(t);return of(e)}function of(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===Wi*2+1)return n=W(e.subarray(r,r+Wi),"base64url"),s=W(e.subarray(r+Wi),"base64url"),new Or({...Kp,key_ops:["verify"],x:n,y:s});if(e.byteLength===Yi*2+1)return n=W(e.subarray(r,r+Yi),"base64url"),s=W(e.subarray(r+Yi),"base64url"),new Or({...Fp,key_ops:["verify"],x:n,y:s});if(e.byteLength===Gi*2+1)return n=W(e.subarray(r,r+Gi),"base64url"),s=W(e.subarray(r+Gi),"base64url"),new Or({...Hp,key_ops:["verify"],x:n,y:s});throw new se(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function af(t){return It([Ne(Uint8Array.from([1])),It([qp(t.crv)],160),It([Us(new Q(Uint8Array.from([4]),ee(t.x??"","base64url"),ee(t.y??"","base64url")))],161)]).subarray()}function qp(t){if(t==="P-256")return Np;if(t==="P-384")return kp;if(t==="P-521")return Mp;throw new se(`Invalid curve ${t}`)}var Or=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=af(this.jwk)),this._raw}toMultihash(){return je.digest(Dt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}async verify(e,r,n){return nf(this.jwk,r,e,n)}};var ln=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Ns=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var $e={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Ns("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 e}};var ks=32;var Xi,zp=(async()=>{try{return await $e.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function $p(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await $e.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await $e.get().subtle.verify({name:"Ed25519"},n,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Vp(t,e,r){return Gu.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function cf(t,e,r){return Xi==null&&(Xi=await zp),Xi?$p(t,e,r):Vp(t,e,r)}function Ms(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Ks=class{type="Ed25519";raw;constructor(e){this.raw=Qi(e,ks)}toMultihash(){return je.digest(Dt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=cf(this.raw,r,e);return Ms(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function Ji(t){return t=Qi(t,ks),new Ks(t)}function Qi(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new se(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var ea=new Float32Array([-0]),Rt=new Uint8Array(ea.buffer);function ff(t,e,r){ea[0]=t,e[r]=Rt[0],e[r+1]=Rt[1],e[r+2]=Rt[2],e[r+3]=Rt[3]}function lf(t,e){return Rt[0]=t[e],Rt[1]=t[e+1],Rt[2]=t[e+2],Rt[3]=t[e+3],ea[0]}var ta=new Float64Array([-0]),De=new Uint8Array(ta.buffer);function hf(t,e,r){ta[0]=t,e[r]=De[0],e[r+1]=De[1],e[r+2]=De[2],e[r+3]=De[3],e[r+4]=De[4],e[r+5]=De[5],e[r+6]=De[6],e[r+7]=De[7]}function df(t,e){return De[0]=t[e],De[1]=t[e+1],De[2]=t[e+2],De[3]=t[e+3],De[4]=t[e+4],De[5]=t[e+5],De[6]=t[e+6],De[7]=t[e+7],ta[0]}var Wp=BigInt(Number.MAX_SAFE_INTEGER),Yp=BigInt(Number.MIN_SAFE_INTEGER),ke=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&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(e=!1){if(e)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(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Zt;if(e<Wp&&e>Yp)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,s=e-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>pf&&(s=0n,++n>pf&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return Zt;let r=e<0;r&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new t(n,s)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Zt}},Zt=new ke(0,0);Zt.toBigInt=function(){return 0n};Zt.zzEncode=Zt.zzDecode=function(){return this};Zt.length=function(){return 1};var pf=4294967296n;function mf(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function yf(t,e,r){if(r-e<1)return"";let s,o=[],i=0,a;for(;e<r;)a=t[e++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function ra(t,e,r){let n=r,s,o;for(let i=0;i<t.length;++i)s=t.charCodeAt(i),s<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=s&63|128):(s&64512)===55296&&((o=t.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=s&63|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=s&63|128);return r-n}function Ze(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Fs(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var na=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ae(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ze(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ze(this,4);return Fs(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ze(this,4);return Fs(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ze(this,4);let e=lf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ze(this,4);let e=df(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ze(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return yf(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ze(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ze(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new ke(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ze(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ze(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ze(this,8);let e=Fs(this.buf,this.pos+=4),r=Fs(this.buf,this.pos+=4);return new ke(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=_o(this.buf,this.pos);return this.pos+=Te(e),e}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 hn(t){return new na(t instanceof Uint8Array?t:t.subarray())}function Xt(t,e,r){let n=hn(t);return e.decode(n,void 0,r)}function sa(t){let e=t??8192,r=e>>>1,n,s=e;return function(i){if(i<1||i>r)return Se(i);s+i>e&&(n=Se(e),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var Qt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function oa(){}var aa=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Gp=sa();function Zp(t){return globalThis.Buffer!=null?Se(t):Gp(t)}var pn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Qt(oa,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Qt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ca((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Hs,10,ke.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ke.fromBigInt(e);return this._push(Hs,r.length(),r)}uint64Number(e){return this._push(dr,Te(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=ke.fromBigInt(e).zzEncode();return this._push(Hs,r.length(),r)}sint64Number(e){let r=ke.fromNumber(e).zzEncode();return this._push(Hs,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ia,1,e?1:0)}fixed32(e){return this._push(dn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ke.fromBigInt(e);return this._push(dn,4,r.lo)._push(dn,4,r.hi)}fixed64Number(e){let r=ke.fromNumber(e);return this._push(dn,4,r.lo)._push(dn,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(ff,4,e)}double(e){return this._push(hf,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(ia,1,0):this.uint32(r)._push(Qp,r,e)}string(e){let r=mf(e);return r!==0?this.uint32(r)._push(ra,r,e):this._push(ia,1,0)}fork(){return this.states=new aa(this),this.head=this.tail=new Qt(oa,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 Qt(oa,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Zp(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function ia(t,e,r){e[r]=t&255}function Xp(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ca=class extends Qt{next;constructor(e,r){super(Xp,e,r),this.next=void 0}};function Hs(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function dn(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Qp(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(pn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Jp,e,t),this},pn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(em,e,t),this});function Jp(t,e,r){e.set(t,r)}function em(t,e,r){t.length<40?ra(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ee(t),r)}function ua(){return new pn}function Jt(t,e){let r=ua();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*er(t,e,r){let n=hn(t);yield*e.stream(n,void 0,".",r)}var qs={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function zs(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function fa(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},s=function*(i,a){};return zs("enum",qs.VARINT,r,n,s)}function tr(t,e,r){return zs("message",qs.LENGTH_DELIMITED,t,e,r)}var rr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var de;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(de||(de={}));var la;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(la||(la={}));(function(t){t.codec=()=>fa(la)})(de||(de={}));var st;(function(t){let e;t.codec=()=>(e==null&&(e=tr((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),de.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:de.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Jt(o,t.codec())}t.encode=r;function n(o,i){return Xt(o,t.codec(),i)}t.decode=n;function s(o,i){return er(o,t.codec(),i)}t.stream=s})(st||(st={}));var ha;(function(t){let e;t.codec=()=>(e==null&&(e=tr((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),de.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:de.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Jt(o,t.codec())}t.encode=r;function n(o,i){return Xt(o,t.codec(),i)}t.decode=n;function s(o,i){return er(o,t.codec(),i)}t.stream=s})(ha||(ha={}));var yn={};Re(yn,{MAX_RSA_KEY_SIZE:()=>da,generateRSAKeyPair:()=>Sf,jwkToJWKKeyPair:()=>vf,jwkToPkcs1:()=>sm,jwkToPkix:()=>ga,jwkToRSAPrivateKey:()=>Ea,pkcs1MessageToJwk:()=>ma,pkcs1MessageToRSAPrivateKey:()=>ba,pkcs1ToJwk:()=>nm,pkcs1ToRSAPrivateKey:()=>Ef,pkixMessageToJwk:()=>ya,pkixMessageToRSAPublicKey:()=>xa,pkixToJwk:()=>om,pkixToRSAPublicKey:()=>wa});var Pr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=yn.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return xe.createV1(114,this._multihash)}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}verify(e,r,n){return xf(this.jwk,r,e,n)}},mn=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=yn.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}sign(e,r){return wf(this.jwk,e,r)}};var da=8192,pa=18,tm=1062,rm=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function nm(t){let e=ht(t);return ma(e)}function ma(t){return{n:W(t[1],"base64url"),e:W(t[2],"base64url"),d:W(t[3],"base64url"),p:W(t[4],"base64url"),q:W(t[5],"base64url"),dp:W(t[6],"base64url"),dq:W(t[7],"base64url"),qi:W(t[8],"base64url"),kty:"RSA"}}function sm(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new se("JWK was missing components");return It([Ne(Uint8Array.from([0])),Ne(ee(t.n,"base64url")),Ne(ee(t.e,"base64url")),Ne(ee(t.d,"base64url")),Ne(ee(t.p,"base64url")),Ne(ee(t.q,"base64url")),Ne(ee(t.dp,"base64url")),Ne(ee(t.dq,"base64url")),Ne(ee(t.qi,"base64url"))]).subarray()}function om(t){let e=ht(t,{offset:0});return ya(e)}function ya(t){let e=ht(t[1],{offset:0});return{kty:"RSA",n:W(e[0],"base64url"),e:W(e[1],"base64url")}}function ga(t){if(t.n==null||t.e==null)throw new se("JWK was missing components");return It([rm,Us(It([Ne(ee(t.n,"base64url")),Ne(ee(t.e,"base64url"))]))]).subarray()}function Ef(t){let e=ht(t);return ba(e)}function ba(t){let e=ma(t);return Ea(e)}function wa(t,e){if(t.byteLength>=tm)throw new Ot("Key size is too large");let r=ht(t,{offset:0});return xa(r,t,e)}function xa(t,e,r){let n=ya(t);if(r==null){let s=et(st.encode({Type:de.RSA,Data:e}));r=Ve(pa,s)}return new Pr(n,r)}function Ea(t){if(Bf(t)>da)throw new se("Key size is too large");let e=vf(t),r=et(st.encode({Type:de.RSA,Data:ga(e.publicKey)})),n=Ve(pa,r);return new mn(e.privateKey,new Pr(e.publicKey,n))}async function Sf(t){if(t>da)throw new se("Key size is too large");let e=await Af(t),r=et(st.encode({Type:de.RSA,Data:ga(e.publicKey)})),n=Ve(pa,r);return new mn(e.privateKey,new Pr(e.publicKey,n))}function vf(t){if(t==null)throw new se("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Af(t,e){let r=await $e.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await im(r,e);return{privateKey:n[0],publicKey:n[1]}}async function wf(t,e,r){let n=await $e.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await $e.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Ae(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function xf(t,e,r,n){let s=await $e.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await $e.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function im(t,e){if(t.privateKey==null||t.publicKey==null)throw new se("Private and public key are required");let r=await Promise.all([$e.get().subtle.exportKey("jwk",t.privateKey),$e.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Bf(t){if(t.kty!=="RSA")throw new se("invalid key type");if(t.n==null)throw new se("invalid key modulus");return ee(t.n,"base64url").length*8}var am=BigInt(0),Sa=class extends Error{constructor(e=""){super(e)}},dt={Err:Sa,_tlv:{encode:(t,e)=>{let{Err:r}=dt;if(lt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(wu(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=Qr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Qr(s.length/2|128):"";return Qr(t)+o+s+e},decode(t,e){let{Err:r}=dt;e=Z(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&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=e.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 f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=dt;if(ws(t),t<am)throw new e("integer: negative integers are not allowed");let r=Qr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=dt;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return tt(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=dt;if(e!==void 0&&(lt(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let o=Z(t,void 0,"signature"),{v:i,l:a}=s.decode(48,o);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=s.decode(2,i),{v:f,l}=s.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=dt;Ie(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}},$s=(Object.freeze(dt._tlv),Object.freeze(dt._int),Object.freeze(dt));var Lf=(t,e)=>(t+(t>=0?e:-e)/_f)/e;function cm(t,e,r){nt("scalar",t,pt,r);let[[n,s],[o,i]]=e,a=Lf(i*t,r),c=Lf(-s*t,r),u=t-a*n-c*o,f=-a*s-c*i,l=u<pt,d=f<pt;l&&(u=-u),d&&(f=-f);let p=en(Math.ceil(Ar(r)/2))+nr;if(u<pt||u>=p||f<pt||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Ba(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function va(t,e){Ie(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ue(r.lowS,"lowS"),Ue(r.prehash,"prehash"),r.format!==void 0&&Ba(r.format),r}var pt=BigInt(0),nr=BigInt(1),_f=BigInt(2),Aa=BigInt(3),um=BigInt(4);function Tf(t,e={}){let r=_s("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;Ie(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:d,toBytes:p}=e,g=e.randomBytes===void 0?ft:e.randomBytes;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,m=If(n,s);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function E(S,h,y){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:v,y:O}=h.toAffine(),N=n.toBytes(v);if(Ue(y,"isCompressed"),y){x();let k=!n.isOdd(O);return qe(Cf(k),N)}else return qe(Uint8Array.of(4),N,n.toBytes(O))}function w(S){Z(S,void 0,"Point");let{publicKey:h,publicKeyUncompressed:y}=m,v=S.length,O=S[0],N=S.subarray(1);if(u&&v===1&&O===0)return{x:n.ZERO,y:n.ZERO};if(v===h&&(O===2||O===3)){let k=n.fromBytes(N);if(!n.isValid(k))throw new Error("bad point: is not on curve, wrong x");let q=U(k),z;try{z=n.sqrt(q)}catch(ce){let ie=ce instanceof Error?": "+ce.message:"";throw new Error("bad point: is not on curve, sqrt error"+ie)}x();let j=n.isOdd(z);return(O&1)===1!==j&&(z=n.neg(z)),{x:k,y:z}}else if(v===y&&O===4){let k=n.BYTES,q=n.fromBytes(N.subarray(0,k)),z=n.fromBytes(N.subarray(k,k*2));if(!I(q,z))throw new Error("bad point: is not on curve");return{x:q,y:z}}else throw new Error(`bad point: got length ${v}, expected compressed=${h} or uncompressed=${y}`)}let A=p===void 0?E:p,L=d===void 0?w:d,R=n.mul(o.b,Aa),M=n.is0(o.a)?S=>n.ZERO:S=>n.mul(o.a,S);function U(S){let h=n.sqr(S),y=n.mul(h,S);return n.add(n.add(y,n.mul(S,o.a)),o.b)}function I(S,h){let y=n.sqr(h),v=U(S);return n.eql(y,v)}if(!I(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let D=n.mul(n.pow(o.a,Aa),um),F=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(D,F)))throw new Error("bad curve params: a or b");function K(S,h,y=!1){if(!n.isValid(h)||y&&n.is0(h))throw new Error(`bad point coordinate ${S}`);return typeof h=="object"&&h!==null?n.create(h):h}function $(S){if(!(S instanceof B))throw new Error("Weierstrass Point expected")}function _(S){if(!b||!b.basises)throw new Error("no endo");return cm(S,b.basises,s.ORDER)}function P(S,h,y,v){if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:O,k1:N,k2neg:k,k2:q}=_(v),z=new B(n.mul(y.X,b.beta),y.Y,y.Z);S.push(O?y.negate():y,k?z.negate():z),h.push(N,q)}else S.push(y),h.push(v)}let T=new WeakSet;class B{static BASE=new B(o.Gx,o.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(h,y,v){this.X=K("x",h),this.Y=K("y",y,!0),this.Z=K("z",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(h){let{x:y,y:v}=h||{};if(!h||!n.isValid(y)||!n.isValid(v))throw new Error("invalid affine point");if(h instanceof B)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(v)?B.ZERO:new B(y,v,n.ONE)}static fromBytes(h){let y=B.fromAffine(L(Z(h,void 0,"point")));return y.assertValidity(),y}static fromHex(h){return B.fromBytes(vr(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,y=!0){return C.setWindowSize(this,h),y||this.multiply(Aa),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(T.has(h))return;let{x:y,y:v}=h.toAffine();if(!n.isValid(y)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!I(y,v))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");T.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){$(h);let{X:y,Y:v,Z:O}=this,{X:N,Y:k,Z:q}=h,z=n.eql(n.mul(y,q),n.mul(N,O)),j=n.eql(n.mul(v,q),n.mul(k,O));return z&&j}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:y,Z:v}=this,O=n.ZERO,N=n.ZERO,k=n.ZERO,q=n.mul(h,h),z=n.mul(y,y),j=n.mul(v,v),Y=n.mul(h,y);return Y=n.add(Y,Y),k=n.mul(h,v),k=n.add(k,k),O=M(k),N=n.mul(R,j),N=n.add(O,N),O=n.sub(z,N),N=n.add(z,N),N=n.mul(O,N),O=n.mul(Y,O),k=n.mul(R,k),j=M(j),Y=n.sub(q,j),Y=M(Y),Y=n.add(Y,k),k=n.add(q,q),q=n.add(k,q),q=n.add(q,j),q=n.mul(q,Y),N=n.add(N,q),j=n.mul(y,v),j=n.add(j,j),q=n.mul(j,Y),O=n.sub(O,q),k=n.mul(j,z),k=n.add(k,k),k=n.add(k,k),new B(O,N,k)}add(h){$(h);let{X:y,Y:v,Z:O}=this,{X:N,Y:k,Z:q}=h,z=n.ZERO,j=n.ZERO,Y=n.ZERO,ce=n.mul(y,N),ie=n.mul(v,k),ye=n.mul(O,q),Pe=n.add(y,v),ae=n.add(N,k);Pe=n.mul(Pe,ae),ae=n.add(ce,ie),Pe=n.sub(Pe,ae),ae=n.add(y,O);let he=n.add(N,q);return ae=n.mul(ae,he),he=n.add(ce,ye),ae=n.sub(ae,he),he=n.add(v,O),z=n.add(k,q),he=n.mul(he,z),z=n.add(ie,ye),he=n.sub(he,z),Y=M(ae),z=n.mul(R,ye),Y=n.add(z,Y),z=n.sub(ie,Y),Y=n.add(ie,Y),j=n.mul(z,Y),ie=n.add(ce,ce),ie=n.add(ie,ce),ye=M(ye),ae=n.mul(R,ae),ie=n.add(ie,ye),ye=n.sub(ce,ye),ye=M(ye),ae=n.add(ae,ye),ce=n.mul(ie,ae),j=n.add(j,ce),ce=n.mul(he,ae),z=n.mul(Pe,z),z=n.sub(z,ce),ce=n.mul(Pe,ie),Y=n.mul(he,Y),Y=n.add(Y,ce),new B(z,j,Y)}subtract(h){return $(h),this.add(h.negate())}is0(){return this.equals(B.ZERO)}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:y,f:v}=C.mulSecret(this,h,i,H);return H([y,v])[0]}multiplyUnsafe(h){let y=this,v=h;if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===pt||y.is0())return B.ZERO;if(v===nr)return y;if(C.hasWindowSize(this))return C.mulUnsafe(y,v,H);let O=[],N=[];return P(O,N,y,v),Ls(B,O,N)}mulAddUnsafe(h,y,v){$(y);let O=[],N=[];return P(O,N,this,h),P(O,N,y,v),Ls(B,O,N)}toAffine(h){let y=this,v=h;if(v!=null&&!n.isValid(v))throw new RangeError('"invertedZ" expected valid field element');let{X:O,Y:N,Z:k}=y;if(n.eql(k,n.ONE))return{x:O,y:N};let q=y.is0();v==null&&(v=q?n.ONE:n.inv(k));let z=n.mul(O,v),j=n.mul(N,v),Y=n.mul(k,v);if(q)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Y,n.ONE))throw new Error("invZ was invalid");return{x:z,y:j}}isTorsionFree(){return i===nr?!0:l?l(B,this):C.mulUnsafe(this,a).is0()}clearCofactor(){return i===nr?this:f?f(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===nr?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Ue(h,"isCompressed"),this.assertValidity(),A(B,this,h)}toHex(h=!0){return Xr(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let H=S=>Bs(B,S),C=new _r(B,g);return C.bits>=6&&B.BASE.precompute(6),Object.freeze(B.prototype),Object.freeze(B),B}function Cf(t){return Uint8Array.of(t?2:3)}function If(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function fm(t,e={}){Ct(t);let{Fn:r}=t,n=e.randomBytes===void 0?ft:e.randomBytes,s=Object.assign(If(t.Fp,r),{seed:Math.max(vs(r.ORDER),16)});function o(p){try{let g=r.fromBytes(p);return r.isValidNot0(g)}catch{return!1}}function i(p,g){let{publicKey:b,publicKeyUncompressed:m}=s;try{let x=p.length;return g===!0&&x!==b||g===!1&&x!==m?!1:!t.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(s.seed):p,As(Z(p,s.seed,"seed"),r.ORDER)}function c(p,g=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(g)}function u(p){let{secretKey:g,publicKey:b,publicKeyUncompressed:m}=s,x=r._lengths;if(!Lt(p))return;let E=Z(p,void 0,"key").length,w=E===b||E===m,A=E===g||!!x?.includes(E);if(!(w&&A))return w}function f(p,g,b=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(g)===!1)throw new Error("second arg must be public key");let m=r.fromBytes(p),x=t.fromBytes(g);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(m).toBytes(b)}let l={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},d=Tr(a,c);return Object.freeze(l),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:t,utils:l,lengths:s})}function Df(t,e,r={}){Ct(t);let n=e;jt(n),Ie(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?ft:s.randomBytes,i=s.hmac===void 0?(S,h)=>on(n,S,h):s.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=vs(u),d=Ni(o,l),{keygen:p,getPublicKey:g,getSharedSecret:b,utils:m,lengths:x}=fm(t,s),E={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},w=u*_f+nr<a.ORDER;function A(S){let h=u>>nr;return S>h}function L(S,h){if(!c.isValidNot0(h))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return h}function R(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(S,h,y){return R(),(S===y?0:2)|Number(a.isOdd(h))}function U(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function I(S,h){Ba(h);let y=x.signature,v=h==="compact"?y:h==="recovered"?y+1:void 0;return Z(S,v)}class D{r;s;recovery;constructor(h,y,v){if(this.r=L("r",h),this.s=L("s",y),v!=null){if(U(),![0,1,2,3].includes(v))throw new Error("invalid recovery id");this.recovery=v}Object.freeze(this)}static fromBytes(h,y=E.format){I(h,y);let v;if(y==="der"){if(h.length>2*c.BYTES+16)throw new $s.Err("invalid signature: DER signature too long");let{r:q,s:z}=$s.toSig(Z(h),c.BYTES+1);return new D(q,z)}y==="recovered"&&(v=h[0],y="compact",h=h.subarray(1));let O=x.signature/2,N=h.subarray(0,O),k=h.subarray(O,O*2);return new D(c.fromBytes(N),c.fromBytes(k),v)}static fromHex(h,y){return this.fromBytes(vr(h),y)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new D(this.r,this.s,h)}recoverPublicKey(h){let{r:y,s:v}=this,O=this.assertRecovery(),N=O===2||O===3?y+u:y;if(!a.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=a.toBytes(N),q=t.fromBytes(qe(Cf((O&1)===0),k)),z=c.inv(N),j=K(Z(h,void 0,"msgHash")),Y=c.create(-j*z),ce=c.create(v*z),ie=t.BASE.mulAddUnsafe(Y,q,ce);if(ie.is0())throw new Error("invalid recovery: point at infinify");return ie.assertValidity(),ie}hasHighS(){return A(this.s)}toBytes(h=E.format){if(Ba(h),h==="der")return vr($s.hexFromSig(this));let{r:y,s:v}=this,O=c.toBytes(y),N=c.toBytes(v);return h==="recovered"?(U(),qe(Uint8Array.of(this.assertRecovery()),O,N)):qe(O,N)}toHex(h){return Xr(this.toBytes(h))}}Object.freeze(D.prototype),Object.freeze(D);let F=s.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let y=tt(h),v=h.length*8-f;return v>0?y>>BigInt(v):y}:s.bits2int,K=s.bits2int_modN===void 0?function(h){return c.create(F(h))}:s.bits2int_modN,$=en(f);function _(S){return nt("num < 2^"+f,S,pt,$),c.toBytes(S)}function P(S,h){return Z(S,void 0,"message"),h?Z(n(S),void 0,"prehashed message"):S}function T(S,h,y){let{lowS:v,prehash:O,extraEntropy:N}=va(y,E);S=P(S,O);let k=K(S),q=c.fromBytes(h);if(!c.isValidNot0(q))throw new Error("invalid private key");let z=[_(q),_(k)];if(N!=null&&N!==!1){let ie=N===!0?o(x.secretKey):N;z.push(Z(ie,void 0,"extraEntropy"))}let j=qe(...z),Y=k;function ce(ie){let ye=F(ie);if(!c.isValidNot0(ye))return;let Pe=t.BASE.multiply(ye).toAffine(),ae=c.create(Pe.x);if(ae===pt)return;let he;if(d!==void 0){let mt=tt(As(d(l),u)),Jf=c.inv(c.mul(mt,ye)),el=c.mul(mt,Y),tl=c.mul(mt,q);he=c.create(Jf*c.create(el+tl*ae))}else{let mt=Cu(ye,u);he=c.create(mt*c.create(Y+ae*q))}if(he===pt)return;let or=M(Pe.x,Pe.y,ae),Nr=he;return v&&A(he)&&(Nr=c.neg(he),or^=1),new D(ae,Nr,w?void 0:or)}return{seed:j,k2sig:ce}}function B(S,h,y={}){let{seed:v,k2sig:O}=T(S,h,y);return Eu(n.outputLen,c.BYTES,i)(v,O).toBytes(y.format)}function H(S,h,y,v={}){let{lowS:O,prehash:N,format:k}=va(v,E);if(y=Z(y,void 0,"publicKey"),h=P(h,N),!Lt(S)){let q=S instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}I(S,k);try{let q=D.fromBytes(S,k),z=t.fromBytes(y);if(z.is0()||O&&q.hasHighS())return!1;let{r:j,s:Y}=q,ce=K(h),ie=c.inv(Y),ye=c.create(ce*ie),Pe=c.create(j*ie),ae=t.BASE.mulAddUnsafe(ye,z,Pe);if(ae.is0())return!1;let he=ae.toAffine();return!(c.create(he.x)!==j||k==="recovered"&&q.recovery!==M(he.x,he.y,j))}catch{return!1}}function C(S,h,y={}){let{prehash:v}=va(y,E);return h=P(h,v),D.fromBytes(S,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:p,getPublicKey:g,getSharedSecret:b,utils:m,lengths:x,Point:t,sign:B,verify:H,recoverPublicKey:C,Signature:D,hash:n})}var _a={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},lm={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Rf=BigInt(2);function hm(t){let e=_a.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=le(f,r,e)*f%e,d=le(l,r,e)*f%e,p=le(d,Rf,e)*u%e,g=le(p,s,e)*p%e,b=le(g,o,e)*g%e,m=le(b,a,e)*b%e,x=le(m,c,e)*m%e,E=le(x,a,e)*b%e,w=le(E,r,e)*f%e,A=le(w,i,e)*g%e,L=le(A,n,e)*u%e,R=le(L,Rf,e);if(!La.eql(La.sqr(R),t))throw new Error("Cannot find square root");return R}var La=Lr(_a.p,{sqrt:hm}),dm=Tf(_a,{Fp:La,endo:lm}),Ur=Df(dm,et);function Of(t,e,r,n){let s=Fr.digest(r instanceof Uint8Array?r:r.subarray());if(Ms(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),Ur.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new ln(String(o))});try{return n?.signal?.throwIfAborted(),Ur.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new ln(String(o))}}var Vs=class{type="secp256k1";raw;_key;constructor(e){this._key=Uf(e),this.raw=Pf(this._key)}toMultihash(){return je.digest(Dt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}verify(e,r,n){return Of(this._key,r,e,n)}};function Ta(t){return new Vs(t)}function Pf(t){return Ur.Point.fromBytes(t).toBytes()}function Uf(t){try{return Ur.Point.fromBytes(t),t}catch(e){throw new Ot(String(e))}}function Nf(t,e){let{Type:r,Data:n}=st.decode(t),s=n??new Uint8Array;switch(r){case de.RSA:return wa(s,e);case de.Ed25519:return Ji(s);case de.secp256k1:return Ta(s);case de.ECDSA:return Zi(s);default:throw new Ut}}function kf(t){let{Type:e,Data:r}=st.decode(t.digest),n=r??new Uint8Array;switch(e){case de.Ed25519:return Ji(n);case de.secp256k1:return Ta(n);case de.ECDSA:return Zi(n);default:throw new Ut}}function Dt(t){return st.encode({Type:de[t.type],Data:t.raw})}var Mf=Symbol.for("nodejs.util.inspect.custom"),pm=114,gn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Zs]=!0;toString(){return this.string==null&&(this.string=me.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return xe.createV1(pm,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return we(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return we(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Mf](){return`PeerId(${this.toString()})`}},bn=class extends gn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},wn=class extends gn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},xn=class extends gn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},mm=2336,En=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=je.digest(ee(this.url))}[Mf](){return`PeerId(${this.url})`}[Zs]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return xe.createV1(mm,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=W(e)),e.toString()===this.toString())}};var ym=114,Kf=2336;function Ff(t,e){let r;if(t.charAt(0)==="1"||t.charAt(0)==="Q")r=hr(me.decode(`z${t}`));else{if(t.startsWith("k51qzi5uqu5")||t.startsWith("kzwfwjn5ji4")||t.startsWith("k2k4r8")||t.startsWith("bafz"))return gm(xe.parse(t));if(e==null)throw new se('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=hr(e.decode(t))}return qf(r)}function Hf(t){if(t.type==="Ed25519")return new wn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new xn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new bn({multihash:t.toCID().multihash,publicKey:t});throw new Ut}function qf(t){if(wm(t))return new bn({multihash:t});if(bm(t))try{let e=kf(t);if(e.type==="Ed25519")return new wn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new xn({multihash:t,publicKey:e})}catch{let r=W(t.digest);return new En(new URL(r))}throw new Cn("Supplied PeerID Multihash is invalid")}function gm(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==ym&&t.code!==Kf)throw new Tn("Supplied PeerID CID is invalid");if(t.code===Kf){let e=W(t.multihash.digest);return new En(new URL(e))}return qf(t.multihash)}function bm(t){return t.code===je.code}function wm(t){return t.code===Fr.code}var Sn;(function(t){let e;t.codec=()=>(e==null&&(e=tr((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.webtransportCerthashes!=null&&o.webtransportCerthashes.length>0)for(let c of o.webtransportCerthashes)i.uint32(10),i.bytes(c);if(o.streamMuxers!=null&&o.streamMuxers.length>0)for(let c of o.streamMuxers)i.uint32(18),i.string(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={webtransportCerthashes:[],streamMuxers:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.webtransportCerthashes!=null&&c.webtransportCerthashes.length===a.limits.webtransportCerthashes)throw new rr('Decode error - repeated field "webtransportCerthashes" had too many elements');c.webtransportCerthashes.push(o.bytes());break}case 2:{if(a.limits?.streamMuxers!=null&&c.streamMuxers.length===a.limits.streamMuxers)throw new rr('Decode error - repeated field "streamMuxers" had too many elements');c.streamMuxers.push(o.string());break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={webtransportCerthashes:0,streamMuxers:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{if(c.limits?.webtransportCerthashes!=null&&u.webtransportCerthashes===c.limits.webtransportCerthashes)throw new rr('Streaming decode error - repeated field "webtransportCerthashes" had too many elements');yield{field:`${a}.webtransportCerthashes[]`,index:u.webtransportCerthashes,value:o.bytes()},u.webtransportCerthashes++;break}case 2:{if(c.limits?.streamMuxers!=null&&u.streamMuxers===c.limits.streamMuxers)throw new rr('Streaming decode error - repeated field "streamMuxers" had too many elements');yield{field:`${a}.streamMuxers[]`,index:u.streamMuxers,value:o.string()},u.streamMuxers++;break}default:{o.skipType(l&7);break}}}})),e);function r(o){return Jt(o,t.codec())}t.encode=r;function n(o,i){return Xt(o,t.codec(),i)}t.decode=n;function s(o,i){return er(o,t.codec(),i)}t.stream=s})(Sn||(Sn={}));var vn;(function(t){let e;t.codec=()=>(e==null&&(e=tr((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.identityKey!=null&&o.identityKey.byteLength>0&&(i.uint32(10),i.bytes(o.identityKey)),o.identitySig!=null&&o.identitySig.byteLength>0&&(i.uint32(18),i.bytes(o.identitySig)),o.extensions!=null&&(i.uint32(34),Sn.codec().encode(o.extensions,i)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={identityKey:be(0),identitySig:be(0)},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.identityKey=o.bytes();break}case 2:{c.identitySig=o.bytes();break}case 4:{c.extensions=Sn.codec().decode(o,o.uint32(),{limits:a.limits?.extensions});break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.identityKey`,value:o.bytes()};break}case 2:{yield{field:`${a}.identitySig`,value:o.bytes()};break}case 4:{yield*Sn.codec().stream(o,o.uint32(),`${a}.extensions`,{limits:c.limits?.extensions});break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Jt(o,t.codec())}t.encode=r;function n(o,i){return Xt(o,t.codec(),i)}t.decode=n;function s(o,i){return er(o,t.codec(),i)}t.stream=s})(vn||(vn={}));async function Ia(t,e,r){let n=await t.sign($f(e));return vn.encode({identityKey:Dt(t.publicKey),identitySig:n,extensions:r})}async function Da(t,e,r){try{let n=vn.decode(t),s=Nf(n.identityKey),o=Hf(s);if(r!=null&&!r.equals(o))throw new Error(`Payload peer id ${o} does not match expected remote peer id ${r}`);if(!e)throw new Error("Remote static does not exist");let i=$f(e);if(!await s.verify(i,n.identitySig))throw new Error("Invalid payload signature");return{payload:n,remotePeer:o}}catch(n){throw new An(n.message)}}function $f(t){let e=ee("noise-libp2p-static-key:");return t instanceof Uint8Array?Me([e,t],e.length+t.length):(t.prepend(e),t)}var Ca=class extends Xe{stream;handshake;metrics;decoder;constructor(e,r,n){super({log:e.log,inactivityTimeout:e.inactivityTimeout,maxReadBufferLength:e.maxReadBufferLength,direction:e.direction}),this.stream=e,this.handshake=r,this.metrics=n,this.decoder=new cs({lengthDecoder:Ir,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let u of this.decoder.decode(c.data))this.onData(this.decrypt(u))}catch(u){this.abort(u)}};this.stream.addEventListener("message",s);let o=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",o);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let r=new Q;for(let n=0;n<e.byteLength;n+=65519){let s=n+65519;s>e.byteLength&&(s=e.byteLength);let o;e instanceof Uint8Array?o=this.handshake.encrypt(e.subarray(n,s)):o=this.handshake.encrypt(e.sublist(n,s)),this.metrics?.encryptedPackets.increment(),r.append(Cr(o.byteLength)),r.append(o)}return r}decrypt(e){let r=new Q;for(let n=0;n<e.byteLength;n+=65535){let s=n+65535;if(s>e.byteLength&&(s=e.byteLength),s-li<n)throw new Error("Invalid chunk");let o;e instanceof Uint8Array?o=e.subarray(n,s):o=e.sublist(n,s);let i=e.subarray(n,s-li);try{let a=this.handshake.decrypt(o,i);this.metrics?.decryptedPackets.increment(),r.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return r}close(e){return this.stream.close(e)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(e){this.stream.abort(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.stream.send(this.encrypt(e))}}};function Ra(t,e,r){return new Ca(t,e,r)}async function Vf(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remotePeer:c,extensions:u}=t,f=await Ia(o,a.publicKey,u),l=new cn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Ki(l.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(l.writeMessageA(Gt),e),r.trace("Stage 0 - Initiator finished sending first message."),Fi(l.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let d=l.readMessageB(await n.read(e));r.trace("Stage 1 - Initiator received the message."),Hi(l.re,r),rf(l.rs,r),r.trace("Initiator going to check remote's signature...");let p=await Da(d,l.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(l.writeMessageC(f),e),r.trace("Stage 2 - Initiator sent message with signed payload.");let[g,b]=l.ss.split();return qi(g,b,r),{payload:p.payload,remotePeer:p.remotePeer,encrypt:m=>g.encryptWithAd(Gt,m),decrypt:(m,x)=>b.decryptWithAd(Gt,m,x)}}async function jf(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remotePeer:c,extensions:u}=t,f=await Ia(o,a.publicKey,u),l=new cn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Ki(l.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await n.read(e)),r.trace("Stage 0 - Responder received first message."),Hi(l.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(l.writeMessageB(f),e),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Fi(l.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let d=l.readMessageC(await n.read(e));r.trace("Stage 2 - Responder received the message, finished handshake.");let p=await Da(d,l.rs,c),[g,b]=l.ss.split();return qi(g,b,r),{payload:p.payload,remotePeer:p.remotePeer,encrypt:m=>b.encryptWithAd(Gt,m),decrypt:(m,x)=>g.decryptWithAd(Gt,m,x)}}var Ws=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(e,r={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=r,{metrics:a}=e;this.components=e,this.log=e.logger.forComponent("libp2p:noise");let c=o??Ju;this.crypto=ef(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?tf(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??be(0)}[Symbol.toStringTag]="@libp2p/noise";[On]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,r){let n=e.log?.newScope("noise")??this.log,s=fi(e,{lengthEncoder:Cr,lengthDecoder:Ir,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer,r);return{connection:Ra(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:o.remotePeer,streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let r=this.components.upgrader.getStreamMuxers();if(r!=null)for(let n of e){let s=r.get(n);if(s!=null)return s}if(e.length)throw new ir("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,r){let n=e.log?.newScope("noise")??this.log,s=fi(e,{lengthEncoder:Cr,lengthDecoder:Ir,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer,r);return{connection:Ra(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:o.remotePeer,streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Vf({connection:e,privateKey:r,remotePeer:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}async performHandshakeResponder(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await jf({connection:e,privateKey:r,remotePeer:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}};function Wf(t={}){return e=>new Ws(e,t)}var sr=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function Oa(t){throw new Error("Not implemented")}var Pa=class extends is{writer;reader;constructor(e){super(e),this.writer=e.stream.writable.getWriter(),this.reader=e.stream.readable.getReader(),this.writer.closed.then(()=>{this.log("writer closed gracefully")}).catch(r=>{r.message.includes("STOP_SENDING")||r.message.includes("StopSending")?this.onRemoteCloseRead():r.message.includes("RESET_STREAM")||r.message.includes("Reset")?this.onRemoteReset():this.log("writer close promise rejected - %e",r)}),this.readData()}readData(){Promise.resolve().then(async()=>{for(;;){let e=await this.reader.read();if(e.value!=null&&this.onData(e.value),e.done){this.log("remote closed write"),this.onRemoteCloseWrite();return}if(this.readStatus==="paused")break}}).catch(e=>{this.abort(e)}).finally(()=>{this.reader.releaseLock()})}sendData(e){for(let n of e)this.writer.write(n).catch(s=>{this.abort(s)});if(this.log.trace("desired size after sending %d bytes is %d bytes",e.byteLength,this.writer.desiredSize),this.writer.desiredSize==null)return{sentBytes:e.byteLength,canSendMore:!1};let r=this.writer.desiredSize>0;return r||this.writer.ready.then(()=>{this.safeDispatchEvent("drain")},n=>{this.abort(n)}),{sentBytes:e.byteLength,canSendMore:r}}sendReset(e){this.writer.abort(e).catch(r=>{this.log.error("error aborting writer - %e",r)})}async sendCloseWrite(e){this.log("sendCloseWrite closing writer"),await Fe(this.writer.close().catch(()=>{}),e?.signal),this.log("sendCloseWrite closed writer")}async sendCloseRead(e){this.log("sendCloseRead cancelling reader"),await Fe(this.reader.cancel(),e?.signal),this.log("sendCloseRead cancelled reader")}sendPause(){}sendResume(){this.readData()}};function Ua(t,e,r,n,s){return new Pa({...s,stream:t,id:e,direction:r,log:n.newScope(`${r}:${e}`),protocol:""})}var Yf="/webtransport",Na=class extends os{webTransport;streamIDCounter;reader;constructor(e,r){super(r,{protocol:Yf,name:"muxer"}),this.webTransport=e,this.streamIDCounter=0,this.reader=this.webTransport.incomingBidirectionalStreams.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:n,value:s}=await this.reader.read();if(n||s==null)break;this.onRemoteStream(Ua(s,String(this.streamIDCounter++),"inbound",this.log,this.streamOptions))}}).catch(n=>{this.log.error("could not create a new stream - %e",n)})}async onCreateStream(e){let r=await this.webTransport.createBidirectionalStream();return e?.signal?.throwIfAborted(),Ua(r,String(this.streamIDCounter++),"outbound",this.log,e)}onData(){}sendReset(){this.webTransport.close()}};function Gf(t){return{protocol:Yf,createStreamMuxer(e){return new Na(t,e)}}}var ka=class extends ss{cleanUpWTSession;constructor(e){super(e),this.cleanUpWTSession=e.cleanUpWTSession}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}sendReset(){this.cleanUpWTSession("abort")}async sendClose(e){this.cleanUpWTSession("close"),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}},Zf=t=>new ka(t);function Xf(t,e){return e.filter(n=>!!t.find(s=>we(n,s))).length===e.length}var xm=Object.values(Mt).map(t=>t.decoder).reduce((t,e)=>t.or(e));function Em(t){return ot.decode(xm.decode(t))}function Ma(t){if(!Qn.matches(t))throw new _n("Invalid multiaddr, was not a WebTransport address");let e=[],r;for(let o of t.getComponents())o.name==="certhash"&&e.push(Em(o.value??"")),o.name==="p2p"&&r==null&&(r=Ff(o.value??""));let n=hc(t),s=n.host;return n.type==="ip6"&&s.includes(":")&&(s=`[${s}]`),{url:`https://${s}:${n.port}`,certhashes:e,remotePeer:r}}var Ys=class extends Xe{writer;reader;constructor(e){super(e),this.writer=e.stream.writable.getWriter(),this.reader=e.stream.readable.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:r,value:n}=await this.reader.read();if(n!=null&&this.onData(n),r)break}}).catch(r=>{this.abort(r)})}async close(e){await Fe(this.writer.close(),e?.signal)}sendData(e){return this.writer.write(e.subarray()).catch(r=>{this.abort(r)}),{sentBytes:e.byteLength,canSendMore:!0}}sendReset(e){this.writer.abort(e).catch(r=>{this.log.error("could not send reset - %e",r)})}sendPause(){}sendResume(){}};var Qf=globalThis.WebTransport;var Ka=class{log;components;config;metrics;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:webtransport"),this.components=e,this.config={...r,certificates:r.certificates??[]},e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webtransport_dialer_events_total",{label:"event",help:"Total count of WebTransport dialer events by type"})})}[Symbol.toStringTag]="@libp2p/webtransport";[Ha]=!0;[On]=["@libp2p/transport"];async dial(e,r){r.signal.throwIfAborted(),this.log("dialing %s",e),r=r??{};let{url:n,certhashes:s,remotePeer:o}=Ma(e),i,a,c=()=>{},u=!1,f=!1,l=!1;try{this.metrics?.dialerEvents.increment({pending:!0});let d=new Qf(`${n}/.well-known/libp2p-webtransport?type=noise`,{serverCertificateHashes:s.map(g=>({algorithm:"sha-256",value:Ae(g.digest)}))});c=g=>{if(!u)try{this.metrics?.dialerEvents.increment({[g]:!0}),d.close()}catch(b){this.log.error("error closing wt session - %e",b)}finally{a!=null&&(a.timeline.close=Date.now()),u=!0}},i=()=>{c(f?"noise_timeout":"ready_timeout")},r.signal.addEventListener("abort",i,{once:!0}),this.log("wait for session to be ready"),r.onProgress?.(new sr("webtransport:wait-for-session")),await Promise.race([d.closed,d.ready]),this.log("session became ready"),f=!0,this.metrics?.dialerEvents.increment({ready:!0}),d.closed.catch(g=>{this.log.error("error on remote wt session close - %e",g)}).finally(()=>{c("remote_close")}),this.metrics?.dialerEvents.increment({open:!0}),a=Zf({remoteAddr:e,cleanUpWTSession:c,direction:"outbound",log:this.components.logger.forComponent("libp2p:webtransport:connection")});let p=await this.authenticateWebTransport({wt:d,maConn:a,remotePeer:o,certhashes:s,...r});if(l=!0,o!=null&&(l=o.equals(p)),!l)throw new ir("Failed to authenticate webtransport");return await r.upgrader.upgradeOutbound(a,{...r,skipEncryption:!0,remotePeer:p,muxerFactory:Gf(d),skipProtection:!0})}catch(d){throw this.log.error("caught wt session err - %e",d),c(l?"upgrade_error":f?"noise_error":"ready_error"),d}finally{i!=null&&r.signal?.removeEventListener("abort",i)}}async authenticateWebTransport({wt:e,maConn:r,remotePeer:n,certhashes:s,onProgress:o,signal:i}){o?.(new sr("webtransport:open-authentication-stream"));let a=await e.createBidirectionalStream();i?.throwIfAborted();let c=new Ys({stream:a,log:r.log.newScope("muxer")}),u=Wf()(this.components);o?.(new sr("webtransport:secure-outbound-connection"));let{remoteExtensions:f,remotePeer:l}=await u.secureOutbound(c,{signal:i,remotePeer:n,skipStreamMuxerNegotiation:!0});if(o?.(new sr("webtransport:close-authentication-stream")),await c.close({signal:i}),!Xf(f?.webtransportCerthashes??[],s.map(d=>d.bytes)))throw new se("Our certhashes are not a subset of the remote's reported certhashes");return l}createListener(e){return Oa(this.components,{...e,certificates:this.config.certificates})}listenFilter(){return[]}dialFilter(e){return globalThis.WebTransport==null?[]:e.filter(r=>{if(!Qn.exactMatch(r))return!1;let{url:n,certhashes:s}=Ma(r);return n!=null&&s.length>0})}};function Sm(t={}){return e=>new Ka(e,t)}return il(vm);})();
2
+ "use strict";var Libp2PWebtransport=(()=>{var Gs=Object.defineProperty;var tl=Object.getOwnPropertyDescriptor;var rl=Object.getOwnPropertyNames;var nl=Object.prototype.hasOwnProperty;var Re=(t,e)=>{for(var r in e)Gs(t,r,{get:e[r],enumerable:!0})},sl=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of rl(e))!nl.call(t,s)&&s!==r&&Gs(t,s,{get:()=>e[s],enumerable:!(n=tl(e,s))||n.enumerable});return t};var ol=t=>sl(Gs({},"__esModule",{value:!0}),t);var Bm={};Re(Bm,{webTransport:()=>Am});var An=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},ir=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},se=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ot=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Bn=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Ln=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var yt=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Pt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var _n=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},Tn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Cn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Ut=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var In=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},ar=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Dn=class extends ar{constructor(e,r){super(!0,e,r)}},Rn=class extends ar{constructor(e,r){super(!1,e,r)}};var Zs=Symbol.for("@libp2p/peer-id");var Ha=Symbol.for("@libp2p/transport");var Fa;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(Fa||(Fa={}));function il(t){return typeof t?.handleEvent=="function"}function al(t){return t===!0||t===!1}function cl(t){return al(t)?t:t?.capture??!1}function Xs(t){let e={capture:cl(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function qa(t,e){return Xs(t).capture===Xs(e).capture}var cr=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let s=Xs(n);if(s?.signal?.aborted===!0)return;let o=u=>{s.once&&this.removeEventListener(e,r,s),il(r)?r.handleEvent(u):r(u)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(u=>u.callback!==r?!1:qa(u.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,r,s)};s.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:o,options:s,onAbort:c})}removeEventListener(e,r,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,s.filter(o=>o.callback===r&&qa(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var On=Symbol.for("@libp2p/service-capabilities");function be(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function ul(t){return t?.buffer instanceof ArrayBuffer}function Qs(t){if(ul(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Me(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=Se(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return Qs(r)}function we(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var $a=Symbol.for("@achingbrain/uint8arraylist");function za(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let s=r+n.byteLength;if(e<s)return{buf:n,index:e-r};r=s}throw new RangeError("index is out of bounds")}function Pn(t){return!!t?.[$a]}var Q=class t{bufs;length;[$a]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Pn(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Pn(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(e){let r=za(this.bufs,e);return r.buf[r.index]}set(e,r){let n=za(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Pn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:s}=this._subList(e,r);return Me(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:Me(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Pn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let l=0;l<o;l++)i[l]=-1;for(let l=0;l<s;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){f=Math.max(1,d-a[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let s=be(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let s=be(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!we(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var no={};Re(no,{base10:()=>gl});var d0=new Uint8Array(0);function ja(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ke(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Nt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Nt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Wa(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Va=4096;function Ya(t){let e=t.length;if(e<=Va)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Va));return r}function fl(t){return t?.buffer instanceof ArrayBuffer}function Nt(t){return fl(t)?t:t.slice()}function ll(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),u!==a&&(n[u]=o)}}var f=t.length,l=t.charAt(0),d=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function b(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var E=0,w=0,A=0,L=x.length;A!==L&&x[A]===0;)A++,E++;for(var R=(L-A)*p+1>>>0,q=new Uint8Array(R);A!==L;){for(var O=x[A],I=0,D=R-1;(O!==0||I<w)&&D!==-1;D--,I++)O+=256*q[D]>>>0,q[D]=O%f>>>0,O=O/f>>>0;if(O!==0)throw new Error("Non-zero carry");w=I,A++}for(var k=R-w;k!==R&&q[k]===0;)k++;for(var K=l.repeat(E);k<R;++k)K+=t.charAt(q[k]);return K}function g(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var E=0;if(x[E]!==" "){for(var w=0,A=0;x[E]===l;)w++,E++;for(var L=(x.length-E)*d+1>>>0,R=new Uint8Array(L);x[E];){var q=x.charCodeAt(E);if(q>255)return;var O=n[q];if(O===255)return;for(var I=0,D=L-1;(O!==0||I<A)&&D!==-1;D--,I++)O+=f*R[D]>>>0,R[D]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");A=I,E++}if(x[E]!==" "){for(var k=L-A;k!==L&&R[k]===0;)k++;for(var K=new Uint8Array(w+(L-k)),z=w;k!==L;)K[z++]=R[k++];return K}}}function m(x){var E=g(x);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:b,decodeUnsafe:g,decode:m}}var hl=ll,dl=hl,Za=dl;var Js=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},eo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xa(this,e)}},to=class{decoders;constructor(e){this.decoders=e}or(e){return Xa(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xa(t,e){return new to({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ro=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new Js(e,r,n),this.decoder=new eo(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ur({name:t,prefix:e,encode:r,decode:n}){return new ro(t,e,r,n)}function gt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=Za(r,t,n);return ur({prefix:e,name:t,encode:s,decode:i=>Ke(o(i))})}function pl(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function ml(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function yl(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let s=t[n].toLowerCase(),o=t[n].toUpperCase();s!==t[n]&&(r[s]=n),o!==t[n]&&(r[o]=n)}return r}function pe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=yl(n,s);return ur({prefix:e,name:t,encode(i){return ml(i,n,r)},decode(i){return pl(i,o,r,t)}})}var gl=gt({prefix:"9",name:"base10",alphabet:"0123456789"});var so={};Re(so,{base16:()=>bl,base16upper:()=>wl});var bl=pe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),wl=pe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var oo={};Re(oo,{base2:()=>xl});var xl=pe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var io={};Re(io,{base256emoji:()=>Bl});var Qa=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}"),El=Qa.reduce((t,e,r)=>(t[r]=e,t),[]),Sl=Qa.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function vl(t){return t.reduce((e,r)=>(e+=El[r],e),"")}function Al(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Sl[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var Bl=ur({prefix:"\u{1F680}",name:"base256emoji",encode:vl,decode:Al});var ao={};Re(ao,{base32:()=>bt,base32hex:()=>Cl,base32hexpad:()=>Dl,base32hexpadupper:()=>Rl,base32hexupper:()=>Il,base32pad:()=>_l,base32padupper:()=>Tl,base32upper:()=>Ll,base32z:()=>Ol});var bt=pe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Ll=pe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),_l=pe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Tl=pe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Cl=pe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Il=pe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Dl=pe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Rl=pe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Ol=pe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var co={};Re(co,{base36:()=>kr,base36upper:()=>Pl});var kr=gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Pl=gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var uo={};Re(uo,{base58btc:()=>me,base58flickr:()=>Ul});var me=gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ul=gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lo={};Re(lo,{base64:()=>Nl,base64pad:()=>kl,base64url:()=>fo,base64urlpad:()=>Ml});var Nl=pe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),kl=pe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fo=pe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ml=pe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ho={};Re(ho,{base8:()=>Kl});var Kl=pe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var po={};Re(po,{identity:()=>Fl});var Fl=ur({prefix:"\0",name:"identity",encode:t=>Ya(Ke(t)),decode:t=>Ke(Wa(t))});var C0=new TextEncoder,I0=new TextDecoder;var go={};Re(go,{identity:()=>je});var ot={};Re(ot,{Digest:()=>kt,create:()=>Ve,decode:()=>hr,equals:()=>yo,hasCode:()=>ah});var zl=tc,Ja=128,$l=127,Vl=~$l,jl=Math.pow(2,31);function tc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=jl;)e[r++]=t&255|Ja,t/=128;for(;t&Vl;)e[r++]=t&255|Ja,t>>>=7;return e[r]=t|0,tc.bytes=r-n+1,e}var Wl=mo,Yl=128,ec=127;function mo(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw mo.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&ec)<<s:(i&ec)*Math.pow(2,s),s+=7}while(i>=Yl);return mo.bytes=o-n,r}var Gl=Math.pow(2,7),Zl=Math.pow(2,14),Xl=Math.pow(2,21),Ql=Math.pow(2,28),Jl=Math.pow(2,35),eh=Math.pow(2,42),th=Math.pow(2,49),rh=Math.pow(2,56),nh=Math.pow(2,63),sh=function(t){return t<Gl?1:t<Zl?2:t<Xl?3:t<Ql?4:t<Jl?5:t<eh?6:t<th?7:t<rh?8:t<nh?9:10},oh={encode:zl,decode:Wl,encodingLength:sh},ih=oh,Mr=ih;function Kr(t,e=0){let r=Mr.decode(t,e),n=Mr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function fr(t,e,r=0){return Mr.encode(t,e,r),e}function lr(t){return Mr.encodingLength(t)}function Ve(t,e){let r=e.byteLength,n=lr(t),s=n+lr(r),o=new Uint8Array(s+r);return fr(t,o,0),fr(r,o,n),o.set(e,s),new kt(t,r,e,o)}function hr(t){let e=Ke(t),[r,n]=Kr(e),[s,o]=Kr(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new kt(r,s,i,e)}function yo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ja(t.bytes,r.bytes)}}var kt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=Nt(n),this.bytes=Nt(s)}};function ah(t,e){return t.code===e}var rc=0,ch="identity",nc=Ke;function uh(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ve(rc,nc(t))}var je={code:rc,name:ch,encode:nc,digest:uh};var xo={};Re(xo,{sha256:()=>Fr,sha512:()=>lh});var fh=20;function wo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new bo(t,e,r,n,s)}var bo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??fh,this.maxDigestLength=o}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?sc(n,this.code,r?.truncate):n.then(s=>sc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function sc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ve(e,t)}function ic(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Fr=wo({name:"sha2-256",code:18,encode:ic("SHA-256")}),lh=wo({name:"sha2-512",code:19,encode:ic("SHA-512")});function ac(t,e){let{bytes:r,version:n}=t;return n===0?dh(r,Eo(t),e??me.encoder):ph(r,Eo(t),e??bt.encoder)}var cc=new WeakMap;function Eo(t){let e=cc.get(t);if(e==null){let r=new Map;return cc.set(t,r),r}return e}var xe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=Nt(s),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:e,multihash:r}=this;if(e!==Hr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==mh)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=Ve(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&yo(e.multihash,n.multihash)}toString(e){return ac(this,e)}toJSON(){return{"/":ac(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new t(n,s,o,i??uc(n,s,o.bytes))}else if(r[yh]===!0){let{version:n,multihash:s,code:o}=r,i=hr(s);return t.create(n,o,i)}else return null}static create(e,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(e){case 0:{if(r!==Hr)throw new Error(`Version 0 CID must use dag-pb (code: ${Hr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=uc(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Hr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Ke(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new kt(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,d]=Kr(e.subarray(r));return r+=d,l},s=n(),o=Hr;if(s===18)s=0,r=0;else if(s===1)o=n();else throw s===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,s]=hh(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Eo(o).set(n,e),o}};function hh(t,e){switch(t[0]){case"Q":{let r=e??me;return[me.prefix,r.decode(`${me.prefix}${t}`)]}case me.prefix:{let r=e??me;return[me.prefix,r.decode(t)]}case bt.prefix:{let r=e??bt;return[bt.prefix,r.decode(t)]}case kr.prefix:{let r=e??kr;return[kr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function dh(t,e,r){let{prefix:n}=r;if(n!==me.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function ph(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var Hr=112,mh=18;function uc(t,e,r){let n=lr(t),s=n+lr(e),o=new Uint8Array(s+r.byteLength);return fr(t,o,0),fr(e,o,n),o.set(r,s),o}var yh=Symbol.for("@ipld/js-cid/CID");var Mt={...po,...oo,...ho,...no,...so,...ao,...co,...uo,...lo,...io},Q0={...xo,...go};function lc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var fc=lc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),So=lc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),gh={utf8:fc,"utf-8":fc,hex:Mt.base16,latin1:So,ascii:So,binary:So,...Mt},Nn=gh;function ee(t,e="utf8"){let r=Nn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function bh(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function hc(t){let e=bh(t);if(e==null)throw new se(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var kn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();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(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(f===void 0)break;if(o*=e,o+=f,o>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let s=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[s]=i[0],r[s+1]=i[1],r[s+2]=i[2],r[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];r[s]=o>>8,r[s+1]=o&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,s]=e(r);if(n===16)return r;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=e(o.subarray(0,i));return r.set(o.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var wh=45,xh=15,Mn=new kn;function dc(t){if(!(t.length>xh))return Mn.new(t).parseWith(()=>Mn.readIPv4Addr())}function pc(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>wh))return Mn.new(t).parseWith(()=>Mn.readIPv6Addr())}function Kn(t){return!!dc(t)}function mc(t){return!!pc(t)}var Eh=Math.pow(2,7),Sh=Math.pow(2,14),vh=Math.pow(2,21),vo=Math.pow(2,28),Ao=Math.pow(2,35),Bo=Math.pow(2,42),Lo=Math.pow(2,49),te=128,_e=127;function Te(t){if(t<Eh)return 1;if(t<Sh)return 2;if(t<vh)return 3;if(t<vo)return 4;if(t<Ao)return 5;if(t<Bo)return 6;if(t<Lo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function dr(t,e,r=0){switch(Te(t)){case 8:e[r++]=t&255|te,t/=128;case 7:e[r++]=t&255|te,t/=128;case 6:e[r++]=t&255|te,t/=128;case 5:e[r++]=t&255|te,t/=128;case 4:e[r++]=t&255|te,t>>>=7;case 3:e[r++]=t&255|te,t>>>=7;case 2:e[r++]=t&255|te,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ah(t,e,r=0){switch(Te(t)){case 8:e.set(r++,t&255|te),t/=128;case 7:e.set(r++,t&255|te),t/=128;case 6:e.set(r++,t&255|te),t/=128;case 5:e.set(r++,t&255|te),t/=128;case 4:e.set(r++,t&255|te),t>>>=7;case 3:e.set(r++,t&255|te),t>>>=7;case 2:e.set(r++,t&255|te),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function _o(t,e){let r=t[e],n=0;if(n+=r&_e,r<te||(r=t[e+1],n+=(r&_e)<<7,r<te)||(r=t[e+2],n+=(r&_e)<<14,r<te)||(r=t[e+3],n+=(r&_e)<<21,r<te)||(r=t[e+4],n+=(r&_e)*vo,r<te)||(r=t[e+5],n+=(r&_e)*Ao,r<te)||(r=t[e+6],n+=(r&_e)*Bo,r<te)||(r=t[e+7],n+=(r&_e)*Lo,r<te))return n;throw new RangeError("Could not decode varint")}function Bh(t,e){let r=t.get(e),n=0;if(n+=r&_e,r<te||(r=t.get(e+1),n+=(r&_e)<<7,r<te)||(r=t.get(e+2),n+=(r&_e)<<14,r<te)||(r=t.get(e+3),n+=(r&_e)<<21,r<te)||(r=t.get(e+4),n+=(r&_e)*vo,r<te)||(r=t.get(e+5),n+=(r&_e)*Ao,r<te)||(r=t.get(e+6),n+=(r&_e)*Bo,r<te)||(r=t.get(e+7),n+=(r&_e)*Lo,r<te))return n;throw new RangeError("Could not decode varint")}function yc(t,e,r=0){return e==null&&(e=Se(Te(t))),e instanceof Uint8Array?dr(t,e,r):Ah(t,e,r)}function Kt(t,e=0){return t instanceof Uint8Array?_o(t,e):Bh(t,e)}function Lh(t){return t.buffer instanceof ArrayBuffer}function Ae(t){return Lh(t)?t:t.slice()}function W(t,e="utf8"){let r=Nn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},it=class extends Error{static name="ValidationError";name="ValidationError"},Fn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Hn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Io(t){return e=>W(e,t)}function Do(t){return e=>ee(e,t)}function pr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ft(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function gc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=ee(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Ft(n);return Me([r,s],r.length+s.length)}function bc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=bt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Ft(n);return Me([r,s],r.length+s.length)}function Ro(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=W(e,"base32"),s=pr(r);return`${n}:${s}`}var Oo=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let s=parseInt(r,10);if(isNaN(s)||s<0||s>255)throw new Be("Invalid byte value in IP address");e[n]=s}),e},wc=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let o=Kn(r[n]),i;o&&(i=Oo(r[n]),r[n]=W(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,W(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 o=[n,1];for(n=9-r.length;n>0;n--)o.push("0");r.splice.apply(r,o)}let s=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let o=parseInt(r[n],16);if(isNaN(o)||o<0||o>65535)throw new Be("Invalid byte value in IP address");s[e++]=o>>8&255,s[e++]=o&255}return s},xc=function(t){if(t.byteLength!==4)throw new Be("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Ec=function(t){if(t.byteLength!==16)throw new Be("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let s=t[n],o=t[n+1],i=`${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Be(`Invalid IPv6 address "${r}"`)}};function Sc(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Be(`Invalid IPv6 address "${t}"`)}}var Co=Object.values(Mt).map(t=>t.decoder),_h=(function(){let t=Co[0].or(Co[1]);return Co.slice(2).forEach(e=>t=t.or(e)),t})();function vc(t){return _h.decode(t)}function Ac(t){return e=>t.encoder.encode(e)}function Th(t){if(parseInt(t).toString()!==t)throw new it("Value must be an integer")}function Ch(t){if(t<0)throw new it("Value must be a positive integer, or zero")}function Ih(t){return e=>{if(e>t)throw new it(`Value must be smaller than or equal to ${t}`)}}function Dh(...t){return e=>{for(let r of t)r(e)}}var qr=Dh(Th,Ch,Ih(65535));var ve=-1,Po=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Hn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ct=new Po,Vh=[{code:4,name:"ip4",size:32,valueToBytes:Oo,bytesToValue:xc,validate:t=>{if(!Kn(t))throw new it(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ft,bytesToValue:pr,validate:qr},{code:273,name:"udp",size:16,valueToBytes:Ft,bytesToValue:pr,validate:qr},{code:33,name:"dccp",size:16,valueToBytes:Ft,bytesToValue:pr,validate:qr},{code:41,name:"ip6",size:128,valueToBytes:wc,bytesToValue:Ec,stringToValue:Sc,validate:t=>{if(!mc(t))throw new it(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ve},{code:43,name:"ipcidr",size:8,bytesToValue:Io("base10"),valueToBytes:Do("base10")},{code:53,name:"dns",size:ve},{code:54,name:"dns4",size:ve},{code:55,name:"dns6",size:ve},{code:56,name:"dnsaddr",size:ve},{code:132,name:"sctp",size:16,valueToBytes:Ft,bytesToValue:pr,validate:qr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ve,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:ve,bytesToValue:Io("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?Do("base58btc")(t):xe.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ro,valueToBytes:gc},{code:445,name:"onion3",size:296,bytesToValue:Ro,valueToBytes:bc},{code:446,name:"garlic64",size:ve},{code:447,name:"garlic32",size:ve},{code:448,name:"tls"},{code:449,name:"sni",size:ve},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ve,bytesToValue:Ac(fo),valueToBytes:vc},{code:480,name:"http"},{code:481,name:"http-path",size:ve,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.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:ve}];Vh.forEach(t=>{ct.addProtocol(t)});function Bc(t){let e=[],r=0;for(;r<t.length;){let n=Kt(t,r),s=ct.getProtocol(n),o=Te(n),i=jh(s,t,r+o),a=0;i>0&&s.size===ve&&(a=Te(i));let c=o+a+i,u={code:n,name:s.name,bytes:Ae(t.subarray(r,r+c))};if(i>0){let f=r+o+a,l=t.subarray(f,f+i);u.value=s.bytesToValue?.(l)??W(l)}e.push(u),r+=c}return e}function Lc(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let s=ct.getProtocol(n.code),o=Te(n.code),i,a=0,c=0;n.value!=null&&(i=s.valueToBytes?.(n.value)??ee(n.value),a=i.byteLength,s.size===ve&&(c=Te(a)));let u=new Uint8Array(o+c+a),f=0;dr(n.code,u,f),f+=o,i!=null&&(s.size===ve&&(dr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Me(r,e)}function _c(t){if(t.charAt(0)!=="/")throw new Be('String multiaddr must start with "/"');let e=[],r="protocol",n="",s="";for(let o=1;o<t.length;o++){let i=t.charAt(o);i!=="/"&&(r==="protocol"?s+=t.charAt(o):n+=t.charAt(o));let a=o===t.length-1;if(i==="/"||a){let c=ct.getProtocol(s);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",s="",r="protocol";continue}else if(a)throw new Be(`Component ${s} 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 Be(`Component ${s} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",s="",r="protocol"}}}if(s!==""&&n!=="")throw new Be("Incomplete multiaddr");return e}function Tc(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ct.getProtocol(e.code);if(r==null)throw new Be(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function jh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Kt(e,r)}var Wh=Symbol.for("nodejs.util.inspect.custom"),Qo=Symbol.for("@multiformats/multiaddr");function Yh(t){if(t==null&&(t="/"),Cc(t))return t.getComponents();if(t instanceof Uint8Array)return Bc(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),_c(t);if(Array.isArray(t))return t;throw new Be("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Xo=class t{[Qo]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Yh(e),r.validate!==!1&&Gh(this)}get bytes(){return this.#r==null&&(this.#r=Lc(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Tc(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),s=n.lastIndexOf(r);if(s<0)throw new Fn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,s),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return we(this.bytes,e.bytes)}[Wh](){return`Multiaddr(${this.toString()})`}};function Gh(t){t.getComponents().forEach(e=>{let r=ct.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Cc(t){return!!t?.[Qo]}var ue=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),V=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Ic=t=>({match:e=>t.match(e)===!1?e:!1}),G=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Ce=(...t)=>({match:e=>{let r;for(let n of t){let s=n.match(e);s!==!1&&(r==null||s.length<r.length)&&(r=s)}return r??!1}}),J=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function fe(...t){function e(s){if(s==null)return!1;let o=s.getComponents();for(let i of t){let a=i.match(o);if(a===!1)return!1;o=a}return o}function r(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matchers:t,matches:r,exactMatch:n}}var Zh=V(421),Eg=fe(Zh),Yn=V(54),Gn=V(55),Zn=V(56),ei=V(53),Sg=fe(Yn,G(V(421))),vg=fe(Gn,G(V(421))),Ag=fe(Zn,G(V(421))),Bg=fe(Ce(ei,Zn,Yn,Gn),G(V(421))),Dc=J(V(4),G(V(43))),Rc=J(G(V(42)),V(41),G(V(43))),ti=Ce(Dc,Rc),br=Ce(ti,ei,Yn,Gn,Zn),Lg=fe(Ce(ti,J(Ce(ei,Zn,Yn,Gn),G(V(421))))),_g=fe(Dc),Tg=fe(Rc),Cg=fe(ti),ri=J(br,V(6)),zr=J(br,V(273)),Ig=fe(J(ri,G(V(421)))),Dg=fe(zr),ni=J(zr,ue(460),G(V(421))),Xn=J(zr,ue(461),G(V(421))),Xh=Ce(ni,Xn),Rg=fe(ni),Og=fe(Xn),Jo=Ce(br,ri,zr,ni,Xn),Oc=Ce(J(Jo,ue(477),G(V(421)))),Pg=fe(Oc),Pc=Ce(J(Jo,ue(478),G(V(421))),J(Jo,ue(448),G(V(449)),ue(477),G(V(421)))),Ug=fe(Pc),Uc=J(zr,ue(280),G(V(466)),G(V(466)),G(V(421))),Ng=fe(Uc),Nc=J(Xn,ue(465),G(V(466)),G(V(466)),G(V(421))),Qn=fe(Nc),Wn=Ce(Oc,Pc,J(ri,G(V(421))),J(Xh,G(V(421))),J(br,G(V(421))),Uc,Nc,V(421)),kg=fe(Wn),Qh=J(G(Wn),ue(290),Ic(ue(281)),G(V(421))),Mg=fe(Qh),Jh=Ce(J(Wn,ue(290),ue(281),G(V(421))),J(Wn,ue(281),G(V(421))),J(ue(281),G(V(421)))),Kg=fe(Jh),ed=J(br,Ce(J(V(6,"80")),J(V(6),ue(480)),ue(480)),G(V(481)),G(V(421))),Fg=fe(ed),td=J(br,Ce(J(V(6,"443")),J(V(6,"443"),ue(480)),J(V(6),ue(443)),J(V(6),ue(448),ue(480)),J(ue(448),ue(480)),ue(448),ue(443)),G(V(481)),G(V(421))),Hg=fe(td),rd=Ce(J(V(777),G(V(421)))),qg=fe(rd),nd=Ce(J(V(400),G(V(421)))),zg=fe(nd);function Jn(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var es=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},wr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new es(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new es(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var si=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ts(t={}){return sd(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}},t)}function sd(t,e){e=e??{};let r=e.onEnd,n=new wr,s,o,i,a=Jn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,x)=>{o=E=>{o=null,n.push(E);try{m(t(n))}catch(w){x(w)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Jn()})}},u=m=>o!=null?o(m):(n.push(m),s),f=m=>(n=new wr,o!=null?o({error:m}):(n.push({error:m}),s)),l=m=>{if(i)return s;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:m})},d=m=>i?s:(i=!0,m!=null?f(m):u({done:!0})),p=()=>(n=new wr,d(),{done:!0}),b=m=>(d(m),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:p,throw:b,push:l,end:d,get readableLength(){return n.size},onEmpty:async m=>{let x=m?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,w;x!=null&&(E=new Promise((A,L)=>{w=()=>{L(new si)},x.addEventListener("abort",w)}));try{await Promise.race([a.promise,E])}finally{w!=null&&x!=null&&x?.removeEventListener("abort",w)}}},r==null)return s;let g=s;return s={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(m){return g.throw(m),r!=null&&(r(m),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(m){return g.end(m),r!=null&&(r(m),r=void 0),s},get readableLength(){return g.readableLength},onEmpty:m=>g.onEmpty(m)},s}var oi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},od=t=>"reason"in t?t.reason:new DOMException("This operation was aborted.","AbortError"),id=2**31-1,ad=(t,e)=>{if(typeof t!="number"||Math.sign(t)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function ii(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,u=()=>{try{t.cancel?.()}catch{}},l=new Promise((d,p)=>{let b=()=>{p(od(i)),u()},g=ad(r,o);try{g?p(g):i?.aborted?b():i&&(c=b,i.addEventListener("abort",c,{once:!0}))}finally{t.then(d,p)}if(g||i?.aborted||r>id)return;let m=n||s===!1||s instanceof Error?void 0:new oi(s??`Promise timed out after ${r} milliseconds`);a=o.setTimeout.call(void 0,()=>{if(n)try{d(n())}catch(x){p(x)}else s===!1?d():p(s instanceof Error?s:m);u()},r)}).finally(()=>{try{l.clear()}catch{}try{c&&i.removeEventListener("abort",c)}catch{}});return l.clear=()=>{a!==void 0&&(o.clearTimeout.call(void 0,a),a=void 0)},l}var kc=t=>typeof t=="function"?{filter:t}:{...t},cd=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,ud=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],fd=t=>{for(let[e,r]of ud){let n=t?.[e],s=t?.[r];if(typeof n=="function"&&typeof s=="function")return{addListener:n.bind(t),removeListener:s.bind(t)}}throw new TypeError("Emitter is not compatible")},ld=t=>{let e=new Map;for(let[r,n]of t)for(let s of Array.isArray(r)?r:[r])e.has(s)||e.set(s,n);return e},hd=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:s,isDone:o})=>{n?.addEventListener("abort",s,{once:!0});for(let[i,a]of r)if(t(i,a),o()){e(i,a);return}},dd=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[s,o]of e)t(s,o);r?.removeEventListener("abort",n)},pd=(t,e,r)=>{let n=Promise.resolve();return(s,o)=>{n=n.then(async()=>{if(e())return;let i;try{i=t?await t(s):!0}catch(a){e()||r(a);return}e()||o(i)})}};function md(t,e,r){let n=()=>{},s=!1,o,i=new Promise((a,c)=>{r=kc(r);let{filter:u}=r;if(!cd(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:l}=fd(t);if(r.count===0){a([]);return}let d=[],p=A=>{n(),c(A)},b=pd(u,()=>s,p),g=A=>{d.push(A),r.count===d.length&&(n(),a(d))},m=(...A)=>{if(s)return;let L=r.multiArgs?A:A[0];if(!u){g(L);return}b(L,R=>{R&&g(L)})},x=(...A)=>{p(r.rejectionMultiArgs?A:A[0])},E=()=>{p(r.signal.reason)},w={addListener:f,removeListener:l,handlers:ld([[e,m],[r.rejectionEvents??["error"],x]]),signal:r.signal,abortHandler:E,isDone:()=>s};n=()=>{s=!0,clearTimeout(o),dd(w)},hd(w),!(s||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&r.timeout<=2**31-1&&(o=setTimeout(n,r.timeout)),a(d))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=ii(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function wt(t,e,r){let n=md(t,e,{...kc(r),count:1,resolveImmediately:!1}),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var qt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},rs=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},ns=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function yd(t){return t.reason}function Fe(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??yd;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let s;return Promise.race([t,new Promise((o,i)=>{s=()=>{i(n(e))},e.addEventListener("abort",s)})]).finally(()=>{s!=null&&e.removeEventListener("abort",s)})}var gd=Math.pow(2,20)*4,Xe=class extends cr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;#t;#r=new Set;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??gd,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new Q,this.writeBuffer=new Q,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=s=>{this.onDrainPromise?.reject(s.error??new ns)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Fe(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){let e=ts(),r,n=o=>{e.push(o.data)};this.addEventListener("message",n);let s=()=>{this.#r.delete(s),this.removeEventListener("message",n),r=this.#t,e.end()};this.#r.add(s),this.readableDone()&&s();try{if(yield*e,r!=null)throw r}finally{this.removeEventListener("message",n),this.#r.delete(s)}}readableDone(){return this.readBuffer.byteLength===0&&(this.remoteWriteStatus==="closed"||this.readStatus==="closing"||this.readStatus==="closed")}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new yt(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(this.status==="aborted"||this.status==="reset"||this.status==="closed"){this.readBuffer.byteLength>0&&(this.#t??=e,this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closed",this.maybeDispatchEnd());return}this.log.error("abort with error - %e",e),this.status="aborted",this.#t=e,this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(r){this.log.error("failed to send reset to remote - %e",r)}this.dispatchEvent(new Dn(e))}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){if(this.status==="aborted"||this.status==="reset"||this.status==="closed")return;this.log("remote reset");let e=new Ln;this.#t=e,this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new Rn(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.maybeDispatchEnd(),this.dispatchEvent(new ar))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),i=new Q(o);this.writeBuffer.consume(o.byteLength);let a;try{a=this.sendData(o)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}maybeDispatchEnd(){this.readableDone()&&(this.#r.forEach(e=>{e()}),!this.#e&&(this.#e=!0,this.safeDispatchEvent("end")))}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new In(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed",this.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Pt(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new Pt(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var ss=class extends Xe{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await wt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await wt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Mc(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var os=class extends cr{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let s=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",s);let o=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",o)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await Fe(Promise.all([...this.streams].map(async r=>{await r.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(r=>{r.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(r=>{r.onTransportClosed(e)})}catch(r){this.abort(r)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new Bn;let r=this.onCreateStream({...this.streamOptions,...e});return Mc(r)&&(r=await r),this.streams.push(r),this.cleanUpStream(r),r}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new rs(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let r=n=>{let s=this.streams.findIndex(o=>o===e);s!==-1&&this.streams.splice(s,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",r),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(r=>{this.safeDispatchEvent("stream",{detail:r})}),this.earlyStreams=[]})}};var is=class extends Xe{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await wt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await wt(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){if(!(this.readStatus==="closing"||this.readStatus==="closed")){this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",this.maybeDispatchEnd();try{await this.sendCloseRead(e)}catch(r){throw this.log.error("failed to close readable end - %e",r),r}finally{this.readStatus="closed"}this.log("closed readable end gracefully")}}};var bd=4194304,as=class extends Error{static name="UnwrappedError";name="UnwrappedError"},$r=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ci=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ui=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function wd(t){return typeof t?.closeRead=="function"}function xd(t){return typeof t?.close=="function"}function ai(t){return wd(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:xd(t)?t.status!=="open":!1}function Ed(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Sd(t,e){let r=e?.maxBufferSize??bd,n=new Q,s,o=!1,i;if(!Ed(t))throw new se("Argument should be a Stream or a Multiaddr");let a=l=>{if(!o&&i==null){if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(d);let p=new Pt(`Read buffer overflow - ${d} > ${r}`);i=p,s?.reject(p),queueMicrotask(()=>{t.abort(p)});return}s?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?s?.reject(l.error):s?.resolve()};t.addEventListener("close",c);let u=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(o===!0)throw new as("Stream was unwrapped");if(i!=null)throw i;if(ai(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new qt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=d){s.resolve();break}if(await Fe(s.promise,l?.signal),ai(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}s=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(ai(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new qt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let b=n.sublist(0,p);return n.consume(p),b},async write(l,d){if(o===!0)throw new as("Stream was unwrapped");t.send(l)||await wt(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return f}function fi(t,e={}){let r=Sd(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Te(e.maxDataLength));let n=e?.lengthDecoder??Kt,s=e?.lengthEncoder??yc;return{async read(i){let a=-1,c=new Q;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new $r("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ui(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ci(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new qt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new qt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new Q(s(i.byteLength),i),a)},async writeV(i,a){let c=new Q(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var vd=1024*1024*4,Ad=1024*1024*4,cs=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new Q,this.maxBufferSize=e.maxBufferSize??vd,this.maxDataLength=e.maxDataLength??Ad,this.lengthDecoder=e.lengthDecoder??Kt,this.encodingLength=e.encodingLength??Te}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new se(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(o){if(o instanceof RangeError)break;throw o}if(r<0||r>this.maxDataLength)throw new $r("Invalid message length");let n=this.encodingLength(r),s=n+r;if(this.buffer.byteLength>=s){let o=this.buffer.sublist(n,s);this.buffer.consume(s),o.byteLength>0&&(yield o)}else break}}};var xr=!!globalThis.process?.env?.DUMP_SESSION_KEYS,li=16;function hi(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var us=t=>t?`"${t}" `:"";function fs(t,e=""){if(typeof t!="boolean")throw new TypeError(us(e)+"expected boolean, got type="+typeof t);return t}function zt(t,e=""){if(typeof t!="number")throw new TypeError(us(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(us(e)+"expected integer >= 0, got "+t);return t}function ge(t,e,r=""){if(hi(t)&&(e===void 0||t.length===e))return t;e!==void 0&&zt(e,"length");let n=hi(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=us(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}var Kc=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`)};function di(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Fc(t,e){ge(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Qe(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function We(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Bd(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var xt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ld(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function _d(t){for(let e=0;e<t.length;e++)t[e]=Ld(t[e]);return t}var ut=xt?t=>t:_d;function Td(t,e){return!t.byteLength||!e.byteLength?!1:t.buffer===e.buffer&&t.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<t.byteOffset+t.byteLength}function Hc(t,e){if(Td(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function qc(t,e){return Kc(t,"defaults"),Kc(e,"opts"),Object.assign(t,e)}function zc(t,e){if(t=ge(t),e=ge(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function $c(t,e,r){let n=e,s=r||(()=>[]),o=(a,c)=>n(c,...s(a)).update(a).digest(),i=n(new Uint8Array(t),...s(new Uint8Array(0)));return o.outputLen=i.outputLen,o.blockLen=i.blockLen,o.create=(a,...c)=>n(a,...c),o}var Vc=(t,e)=>{function r(n,...s){if(ge(n,void 0,"key"),t.nonceLength!==void 0){let l=s[0];ge(l,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let o=t.tagLength,i=t.nonceLength!==void 0?1:0;if(!t.withAAD){for(let l=i;l<s.length;l++)if(hi(s[l]))throw new Error("AAD not supported")}t.withAAD&&s[i]!==void 0&&ge(s[i],void 0,"AAD");let a=e(n,...s),c=(l,d)=>{if(d!==void 0){if(l!==2)throw new Error("cipher output not supported");ge(d,void 0,"output")}},u=!1;return{encrypt(l,d){if(u)throw new Error("cannot encrypt() twice with same key + nonce");return u=!0,ge(l,void 0,"data"),c(a.encrypt.length,d),a.encrypt(l,d)},decrypt(l,d){if(ge(l,void 0,"data"),o&&l.length<o)throw new Error('"ciphertext" expected length >= tagLength='+o);return c(a.decrypt.length,d),a.decrypt(l,d)}}}return Object.assign(r,t),r};function Vr(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(ge(e,t,"output"),r&&!jr(e))throw new Error("invalid output, must be aligned");return e}function jc(t,e,r){zt(t),zt(e),fs(r);let n=new Uint8Array(16),s=Bd(n);return s.setBigUint64(0,BigInt(e),r),s.setBigUint64(8,BigInt(t),r),n}function jr(t){return t.byteOffset%4===0}function Er(t){return Uint8Array.from(ge(t))}var Yc=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),Cd=ut(Qe(Yc("expand 16-byte k"))),Id=ut(Qe(Yc("expand 32-byte k")));function X(t,e){return t<<e|t>>>32-e}var Wr=64,Dd=16,pi=2**32-1,Wc=Uint32Array.of();function Rd(t,e,r,n,s,o,i,a){let c=s.length,u=new Uint8Array(Wr),f=Qe(u),l=xt&&jr(s)&&jr(o),d=l?Qe(s):Wc,p=l?Qe(o):Wc;if(!xt){for(let b=0;b<c;i++){if(t(e,r,n,f,i,a),ut(f),i>=pi)throw new Error("arx: counter overflow");let g=Math.min(Wr,c-b);for(let m=0,x;m<g;m++)x=b+m,o[x]=s[x]^u[m];b+=g}return}for(let b=0;b<c;i++){if(t(e,r,n,f,i,a),i>=pi)throw new Error("arx: counter overflow");let g=Math.min(Wr,c-b);if(l&&g===Wr){let m=b/4;if(b%4!==0)throw new Error("arx: invalid block position");for(let x=0,E;x<Dd;x++)E=m+x,p[E]=d[E]^f[x];b+=Wr;continue}for(let m=0,x;m<g;m++)x=b+m,o[x]=s[x]^u[m];b+=g}}function Gc(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=qc({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return zt(s),zt(i),fs(o),fs(r),(a,c,u,f,l=0)=>{ge(a,void 0,"key"),ge(c,void 0,"nonce"),ge(u,void 0,"data");let d=u.length,p=f!==void 0;if(f=Vr(d,f,!1),p&&Hc(u,f),zt(l),l<0||l>=pi)throw new Error("arx: counter overflow");let b=[],g=a.length,m,x;if(g===32)b.push(m=Er(a)),x=Id;else if(g===16&&r)m=new Uint8Array(32),m.set(a),m.set(a,16),x=Cd,b.push(m);else throw ge(a,32,"arx key"),new Error("invalid key size");(!xt||!jr(c))&&b.push(c=Er(c));let E=Qe(m);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let L=c.subarray(0,16);if(xt)n(x,E,Qe(L),E);else{let R=ut(Uint32Array.from(x));n(R,E,Qe(L),E),We(R),ut(E)}c=c.subarray(16)}else xt||ut(E);let w=16-s;if(w!==c.length)throw new Error(`arx: nonce must be ${w} or 16 bytes`);if(w!==12){let L=new Uint8Array(12);L.set(c,o?0:12-c.length),c=L,b.push(c)}let A=ut(Qe(c));try{return Rd(t,x,E,A,u,f,l,i),f}finally{We(...b)}}}function Le(t,e){return t[e++]&255|(t[e++]&255)<<8}var mi=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=Er(ge(e,32,"key"));let r=Le(e,0),n=Le(e,2),s=Le(e,4),o=Le(e,6),i=Le(e,8),a=Le(e,10),c=Le(e,12),u=Le(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=Le(e,16+2*f)}process(e,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],f=i[3],l=i[4],d=i[5],p=i[6],b=i[7],g=i[8],m=i[9],x=Le(e,r+0),E=Le(e,r+2),w=Le(e,r+4),A=Le(e,r+6),L=Le(e,r+8),R=Le(e,r+10),q=Le(e,r+12),O=Le(e,r+14),I=o[0]+(x&8191),D=o[1]+((x>>>13|E<<3)&8191),k=o[2]+((E>>>10|w<<6)&8191),K=o[3]+((w>>>7|A<<9)&8191),z=o[4]+((A>>>4|L<<12)&8191),_=o[5]+(L>>>1&8191),U=o[6]+((L>>>14|R<<2)&8191),T=o[7]+((R>>>11|q<<5)&8191),B=o[8]+((q>>>8|O<<8)&8191),F=o[9]+(O>>>5|s),C=0,S=C+I*a+D*(5*m)+k*(5*g)+K*(5*b)+z*(5*p);C=S>>>13,S&=8191,S+=_*(5*d)+U*(5*l)+T*(5*f)+B*(5*u)+F*(5*c),C+=S>>>13,S&=8191;let h=C+I*c+D*a+k*(5*m)+K*(5*g)+z*(5*b);C=h>>>13,h&=8191,h+=_*(5*p)+U*(5*d)+T*(5*l)+B*(5*f)+F*(5*u),C+=h>>>13,h&=8191;let y=C+I*u+D*c+k*a+K*(5*m)+z*(5*g);C=y>>>13,y&=8191,y+=_*(5*b)+U*(5*p)+T*(5*d)+B*(5*l)+F*(5*f),C+=y>>>13,y&=8191;let v=C+I*f+D*u+k*c+K*a+z*(5*m);C=v>>>13,v&=8191,v+=_*(5*g)+U*(5*b)+T*(5*p)+B*(5*d)+F*(5*l),C+=v>>>13,v&=8191;let P=C+I*l+D*f+k*u+K*c+z*a;C=P>>>13,P&=8191,P+=_*(5*m)+U*(5*g)+T*(5*b)+B*(5*p)+F*(5*d),C+=P>>>13,P&=8191;let N=C+I*d+D*l+k*f+K*u+z*c;C=N>>>13,N&=8191,N+=_*a+U*(5*m)+T*(5*g)+B*(5*b)+F*(5*p),C+=N>>>13,N&=8191;let M=C+I*p+D*d+k*l+K*f+z*u;C=M>>>13,M&=8191,M+=_*c+U*a+T*(5*m)+B*(5*g)+F*(5*b),C+=M>>>13,M&=8191;let H=C+I*b+D*p+k*d+K*l+z*f;C=H>>>13,H&=8191,H+=_*u+U*c+T*a+B*(5*m)+F*(5*g),C+=H>>>13,H&=8191;let $=C+I*g+D*b+k*p+K*d+z*l;C=$>>>13,$&=8191,$+=_*f+U*u+T*c+B*a+F*(5*m),C+=$>>>13,$&=8191;let j=C+I*m+D*g+k*b+K*p+z*d;C=j>>>13,j&=8191,j+=_*l+U*f+T*u+B*c+F*a,C+=j>>>13,j&=8191,C=(C<<2)+C|0,C=C+S|0,S=C&8191,C=C>>>13,h+=C,o[0]=S,o[1]=h,o[2]=y,o[3]=v,o[4]=P,o[5]=N,o[6]=M,o[7]=H,o[8]=$,o[9]=j}finalize(){let{h:e,pad:r}=this,n=new Uint16Array(10),s=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=s,s=e[a]>>>13,e[a]&=8191;e[0]+=s*5,s=e[0]>>>13,e[0]&=8191,e[1]+=s,s=e[1]>>>13,e[1]&=8191,e[2]+=s,n[0]=e[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)e[a]=e[a]&o|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+r[0];e[0]=i&65535;for(let a=1;a<8;a++)i=(e[a]+r[a]|0)+(i>>>16)|0,e[a]=i&65535;We(n)}update(e){di(this),ge(e),e=Er(e);let{buffer:r,blockLen:n}=this,s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(e,o);continue}r.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,We(this.h,this.r,this.buffer,this.pad)}digestInto(e){di(this),Fc(e,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:s}=this;if(s){for(r[s++]=1;s<16;s++)r[s]=0;this.process(r,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)e[o++]=n[i]>>>0,e[o++]=n[i]>>>8}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}},Zc=$c(32,t=>new mi(t));function Od(t,e,r,n,s,o=20){let i=t[0],a=t[1],c=t[2],u=t[3],f=e[0],l=e[1],d=e[2],p=e[3],b=e[4],g=e[5],m=e[6],x=e[7],E=s,w=r[0],A=r[1],L=r[2],R=i,q=a,O=c,I=u,D=f,k=l,K=d,z=p,_=b,U=g,T=m,B=x,F=E,C=w,S=A,h=L;for(let v=0;v<o;v+=2)R=R+D|0,F=X(F^R,16),_=_+F|0,D=X(D^_,12),R=R+D|0,F=X(F^R,8),_=_+F|0,D=X(D^_,7),q=q+k|0,C=X(C^q,16),U=U+C|0,k=X(k^U,12),q=q+k|0,C=X(C^q,8),U=U+C|0,k=X(k^U,7),O=O+K|0,S=X(S^O,16),T=T+S|0,K=X(K^T,12),O=O+K|0,S=X(S^O,8),T=T+S|0,K=X(K^T,7),I=I+z|0,h=X(h^I,16),B=B+h|0,z=X(z^B,12),I=I+z|0,h=X(h^I,8),B=B+h|0,z=X(z^B,7),R=R+k|0,h=X(h^R,16),T=T+h|0,k=X(k^T,12),R=R+k|0,h=X(h^R,8),T=T+h|0,k=X(k^T,7),q=q+K|0,F=X(F^q,16),B=B+F|0,K=X(K^B,12),q=q+K|0,F=X(F^q,8),B=B+F|0,K=X(K^B,7),O=O+z|0,C=X(C^O,16),_=_+C|0,z=X(z^_,12),O=O+z|0,C=X(C^O,8),_=_+C|0,z=X(z^_,7),I=I+D|0,S=X(S^I,16),U=U+S|0,D=X(D^U,12),I=I+D|0,S=X(S^I,8),U=U+S|0,D=X(D^U,7);let y=0;n[y++]=i+R|0,n[y++]=a+q|0,n[y++]=c+O|0,n[y++]=u+I|0,n[y++]=f+D|0,n[y++]=l+k|0,n[y++]=d+K|0,n[y++]=p+z|0,n[y++]=b+_|0,n[y++]=g+U|0,n[y++]=m+T|0,n[y++]=x+B|0,n[y++]=E+F|0,n[y++]=w+C|0,n[y++]=A+S|0,n[y++]=L+h|0}var Pd=Gc(Od,{counterRight:!1,counterLength:4,allowShortKeys:!1});var Ud=new Uint8Array(16),Xc=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(Ud.subarray(r))},Nd=new Uint8Array(32);function Qc(t,e,r,n,s){s!==void 0&&ge(s,void 0,"AAD");let o=t(e,r,Nd),i=jc(n.length,s?s.length:0,!0),a=Zc.create(o);s&&Xc(a,s),Xc(a,n),a.update(i);let c=a.digest();return We(o,i),c}var kd=t=>(e,r,n)=>({encrypt(o,i){let a=o.length;i=Vr(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);t(e,r,c,c,1);let u=Qc(t,e,r,c,n);return i.set(u,a),We(u),i},decrypt(o,i){i=Vr(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),u=Qc(t,e,r,a,n);if(!zc(c,u))throw We(u),new Error("invalid tag");return i.set(o.subarray(0,-16)),t(e,r,i,i,1),We(u),i}}),yi=Vc({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},kd(Pd));var ls=BigInt(4294967295),Jc=BigInt(32);function Md(t,e=!1){return e?{h:Number(t&ls),l:Number(t>>Jc&ls)}:{h:Number(t>>Jc&ls)|0,l:Number(t&ls)|0}}function eu(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Md(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var Kd=t=>t/2**32|0,Fd=t=>t>>>0;function tu(t,e,r,n){let s=Kd(r),o=Fd(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}var gi=(t,e,r)=>t>>>r,bi=(t,e,r)=>t<<32-r|e>>>r,$t=(t,e,r)=>t>>>r|e<<32-r,Vt=(t,e,r)=>t<<32-r|e>>>r,Yr=(t,e,r)=>t<<64-r|e>>>r-32,Gr=(t,e,r)=>t>>>r-32|e<<64-r;function Je(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var ru=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),nu=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,su=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),ou=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,iu=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),au=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;function hs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var wi=t=>t?`"${t}" `:"";function Ye(t,e=""){if(typeof t!="number")throw new TypeError(wi(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(wi(e)+"expected integer >= 0, got "+t);return t}function Oe(t,e,r=""){if(hs(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Ye(e,"length");let n=hs(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=wi(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}function jt(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ye(t.outputLen),Ye(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var qd=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},cu=(t,e)=>{qd(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Sr(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function ds(t,e){Oe(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function He(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function ps(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ge(t,e){return t<<32-e|t>>>e}var fu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",zd=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ms(t){if(Oe(t),fu)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=zd[t[r]];return e}function uu(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function ys(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(fu)try{return Uint8Array.fromHex(t)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=uu(t.charCodeAt(o)),a=uu(t.charCodeAt(o+1));if(i===void 0||a===void 0){let c=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function xi(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Oe(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function $d(t,e,r="opts"){return cu(t,"defaults"),e!==void 0&&cu(e,r),Object.assign(Object.create(null),t,e)}function Ei(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=$d({},e,"info");let r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function lu(t=32){Ye(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Si=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function hu(t,e,r){return t&e^~t&r}function du(t,e,r){return t&e^t&r^e&r}var Zr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=ps(this.buffer)}update(e){Sr(this),Oe(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length,i=!1;for(let a=0;a<o;){let c=Math.min(s-this.pos,o-a);if(c===s){let u=ps(e);for(;s<=o-a;a+=s)this.process(u,a);i=!0;continue}n.set(a===0&&c===o?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Sr(this),ds(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>s-i&&(this.process(n,0),r.fill(0)),tu(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let a=e===r?n:ps(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:s,destroyed:o,pos:i}=this;return e.destroyed=o,e.finished=s,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},pu=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mu=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Vd=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]),Et=new Uint32Array(64),vi=class extends Zr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,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:e,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,r,n,s,o,i,a,c]}set(e,r,n,s,o,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)Et[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let d=Et[l-15],p=Et[l-2],b=Ge(d,7)^Ge(d,18)^d>>>3,g=Ge(p,17)^Ge(p,19)^p>>>10;Et[l]=g+Et[l-7]+b+Et[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Ge(a,6)^Ge(a,11)^Ge(a,25),p=f+d+hu(a,c,u)+Vd[l]+Et[l]|0,g=(Ge(n,2)^Ge(n,13)^Ge(n,22))+du(n,s,o)|0;f=u,u=c,c=a,a=i+p|0,i=o,o=s,s=n,n=p+g|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){He(Et)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),He(this.buffer)}},Ai=class extends vi{constructor(){super(32,pu)}};var yu=eu(["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(t=>BigInt(t))),jd=yu[0],Wd=yu[1],St=new Uint32Array(80),vt=new Uint32Array(80),Bi=class extends Zr{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(e,r){super(128,e,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:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:p,Gl:b,Hh:g,Hl:m}=this;return[e,r,n,s,o,i,a,c,u,f,l,d,p,b,g,m]}set(e,r,n,s,o,i,a,c,u,f,l,d,p,b,g,m){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=b|0,this.Hh=g|0,this.Hl=m|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let w=0;w<16;w++,r+=4)St[w]=e.getUint32(r),vt[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let A=St[w-15]|0,L=vt[w-15]|0,R=$t(A,L,1)^$t(A,L,8)^gi(A,L,7),q=Vt(A,L,1)^Vt(A,L,8)^bi(A,L,7),O=St[w-2]|0,I=vt[w-2]|0,D=$t(O,I,19)^Yr(O,I,61)^gi(O,I,6),k=Vt(O,I,19)^Gr(O,I,61)^bi(O,I,6),K=su(q,k,vt[w-7],vt[w-16]),z=ou(K,R,D,St[w-7],St[w-16]);St[w]=z|0,vt[w]=K|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:b,Gh:g,Gl:m,Hh:x,Hl:E}=this;for(let w=0;w<80;w++){let A=$t(l,d,14)^$t(l,d,18)^Yr(l,d,41),L=Vt(l,d,14)^Vt(l,d,18)^Gr(l,d,41),R=l&p^~l&g,q=d&b^~d&m,O=iu(E,L,q,Wd[w],vt[w]),I=au(O,x,A,R,jd[w],St[w]),D=O|0,k=$t(n,s,28)^Yr(n,s,34)^Yr(n,s,39),K=Vt(n,s,28)^Gr(n,s,34)^Gr(n,s,39),z=n&o^n&a^o&a,_=s&i^s&c^i&c;x=g|0,E=m|0,g=p|0,m=b|0,p=l|0,b=d|0,{h:l,l:d}=Je(u|0,f|0,I|0,D|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let U=ru(D,K,_);n=nu(U,I,k,z),s=U|0}({h:n,l:s}=Je(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Je(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Je(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Je(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Je(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:b}=Je(this.Fh|0,this.Fl|0,p|0,b|0),{h:g,l:m}=Je(this.Gh|0,this.Gl|0,g|0,m|0),{h:x,l:E}=Je(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,o,i,a,c,u,f,l,d,p,b,g,m,x,E)}roundClean(){He(St,vt)}destroy(){this.destroyed=!0,He(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Li=class extends Bi{constructor(){super(64,mu)}};var et=Ei(()=>new Ai,Si(1));var _i=Ei(()=>new Li,Si(3));function bs(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var Z=(t,e,r)=>Oe(t,e,r),Ti=Ye;function bu(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function At(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Wt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Xr=ms,qe=(...t)=>xi(...t),vr=t=>ys(t),Lt=hs,ft=t=>lu(t),gs=BigInt(0),gu=BigInt(1),Yd=t=>t?`"${t}" `:"";function Ue(t,e=""){if(typeof t!="boolean")throw new TypeError(Yd(e)+"expected boolean, got type="+typeof t);return t}function ws(t){if(typeof t=="bigint"){if(!Bt(t))throw new RangeError("positive bigint expected, got "+t)}else Ti(t);return t}function lt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Qr(t){let e=ws(t).toString(16);return e.length&1?"0"+e:e}function wu(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?gs:BigInt("0x"+t)}function tt(t){return wu(ms(t))}function rt(t){return wu(ms(_t(Oe(t)).reverse()))}function xs(t,e){if(Ye(e),e===0)throw new Error("zero output length is invalid");t=ws(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return ys(n.padStart(r,"0"))}function Jr(t,e){return xs(t,e).reverse()}function _t(t){return Uint8Array.from(Z(t))}function Bt(t){return typeof t=="bigint"&&gs<=t}function Ci(t,e,r){return Bt(t)&&Bt(e)&&Bt(r)&&e<=t&&t<r}function nt(t,e,r,n){if(!Ci(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Ar(t){if(t<gs)throw new Error("expected non-negative bigint, got "+t);return t===gs?0:t.toString(2).length}var en=t=>(lt(t,"n"),(gu<<BigInt(t))-gu);function xu(t,e,r){if(Ye(t,"hashLen"),Ye(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...m)=>r(u,qe(c,...m)),p=(m=s)=>{u=d(o,m),c=d(),m.length!==0&&(u=d(i,m),c=d())},b=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,x=[];for(;m<e;){c=d();let E=c.slice();x.push(E),m+=c.length}return qe(...x)};return(m,x)=>{l(),p(m);let E;for(;(E=x(b()))===void 0;)p();return l(),E}}function Ie(t,e={},r={},n="object"){At(t,n),At(e,"fields"),At(r,"optFields");function s(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let o=(i,a)=>Object.entries(i).forEach(([c,u])=>s(c,u,a));o(e,!1),o(r,!0)}var Ee=BigInt(0),re=BigInt(1),Tt=BigInt(2),vu=BigInt(3),Ii=BigInt(4),Au=BigInt(5),Gd=BigInt(7),Bu=BigInt(8),Zd=BigInt(9),Xd=BigInt(15),Lu=BigInt(16),Qd=BigInt("0x10000000000000000");function ne(t,e){if(e<=Ee)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=Ee?r:e+r}function _u(t,e,r){if(r<=re)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<Ee)throw new Error("invalid exponent, negatives unsupported");if(e===Ee)return re;if(e===re)return t;let n=t%r;if(n<Ee&&(n+=r),e<Qd){let a=re;for(;e>Ee;)e&re&&(a=a*n%r),n=n*n%r,e>>=re;return a}let s=[];for(;e>Ee;)s.push(Number(e&Xd)),e>>=Ii;let o=new Array(16);o[0]=re,o[1]=n;for(let a=2;a<16;a++)o[a]=o[a-1]*n%r;let i=o[s[s.length-1]];for(let a=s.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=s[a];c!==0&&(i=i*o[c]%r)}return i}function le(t,e,r){if(r<=re)throw new Error("pow2: expected modulus > 1, got "+r);if(e<Ee)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >Ee;)n*=n,n%=r;return n}function Eu(t,e){if(t===Ee)throw new Error("invert: expected non-zero number");if(e<=re)throw new Error("invert: expected modulus > 1, got "+e);let r=ne(t,e),n=e,s=Ee,o=re;for(;r!==Ee;){let a=n/r,c=n-r*a,u=s-o*a;n=r,r=c,s=o,o=u}if(n!==re)throw new Error("invert: does not exist");return ne(s,e)}function Tu(t,e){if(e<=re)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ne(t,e);if(r===Ee)throw new Error("invertCt: expected non-zero number");let n=_u(r,e-Tt,e);if(ne(r*n,e)!==re)throw new Error("invertCt: does not exist");return n}function Di(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Ri(t,e){if((t&re)===Ee)throw new Error(e+": expected odd modulus, got "+t)}function Cu(t,e){let r=t,n=(r.ORDER+re)/Ii,s=r.pow(e,n);return Di(r,s,e),s}function Jd(t,e){let r=t,n=(r.ORDER-Au)/Bu,s=r.mul(e,Tt),o=r.pow(s,n),i=r.mul(e,o),a=r.mul(r.mul(i,Tt),o),c=r.mul(i,r.sub(a,r.ONE));return Di(r,c,e),c}function ep(t){let e=Lr(t),r=Iu(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Gd)/Lu;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,s),p=u.mul(f,o),b=u.eql(u.sqr(l),c),g=u.eql(u.sqr(d),c);f=u.cmov(f,l,b),l=u.cmov(p,d,g);let m=u.eql(u.sqr(l),c),x=u.cmov(f,l,m);return Di(u,x,c),x})}function Iu(t){if(t<vu)throw new Error("sqrt is not defined for small field");Ri(t,"tonelliShanks");let e=t-re,r=0;for(;e%Tt===Ee;)e/=Tt,r++;let n=Tt,s=Lr(t);for(;tn(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Cu;let o=s.pow(n,e),i=(e+re)/Tt;return function(c,u){let f=c;if(f.is0(u))return u;if(tn(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,o),p=f.pow(u,e),b=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let g=1,m=f.sqr(p);for(;!f.eql(m,f.ONE);)if(g++,m=f.sqr(m),g===l)throw new Error("Cannot find square root");let x=re<<BigInt(l-g-1),E=f.pow(d,x);l=g,d=f.sqr(E),p=f.mul(p,d),b=f.mul(b,E)}return b}}function tp(t){return Ri(t,"Fp.sqrt"),t%Ii===vu?Cu:t%Bu===Au?Jd:t%Lu===Zd?ep(t):Iu(t)}var Du=(t,e)=>(ne(t,e)&re)===re,rp=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Br(t){if(At(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);lt(t.BYTES,"BYTES"),lt(t.BITS,"BITS");for(let e of rp)Wt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=re)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Ss(t,e,r=!1){Br(t),bs(e,"nums"),Ue(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),i),s}function tn(t,e){Br(t);let r=t;Ri(r.ORDER,"FpLegendre");let n=(r.ORDER-re)/Tt,s=r.pow(e,n),o=r.eql(s,r.ONE),i=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!o&&!i&&!a)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function np(t,e){if(e!==void 0&&Ti(e),t<=Ee)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Ar(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var Su=new WeakMap,Es=class{ORDER;BITS;BYTES;isLE;ZERO=Ee;ONE=re;_lengths;_mod;constructor(e,r={}){if(e<=re)throw new Error("invalid field: expected ORDER > 1, got "+e);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:s,nByteLength:o}=np(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(e){return ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return Ee<=e&&e<this.ORDER}is0(e){return e===Ee}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&re)===re}neg(e){return ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ne(e*e,this.ORDER)}add(e,r){return ne(e+r,this.ORDER)}sub(e,r){return ne(e-r,this.ORDER)}mul(e,r){return ne(e*r,this.ORDER)}pow(e,r){return _u(e,r,this.ORDER)}div(e,r){return ne(e*Eu(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Eu(e,this.ORDER)}sqrt(e){let r=Su.get(this);return r||Su.set(this,r=tp(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Jr(e,this.BYTES):xs(e,this.BYTES)}fromBytes(e,r=!1){Z(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(s);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?rt(e):tt(e);if(a&&(c=ne(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Ss(this,e,!0)}cmov(e,r,n){return Ue(n,"condition"),n?r:e}};function Lr(t,e={}){return Object.freeze(Es.prototype),new Es(t,e)}function Ru(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=re)throw new Error("field order must be greater than 1");let e=Ar(t-re);return Math.ceil(e/8)}function vs(t){let e=Ru(t);return e+Math.ceil(e/2)}function As(t,e,r=!1){Z(t);let n=t.length,s=Ru(e),o=Math.max(vs(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?rt(t):tt(t),a=ne(i,e-re)+re;return r?Jr(a,s):xs(a,s)}var Ui=BigInt(0),rn=BigInt(1),sp=BigInt(4),Oi=16,Ou=128,op=5,Pu=2**31;function Ct(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Wt(e.fromAffine,"Point.fromAffine"),Wt(e.fromBytes,"Point.fromBytes"),Wt(e.fromHex,"Point.fromHex"),At(e.BASE,"Point.BASE"),At(e.ZERO,"Point.ZERO"),Br(e.Fp),Br(e.Fn)}function Bs(t,e){Ct(t),Nu(e,t);let r=Ss(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function ip(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function ap(t,e){let r=t*(4*e+128);if(r>Pu)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Pu/2**20+" MiB")}function Ni(t,e){if(t!==void 0){Wt(t,"randomBytes");try{let r=t(e);if(!Lt(r)||r.length!==e)return}catch{return}return t}}function Nu(t,e){bs(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function cp(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,s)=>{if(!(r===void 0?e.isValid(n):Bt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var ku=new WeakMap;function Pi(t){return ku.get(t)||1}function up(t,e){let r=t.double(),n=[t];for(let s=1;s<e;s++)n.push(n[s-1].add(r));return n}function fp(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>Ui;){let i=0;t&rn&&(i=Number(t&s),i>=n&&(i-=r),t-=BigInt(i)),o.push(i),t>>=rn}return o}function lp(t,e,r){let n=2**e,s=n/2,o=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&o);t>>=i,u>s&&(u-=n,t+=rn),a.push(u)}if(t!==Ui)throw new Error("invalid wnaf");return a}function hp(t,e,r){let n=0;for(let o of r)n=Math.max(n,o.length);let s=t;for(let o=n-1;o>=0;o--){o!==n-1&&(s=s.double());for(let i=0;i<r.length;i++){let a=r[i][o];if(a){let c=e[i][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var _r=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Ct(e),this.randomBytes=Ni(r,Oi),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let s=Math.ceil(n/r)+1,o=2**(r-1),i=[],a=e;for(let c=0;c<s;c++){let u=a;for(let f=0;f<o;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:s,comp:i}}wnafCachedCT(e,r){let{W:n,windows:s,comp:o}=e,i=2**(n-1),a=lp(r,n,s),c=this.ZERO,u=this.BASE;for(let f=0;f<s;f++){let l=a[f],d=f*i,p=Math.abs(l)-1,b=o[d];for(let m=1;m<i;m++)b=m===p?o[d+m]:b;let g=b.negate();l===0?u=u.add(o[d]):c=c.add(l<0?g:b)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,s){let o=this.wnafPrecomputes.get(r),i=o?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof s=="function"&&(i={...i,comp:s(i.comp)}),o||(o=[],this.wnafPrecomputes.set(r,o)),o.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!Ci(r,rn,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Pi(e);return o===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(o,e,n,s),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+Ou,o=this.randomBytes(Oi);if(!Lt(o)||o.length!==Oi)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let i=r+tt(o)*this.Point.Fn.ORDER;return this.runCT(e,i,s,n)}fixedWindowCT(e,r,n){let s=op,o=1<<s,i=en(s),a=new Array(o);a[0]=this.ZERO;for(let f=1;f<o;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/s),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<s;p++)u=u.double();let l=Number(r>>BigInt(f*s)&i),d=a[0];for(let p=1;p<o;p++)d=p===l?a[p]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===rn?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,s){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,s):this.mulCT(e,r,s)}mulUnsafe(e,r,n){if(this.assertPoint(e),!Bt(r))throw new Error("invalid scalar");let s=Pi(e);if(s===1||r>=this.Point.Fn.ORDER)return Ls(this.Point,[e],[r],!0);let o=this.getWnafPrecomputes(s,e,this.bits,n);return this.wnafCachedCT(o,r).p}setWindowSize(e,r){this.assertPoint(e),ip(r,this.bits);let n=Math.ceil((this.bits+Ou)/r)+1;ap(n*2**(r-1),this.Point.Fp.BYTES),ku.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Pi(e)!==1}};function Ls(t,e,r,n=!1){if(Ct(t),Nu(e,t),Ue(n,"allowOversized"),cp(r,t.Fn,n?t.Fn.ORDER**sp:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(i=>up(i,4)),o=r.map(i=>fp(i,4));return hp(t.ZERO,s,o)}function Uu(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Br(e),e}else return Lr(t,{isLE:r})}function _s(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Ie(r);for(let c of["p","n","h"]){let u=e[c];if(!(Bt(u)&&u!==Ui))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Uu(e.p,r.Fp,n),o=Uu(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function Tr(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var Ts=BigInt(0),Cs=BigInt(1),Is=BigInt(2),dp=BigInt(4),Mu=BigInt(8);function pp(t,e,r,n){let s=t.sqr(r),o=t.sqr(n),i=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(i,a)}function Ku(t,e={}){Ie(e,{},{},"extraOpts");let r=e,n=_s("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;if(tn(s,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(tn(s,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Ie(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?ft:r.randomBytes,u=Is<<BigInt(s.BYTES*8)-Cs;function f(E){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(E)}let l=r.uvRatio===void 0?(E,w)=>{try{return{isValid:!0,value:s.sqrt(s.div(E,w))}}catch{return{isValid:!1,value:Ts}}}:r.uvRatio;if(!pp(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=s.eql(i.a,s.neg(s.ONE))?E=>s.neg(E):s.eql(i.a,s.ONE)?E=>E:E=>s.mul(i.a,E);function p(E,w,A=!1){let L=A?Cs:Ts;return nt("coordinate "+E,w,L,u),w}function b(E){if(!(E instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(i.Gx,i.Gy,s.ONE,s.mul(i.Gx,i.Gy));static ZERO=new g(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=o;X;Y;Z;T;constructor(w,A,L,R){this.X=p("x",w),this.Y=p("y",A),this.Z=p("z",L,!0),this.T=p("t",R),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof g)throw new Error("extended point not allowed");let{x:A,y:L}=w||{};return p("x",A),p("y",L),new g(A,L,s.ONE,s.mul(A,L))}static fromBytes(w,A=!1){let L=s.BYTES,{a:R,d:q}=i;w=_t(Z(w,L,"point")),Ue(A,"zip215");let O=_t(w),I=w[L-1];O[L-1]=I&-129;let D=rt(O),k=A?u:s.ORDER;nt("point.y",D,Ts,k);let K=s.sqr(D),z=s.sub(K,s.ONE),_=s.sub(s.mulN(q,K),R),{isValid:U,value:T}=l(z,_);if(!U)throw new Error("bad point: invalid y coordinate");let B=f(T),F=(I&128)!==0;if(!A&&s.is0(T)&&F)throw new Error("bad point: x=0 and x_0=1");return F!==B&&(T=s.neg(T)),g.fromAffine({x:T,y:D})}static fromHex(w,A=!1){return g.fromBytes(vr(w),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=6,A=!0){return x.setWindowSize(this,w),A||this.multiply(Is),this}assertValidity(){let w=this,{a:A,d:L}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:R,Y:q,Z:O,T:I}=w,D=s.sqr(R),k=s.sqr(q),K=s.sqr(O),z=s.sqr(K),_=s.mul(D,A),U=s.mul(s.add(_,k),K),T=s.add(z,s.mul(L,s.mul(D,k)));if(!s.eql(U,T))throw new Error("bad point: equation left != right (1)");let B=s.mul(R,q),F=s.mul(O,I);if(!s.eql(B,F))throw new Error("bad point: equation left != right (2)")}equals(w){b(w);let{X:A,Y:L,Z:R}=this,{X:q,Y:O,Z:I}=w,D=s.mul(A,I),k=s.mul(q,R),K=s.mul(L,I),z=s.mul(O,R);return s.eql(D,k)&&s.eql(K,z)}is0(){return this.equals(g.ZERO)}negate(){return new g(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:w,Y:A,Z:L}=this,R=s.sqr(w),q=s.sqr(A),O=s.mul(s.sqr(L),Is),I=d(R),D=s.addN(w,A),k=s.sub(s.subN(s.sqr(D),R),q),K=s.addN(I,q),z=s.subN(K,O),_=s.subN(I,q),U=s.mul(k,z),T=s.mul(K,_),B=s.mul(k,_),F=s.mul(z,K);return new g(U,T,F,B)}add(w){b(w);let{d:A}=i,{X:L,Y:R,Z:q,T:O}=this,{X:I,Y:D,Z:k,T:K}=w,z=s.mul(L,I),_=s.mul(R,D),U=s.mul(s.mulN(O,A),K),T=s.mul(q,k),B=s.sub(s.subN(s.mulN(s.addN(L,R),s.addN(I,D)),z),_),F=s.subN(T,U),C=s.addN(T,U),S=s.sub(_,d(z)),h=s.mul(B,F),y=s.mul(C,S),v=s.mul(B,S),P=s.mul(F,C);return new g(h,y,P,v)}subtract(w){return b(w),this.add(w.negate())}multiply(w){if(!o.isValidNot0(w))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:L}=x.mulSecret(this,w,a,m);return m([A,L])[0]}multiplyUnsafe(w){if(!o.isValid(w))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return w===Ts?g.ZERO:this.is0()||w===Cs?this:x.mulUnsafe(this,w,m)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(w){let A=this,L=w;if(L!=null&&typeof L!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof L);let{X:R,Y:q,Z:O}=A,I=A.is0();L==null&&(L=I?s.create(Mu):s.inv(O));let D=s.mul(R,L),k=s.mul(q,L),K=s.mul(O,L);if(I)return{x:s.ZERO,y:s.ONE};if(!s.eql(K,s.ONE))throw new Error("invZ was invalid");return{x:D,y:k}}clearCofactor(){return a===Cs?this:a===Is?this.double():a===dp?this.double().double():a===Mu?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:w,y:A}=this.toAffine(),L=s.toBytes(A);return L[L.length-1]|=f(w)?128:0,L}toHex(){return Xr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=E=>Bs(g,E),x=new _r(g,c);return x.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function Fu(t,e,r={}){if(Ct(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;Ie(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(lt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=s.randomBytes===void 0?ft:s.randomBytes,d=s.toMontgomery,p=s.toMontgomerySecret,b=s.adjustScalarBytes===void 0?_=>_:s.adjustScalarBytes,g=s.domain===void 0?(_,U,T)=>{if(Ue(T,"phflag"),U.length||T)throw new Error("Contexts/pre-hash are not supported");return _}:s.domain;function m(_){return c.create(rt(_))}function x(_){let U=I.secretKey;Z(_,I.secretKey,"secretKey");let T=Z(n(_),2*U,"hashedSecretKey"),B=b(T.slice(0,U)),F=T.slice(U,2*U),C=m(B);return{head:B,prefix:F,scalar:C}}function E(_){let{head:U,prefix:T,scalar:B}=x(_),F=i.multiply(B),C=F.toBytes();return{head:U,prefix:T,scalar:B,point:F,pointBytes:C}}function w(_){return E(_).pointBytes}function A(_=Uint8Array.of(),...U){let T=qe(...U);return m(n(g(T,Z(_,void 0,"context"),!!o)))}function L(_,U,T={}){Ie(T,{},{},"options"),_=_t(Z(_,void 0,"message")),o&&(_=o(_));let{prefix:B,scalar:F,pointBytes:C}=E(U),S=A(T.context,B,_),h=i.multiply(S).toBytes(),y=A(T.context,h,C,_),v=c.create(S+y*F);if(!c.isValid(v))throw new Error("sign failed: invalid s");let P=qe(h,c.toBytes(v));return Z(P,I.signature,"result")}let R={zip215:s.zip215};function q(_,U,T,B=R){Ie(B);let{context:F}=B,C=B.zip215===void 0?!!R.zip215:B.zip215,S=I.signature;_=Z(_,S,"signature"),U=Z(U,void 0,"message"),T=Z(T,I.publicKey,"publicKey"),C!==void 0&&Ue(C,"zip215"),o&&(U=o(U));let h=S/2,y=_.subarray(0,h),v=rt(_.subarray(h,S)),P,N,M;try{P=t.fromBytes(T,C),N=t.fromBytes(y,C),M=i.multiplyUnsafe(v)}catch{return!1}if(!C&&P.isSmallOrder())return!1;let H=A(F,y,T,U);return N.add(P.multiplyUnsafe(H)).subtract(M).clearCofactor().is0()}let O=a.BYTES,I={secretKey:O,publicKey:O,signature:2*O,seed:O};function D(_){return _=_===void 0?l(I.seed):_,Z(_,I.seed,"seed")}function k(_){return Lt(_)&&_.length===I.secretKey}function K(_,U){try{return!!t.fromBytes(_,U===void 0?R.zip215:U)}catch{return!1}}let z={getExtendedPublicKey:E,randomSecretKey:D,isValidSecretKey:k,isValidPublicKey:K,toMontgomery(_){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(t.fromBytes(_))},toMontgomerySecret(_){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(_)}};return Object.freeze(I),Object.freeze(z),Object.freeze({keygen:Tr(D,w),getPublicKey:w,sign:L,verify:q,utils:z,Point:t,lengths:I})}var Yt=BigInt(0),ze=BigInt(1),Ds=BigInt(2);function Hu(t,e){return t+e-(e>>ze<<ze)}function mp(t){let e=BigInt(6)*t;return(r,n,s)=>{let o=n+s,a=((e+s-n)*r+n)%t;return{x_2:a,x_3:o-a}}}function yp(t){return Ie(t,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function",scalarMultBase:"function"}),Object.freeze({...t})}function qu(t){let e=yp(t),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=e,a=e.scalarMultBase,c=n==="x25519";if(!c&&n!=="x448")throw new Error("invalid type");let u=i===void 0?ft:i,f=c?255:448,l=mp(r),d=c?32:56,p=BigInt(c?9:5),b=BigInt(c?121665:39081),g=c?Ds**BigInt(254):Ds**BigInt(447),m=c?BigInt(8)*(Ds**BigInt(251)-ze):BigInt(4)*(Ds**BigInt(445)-ze),x=g+m+ze,E=T=>ne(T,r),w=A(p);function A(T){return Jr(E(T),d)}function L(T){let B=_t(Z(T,d,"uCoordinate"));return c&&(B[31]&=127),E(rt(B))}function R(T){return rt(s(_t(Z(T,d,"scalar"))))}let q=new Set(c?[Yt,ze,r-ze,BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")]:[Yt,ze,r-ze]);function O(T,B){let F=L(B);if(q.has(F))throw new Error("invalid private or public key received");let C=K(F,R(T));if(C===Yt)throw new Error("invalid private or public key received");return A(C)}function I(T){if(a===void 0)return O(T,w);let B=R(T);nt("scalar",B,g,x);let F=E(a(B));if(F===Yt)throw new Error("invalid private or public key received");return A(F)}let D=I,k=O;function K(T,B){nt("u",T,Yt,r),nt("scalar",B,g,x);let F=B,C=T,S=ze,h=Yt,y=T,v=ze,P=F^F>>ze;for(let H=BigInt(f-1);H>=Yt;H--){let $=Hu(r,P>>H);({x_2:S,x_3:y}=l($,S,y)),{x_2:h,x_3:v}=l($,h,v);let j=S+h,Y=E(j*j),ce=S-h,ie=E(ce*ce),ye=Y-ie,Pe=y+v,ae=y-v,he=E(ae*j),or=E(Pe*ce),Nr=he+or,mt=he-or;y=E(Nr*Nr),v=E(C*E(mt*mt)),S=E(Y*ie),h=E(ye*(Y+E(b*ye)))}let N=Hu(r,F);({x_2:S,x_3:y}=l(N,S,y)),{x_2:h,x_3:v}=l(N,h,v);let M=o(h);return E(S*M)}let z={secretKey:d,publicKey:d,seed:d},_=T=>(T=T===void 0?u(d):T,Z(T,z.seed,"seed"),T),U={randomSecretKey:_};return Object.freeze(z),Object.freeze(U),Object.freeze({keygen:Tr(_,D),getSharedSecret:k,getPublicKey:D,scalarMult:O,scalarMultBase:I,utils:U,GuBytes:w.slice(),lengths:z})}var zu=BigInt(0),ki=BigInt(1),$u=BigInt(2),gp=BigInt(3),bp=BigInt(5),wp=BigInt(8),Rs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),xp={p:Rs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:wp,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Wu(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=Rs,a=t*t%o*t%o,c=le(a,$u,o)*a%o,u=le(c,ki,o)*t%o,f=le(u,bp,o)*u%o,l=le(f,e,o)*f%o,d=le(l,r,o)*l%o,p=le(d,n,o)*d%o,b=le(p,s,o)*p%o,g=le(b,s,o)*p%o,m=le(g,e,o)*f%o;return{pow_p_5_8:le(m,$u,o)*t%o,b2:a}}function Mi(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Vu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ep(t,e){let r=Rs,n=ne(e*e*e,r),s=ne(n*n*e,r),o=Wu(t*s).pow_p_5_8,i=ne(t*n*o,r),a=ne(e*i*i,r),c=i,u=ne(i*Vu,r),f=a===t,l=a===ne(-t,r),d=a===ne(-t*Vu,r);return f&&(i=c),(l||d)&&(i=u),Du(i,r)&&(i=ne(-i,r)),{isValid:f||l,value:i}}var nn=Ku(xp,{uvRatio:Ep}),ju=nn.Fp;function Sp(t){let{y:e}=t;return ju.toBytes(ju.div(ki+e,ki-e))}function vp(t){let e=nn.Fp.BYTES;return Oe(t,e),Mi(_i(t.subarray(0,e))).subarray(0,e)}function Ap(t){return Fu(nn,_i,Object.assign({adjustScalarBytes:Mi,toMontgomery:Sp,toMontgomerySecret:vp,zip215:!0},t))}var Yu=Ap({});var sn=(()=>{let t=Rs,e=r=>{let{pow_p_5_8:n,b2:s}=Wu(r);return ne(le(n,gp,t)*s,t)};return qu({P:t,type:"x25519",powPminus2:e,adjustScalarBytes:Mi,scalarMultBase:r=>{let n=ne(r,nn.Fn.ORDER);if(n===zu)return zu;let s=nn.BASE.multiply(n);return ne((s.Z+s.Y)*e(ne(s.Z-s.Y,t)),t)}})})();var Os=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(jt(e),Oe(r,void 0,"key"),this.iHash=e.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,s=new Uint8Array(n);s.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),He(s)}update(e){return Sr(this),this.iHash.update(e),this}digestInto(e){Sr(this),ds(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},on=(()=>{let t=((e,r,n)=>new Os(e,r).update(n).digest());return t.create=(e,r)=>new Os(e,r),t})();function Gu(t,e,r){return jt(t),r===void 0&&(r=new Uint8Array(t.outputLen)),on(t,r,e)}var an=Uint8Array.of(0),Bp=Uint8Array.of();function Zu(t,e,r,n=32,s){jt(t),Ye(n,"length"),Oe(e,void 0,"prk");let o=t.outputLen;if(e.length<o)throw new Error('"prk" must be at least HashLen octets');if(n>255*o)throw new Error("Length must be <= 255*HashLen");let i=Math.ceil(n/o);if(r===void 0?r=Bp:Oe(r,void 0,"info"),!i)return s&&He(e),new Uint8Array;let a=s&&i===1?e:new Uint8Array(i*o),{iHash:c,oHash:u}=on.create(t,e),f=s?e:new Uint8Array(o),l=i>1?s?.iHash||t.create():void 0;for(let p=0;p<i-1;p++){an[0]=p+1;let b=c._cloneInto(l);p&&b.update(f),b.update(r).update(an).digestInto(f),u._cloneInto(l).update(f).digestInto(f),a.set(f,o*p)}if(an[0]=i,i>1&&c.update(f),c.update(r).update(an).digestInto(f),u.update(f).digestInto(f),a.set(f,o*(i-1)),c.destroy(),u.destroy(),l?.destroy(),f!==a&&He(f),He(an),n===a.length)return a;let d=a.slice(0,n);return He(a),d}var Xu={hashSHA256(t){return et(t.subarray())},getHKDF(t,e){let r=Gu(et,e,t),s=Zu(et,r,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let t=sn.utils.randomSecretKey();return{publicKey:sn.getPublicKey(t),privateKey:t}},generateX25519KeyPairFromSeed(t){return{publicKey:sn.getPublicKey(t),privateKey:t}},generateX25519SharedKey(t,e){return sn.getSharedSecret(t.subarray(),e.subarray())},chaCha20Poly1305Encrypt(t,e,r,n){return yi(n,e,r).encrypt(t.subarray())},chaCha20Poly1305Decrypt(t,e,r,n,s){return yi(n,e,r).decrypt(t.subarray(),s)}};var Qu=Xu;function Ju(t){return{generateKeypair:t.generateX25519KeyPair,dh:(e,r)=>t.generateX25519SharedKey(e.privateKey,r).subarray(0,32),encrypt:t.chaCha20Poly1305Encrypt,decrypt:t.chaCha20Poly1305Decrypt,hash:t.hashSHA256,hkdf:t.getHKDF}}var Cr=t=>{let e=Se(2);return e[0]=t>>8,e[1]=t,e};Cr.bytes=2;var Ir=t=>{if(t.length<2)throw RangeError("Could not decode int16BE");if(t instanceof Uint8Array){let e=0;return e+=t[0]<<8,e+=t[1],e}return t.getUint16(0)};Ir.bytes=2;function ef(t){return{xxHandshakeSuccesses:t.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:t.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:t.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:t.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:t.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Ki(t,e){!e.enabled||!xr||(t?(e(`LOCAL_STATIC_PUBLIC_KEY ${W(t.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${W(t.privateKey,"hex")}`)):e("Missing local static keys."))}function Fi(t,e){!e.enabled||!xr||(t?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${W(t.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${W(t.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function tf(t,e){!e.enabled||!xr||e(t?`REMOTE_STATIC_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote static public key.")}function Hi(t,e){!e.enabled||!xr||e(t?`REMOTE_EPHEMERAL_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function qi(t,e,r){!r.enabled||!xr||(r(`CIPHER_STATE_1 ${t.n.getUint64()} ${t.k&&W(t.k,"hex")}`),r(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&W(e.k,"hex")}`))}var Dr=class t extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=t.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Lp=0,_p=4294967295,Tp="Cipherstate has reached maximum n, a new handshake must be performed",Ps=class{n;bytes;view;constructor(e=Lp){this.n=e,this.bytes=be(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>_p)throw new Error(Tp)}};var Gt=be(0),Rr=class{k;n;crypto;constructor(e,r=void 0,n=0){this.crypto=e,this.k=r,this.n=new Ps(n)}hasKey(){return!!this.k}encryptWithAd(e,r){if(!this.hasKey())return r;this.n.assertValue();let n=this.crypto.encrypt(r,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,r,n){if(!this.hasKey())return r;this.n.assertValue();let s=this.crypto.decrypt(r,this.n.getBytes(),e,this.k,n);return this.n.increment(),s}},zi=class{cs;ck;h;crypto;constructor(e,r){this.crypto=e;let n=ee(r,"utf-8");this.h=Cp(e,n),this.ck=this.h,this.cs=new Rr(e)}mixKey(e){let[r,n]=this.crypto.hkdf(this.ck,e);this.ck=r,this.cs=new Rr(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new Q(this.h,e))}encryptAndHash(e){let r=this.cs.encryptWithAd(this.h,e);return this.mixHash(r),r}decryptAndHash(e){let r=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),r}split(){let[e,r]=this.crypto.hkdf(this.ck,Gt);return[new Rr(this.crypto,e),new Rr(this.crypto,r)]}},$i=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=e;this.crypto=r,this.ss=new zi(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<r+32)throw new Error("message is not long enough");this.re=e.sublist(r,r+32),this.ss.mixHash(this.re)}readS(e,r=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<r+n)throw new Error("message is not long enough");let s=e.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},cn=class extends $i{writeMessageA(e){return new Q(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new Q(r,n,this.ss.encryptAndHash(e))}writeMessageC(e){let r=this.writeS();return this.writeSE(),new Q(r,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(r){throw new Dr(`handshake stage 0 validation fail: ${r.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let r=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+r))}catch(r){throw new Dr(`handshake stage 1 validation fail: ${r.message}`)}}readMessageC(e){try{let r=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(r))}catch(r){throw new Dr(`handshake stage 2 validation fail: ${r.message}`)}}};function Cp(t,e){if(e.length<=32){let r=be(32);return r.set(e),r}else return t.hash(e)}async function rf(t,e,r,n){let s=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,Ae(e),Ae(r.subarray()));return n?.signal?.throwIfAborted(),o}var Ip=parseInt("11111",2),Vi=parseInt("10000000",2),Dp=parseInt("01111111",2),nf={0:un,1:un,2:Rp,3:Up,4:Np,5:Pp,6:Op,16:un,22:un,48:un};function ht(t,e={offset:0}){let r=t[e.offset]&Ip;if(e.offset++,nf[r]!=null)return nf[r](t,e);throw new Error("No decoder for tag "+r)}function fn(t,e){let r=0;if((t[e.offset]&Vi)===Vi){let n=t[e.offset]&Dp,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");s+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function un(t,e){fn(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=ht(t,e);if(n===null)break;r.push(n)}return r}function Rp(t,e){let r=fn(t,e),n=e.offset,s=e.offset+r,o=[];for(let i=n;i<s;i++)i===n&&t[i]===0||o.push(t[i]);return e.offset+=r,Uint8Array.from(o)}function Op(t,e){let r=fn(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Pp(t,e){return e.offset++,null}function Up(t,e){let r=fn(t,e),n=t[e.offset];e.offset++;let s=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Np(t,e){let r=fn(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function kp(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Q;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function ji(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=kp(t.byteLength);return new Q(Uint8Array.from([e.byteLength|Vi]),e)}function Ne(t){let e=new Q,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Q(Uint8Array.from([2]),ji(e),e)}function Us(t){let e=Uint8Array.from([0]),r=new Q(e,t);return new Q(Uint8Array.from([3]),ji(r),r)}function It(t,e=48){let r=new Q;for(let n of t)r.append(n);return new Q(Uint8Array.from([e]),ji(r),r)}var Mp=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Kp=Uint8Array.from([6,5,43,129,4,0,34]),Fp=Uint8Array.from([6,5,43,129,4,0,35]),Hp={ext:!0,kty:"EC",crv:"P-256"},qp={ext:!0,kty:"EC",crv:"P-384"},zp={ext:!0,kty:"EC",crv:"P-521"},Wi=32,Yi=48,Gi=66;function Zi(t){let e=ht(t);return sf(e)}function sf(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===Wi*2+1)return n=W(e.subarray(r,r+Wi),"base64url"),s=W(e.subarray(r+Wi),"base64url"),new Or({...Hp,key_ops:["verify"],x:n,y:s});if(e.byteLength===Yi*2+1)return n=W(e.subarray(r,r+Yi),"base64url"),s=W(e.subarray(r+Yi),"base64url"),new Or({...qp,key_ops:["verify"],x:n,y:s});if(e.byteLength===Gi*2+1)return n=W(e.subarray(r,r+Gi),"base64url"),s=W(e.subarray(r+Gi),"base64url"),new Or({...zp,key_ops:["verify"],x:n,y:s});throw new se(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function of(t){return It([Ne(Uint8Array.from([1])),It([$p(t.crv)],160),It([Us(new Q(Uint8Array.from([4]),ee(t.x??"","base64url"),ee(t.y??"","base64url")))],161)]).subarray()}function $p(t){if(t==="P-256")return Mp;if(t==="P-384")return Kp;if(t==="P-521")return Fp;throw new se(`Invalid curve ${t}`)}var Or=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=of(this.jwk)),this._raw}toMultihash(){return je.digest(Dt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}async verify(e,r,n){return rf(this.jwk,r,e,n)}};var ln=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Ns=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var $e={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Ns("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 e}};var ks=32;var Xi,Vp=(async()=>{try{return await $e.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function jp(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await $e.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await $e.get().subtle.verify({name:"Ed25519"},n,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Wp(t,e,r){return Yu.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function af(t,e,r){return Xi==null&&(Xi=await Vp),Xi?jp(t,e,r):Wp(t,e,r)}function Ms(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Ks=class{type="Ed25519";raw;constructor(e){this.raw=Qi(e,ks)}toMultihash(){return je.digest(Dt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=af(this.raw,r,e);return Ms(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function Ji(t){return t=Qi(t,ks),new Ks(t)}function Qi(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new se(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var ea=new Float32Array([-0]),Rt=new Uint8Array(ea.buffer);function uf(t,e,r){ea[0]=t,e[r]=Rt[0],e[r+1]=Rt[1],e[r+2]=Rt[2],e[r+3]=Rt[3]}function ff(t,e){return Rt[0]=t[e],Rt[1]=t[e+1],Rt[2]=t[e+2],Rt[3]=t[e+3],ea[0]}var ta=new Float64Array([-0]),De=new Uint8Array(ta.buffer);function lf(t,e,r){ta[0]=t,e[r]=De[0],e[r+1]=De[1],e[r+2]=De[2],e[r+3]=De[3],e[r+4]=De[4],e[r+5]=De[5],e[r+6]=De[6],e[r+7]=De[7]}function hf(t,e){return De[0]=t[e],De[1]=t[e+1],De[2]=t[e+2],De[3]=t[e+3],De[4]=t[e+4],De[5]=t[e+5],De[6]=t[e+6],De[7]=t[e+7],ta[0]}var Gp=BigInt(Number.MAX_SAFE_INTEGER),Zp=BigInt(Number.MIN_SAFE_INTEGER),ke=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&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(e=!1){if(e)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(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Zt;if(e<Gp&&e>Zp)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,s=e-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>df&&(s=0n,++n>df&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return Zt;let r=e<0;r&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new t(n,s)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Zt}},Zt=new ke(0,0);Zt.toBigInt=function(){return 0n};Zt.zzEncode=Zt.zzDecode=function(){return this};Zt.length=function(){return 1};var df=4294967296n;function pf(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function mf(t,e,r){if(r-e<1)return"";let s,o=[],i=0,a;for(;e<r;)a=t[e++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function ra(t,e,r){let n=r,s,o;for(let i=0;i<t.length;++i)s=t.charCodeAt(i),s<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=s&63|128):(s&64512)===55296&&((o=t.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=s&63|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=s&63|128);return r-n}function Ze(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Fs(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var na=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ae(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ze(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ze(this,4);return Fs(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ze(this,4);return Fs(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ze(this,4);let e=ff(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ze(this,4);let e=hf(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ze(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return mf(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ze(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ze(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new ke(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ze(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ze(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ze(this,8);let e=Fs(this.buf,this.pos+=4),r=Fs(this.buf,this.pos+=4);return new ke(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=_o(this.buf,this.pos);return this.pos+=Te(e),e}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 hn(t){return new na(t instanceof Uint8Array?t:t.subarray())}function Xt(t,e,r){let n=hn(t);return e.decode(n,void 0,r)}function sa(t){let e=t??8192,r=e>>>1,n,s=e;return function(i){if(i<1||i>r)return Se(i);s+i>e&&(n=Se(e),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var Qt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function oa(){}var aa=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Xp=sa();function Qp(t){return globalThis.Buffer!=null?Se(t):Xp(t)}var pn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Qt(oa,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Qt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ca((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Hs,10,ke.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ke.fromBigInt(e);return this._push(Hs,r.length(),r)}uint64Number(e){return this._push(dr,Te(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=ke.fromBigInt(e).zzEncode();return this._push(Hs,r.length(),r)}sint64Number(e){let r=ke.fromNumber(e).zzEncode();return this._push(Hs,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ia,1,e?1:0)}fixed32(e){return this._push(dn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ke.fromBigInt(e);return this._push(dn,4,r.lo)._push(dn,4,r.hi)}fixed64Number(e){let r=ke.fromNumber(e);return this._push(dn,4,r.lo)._push(dn,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(uf,4,e)}double(e){return this._push(lf,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(ia,1,0):this.uint32(r)._push(em,r,e)}string(e){let r=pf(e);return r!==0?this.uint32(r)._push(ra,r,e):this._push(ia,1,0)}fork(){return this.states=new aa(this),this.head=this.tail=new Qt(oa,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 Qt(oa,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Qp(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function ia(t,e,r){e[r]=t&255}function Jp(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ca=class extends Qt{next;constructor(e,r){super(Jp,e,r),this.next=void 0}};function Hs(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function dn(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function em(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(pn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(tm,e,t),this},pn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(rm,e,t),this});function tm(t,e,r){e.set(t,r)}function rm(t,e,r){t.length<40?ra(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ee(t),r)}function ua(){return new pn}function Jt(t,e){let r=ua();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*er(t,e,r){let n=hn(t);yield*e.stream(n,void 0,".",r)}var qs={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function zs(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function fa(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},s=function*(i,a){};return zs("enum",qs.VARINT,r,n,s)}function tr(t,e,r){return zs("message",qs.LENGTH_DELIMITED,t,e,r)}var rr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var de;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(de||(de={}));var la;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(la||(la={}));(function(t){t.codec=()=>fa(la)})(de||(de={}));var st;(function(t){let e;t.codec=()=>(e==null&&(e=tr((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),de.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:de.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Jt(o,t.codec())}t.encode=r;function n(o,i){return Xt(o,t.codec(),i)}t.decode=n;function s(o,i){return er(o,t.codec(),i)}t.stream=s})(st||(st={}));var ha;(function(t){let e;t.codec=()=>(e==null&&(e=tr((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),de.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:de.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Jt(o,t.codec())}t.encode=r;function n(o,i){return Xt(o,t.codec(),i)}t.decode=n;function s(o,i){return er(o,t.codec(),i)}t.stream=s})(ha||(ha={}));var yn={};Re(yn,{MAX_RSA_KEY_SIZE:()=>da,generateRSAKeyPair:()=>Ef,jwkToJWKKeyPair:()=>Sf,jwkToPkcs1:()=>im,jwkToPkix:()=>ga,jwkToRSAPrivateKey:()=>Ea,pkcs1MessageToJwk:()=>ma,pkcs1MessageToRSAPrivateKey:()=>ba,pkcs1ToJwk:()=>om,pkcs1ToRSAPrivateKey:()=>xf,pkixMessageToJwk:()=>ya,pkixMessageToRSAPublicKey:()=>xa,pkixToJwk:()=>am,pkixToRSAPublicKey:()=>wa});var Pr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=yn.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return xe.createV1(114,this._multihash)}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}verify(e,r,n){return wf(this.jwk,r,e,n)}},mn=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=yn.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}sign(e,r){return bf(this.jwk,e,r)}};var da=8192,pa=18,nm=1062,sm=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function om(t){let e=ht(t);return ma(e)}function ma(t){return{n:W(t[1],"base64url"),e:W(t[2],"base64url"),d:W(t[3],"base64url"),p:W(t[4],"base64url"),q:W(t[5],"base64url"),dp:W(t[6],"base64url"),dq:W(t[7],"base64url"),qi:W(t[8],"base64url"),kty:"RSA"}}function im(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new se("JWK was missing components");return It([Ne(Uint8Array.from([0])),Ne(ee(t.n,"base64url")),Ne(ee(t.e,"base64url")),Ne(ee(t.d,"base64url")),Ne(ee(t.p,"base64url")),Ne(ee(t.q,"base64url")),Ne(ee(t.dp,"base64url")),Ne(ee(t.dq,"base64url")),Ne(ee(t.qi,"base64url"))]).subarray()}function am(t){let e=ht(t,{offset:0});return ya(e)}function ya(t){let e=ht(t[1],{offset:0});return{kty:"RSA",n:W(e[0],"base64url"),e:W(e[1],"base64url")}}function ga(t){if(t.n==null||t.e==null)throw new se("JWK was missing components");return It([sm,Us(It([Ne(ee(t.n,"base64url")),Ne(ee(t.e,"base64url"))]))]).subarray()}function xf(t){let e=ht(t);return ba(e)}function ba(t){let e=ma(t);return Ea(e)}function wa(t,e){if(t.byteLength>=nm)throw new Ot("Key size is too large");let r=ht(t,{offset:0});return xa(r,t,e)}function xa(t,e,r){let n=ya(t);if(r==null){let s=et(st.encode({Type:de.RSA,Data:e}));r=Ve(pa,s)}return new Pr(n,r)}function Ea(t){if(Af(t)>da)throw new se("Key size is too large");let e=Sf(t),r=et(st.encode({Type:de.RSA,Data:ga(e.publicKey)})),n=Ve(pa,r);return new mn(e.privateKey,new Pr(e.publicKey,n))}async function Ef(t){if(t>da)throw new se("Key size is too large");let e=await vf(t),r=et(st.encode({Type:de.RSA,Data:ga(e.publicKey)})),n=Ve(pa,r);return new mn(e.privateKey,new Pr(e.publicKey,n))}function Sf(t){if(t==null)throw new se("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function vf(t,e){let r=await $e.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await cm(r,e);return{privateKey:n[0],publicKey:n[1]}}async function bf(t,e,r){let n=await $e.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await $e.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Ae(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function wf(t,e,r,n){let s=await $e.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await $e.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function cm(t,e){if(t.privateKey==null||t.publicKey==null)throw new se("Private and public key are required");let r=await Promise.all([$e.get().subtle.exportKey("jwk",t.privateKey),$e.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Af(t){if(t.kty!=="RSA")throw new se("invalid key type");if(t.n==null)throw new se("invalid key modulus");return ee(t.n,"base64url").length*8}var um=BigInt(0),Sa=class extends Error{constructor(e=""){super(e)}},dt={Err:Sa,_tlv:{encode:(t,e)=>{let{Err:r}=dt;if(lt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(bu(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=Qr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Qr(s.length/2|128):"";return Qr(t)+o+s+e},decode(t,e){let{Err:r}=dt;e=Z(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&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=e.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 f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=dt;if(ws(t),t<um)throw new e("integer: negative integers are not allowed");let r=Qr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=dt;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return tt(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=dt;if(e!==void 0&&(lt(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let o=Z(t,void 0,"signature"),{v:i,l:a}=s.decode(48,o);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=s.decode(2,i),{v:f,l}=s.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=dt;Ie(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}},$s=(Object.freeze(dt._tlv),Object.freeze(dt._int),Object.freeze(dt));var Bf=(t,e)=>(t+(t>=0?e:-e)/Lf)/e;function fm(t,e,r){nt("scalar",t,pt,r);let[[n,s],[o,i]]=e,a=Bf(i*t,r),c=Bf(-s*t,r),u=t-a*n-c*o,f=-a*s-c*i,l=u<pt,d=f<pt;l&&(u=-u),d&&(f=-f);let p=en(Math.ceil(Ar(r)/2))+nr;if(u<pt||u>=p||f<pt||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Ba(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function va(t,e){Ie(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ue(r.lowS,"lowS"),Ue(r.prehash,"prehash"),r.format!==void 0&&Ba(r.format),r}var pt=BigInt(0),nr=BigInt(1),Lf=BigInt(2),Aa=BigInt(3),lm=BigInt(4);function _f(t,e={}){let r=_s("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;Ie(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:d,toBytes:p}=e,b=e.randomBytes===void 0?ft:e.randomBytes;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let g=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,m=Cf(n,s);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function E(S,h,y){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:v,y:P}=h.toAffine(),N=n.toBytes(v);if(Ue(y,"isCompressed"),y){x();let M=!n.isOdd(P);return qe(Tf(M),N)}else return qe(Uint8Array.of(4),N,n.toBytes(P))}function w(S){Z(S,void 0,"Point");let{publicKey:h,publicKeyUncompressed:y}=m,v=S.length,P=S[0],N=S.subarray(1);if(u&&v===1&&P===0)return{x:n.ZERO,y:n.ZERO};if(v===h&&(P===2||P===3)){let M=n.fromBytes(N);if(!n.isValid(M))throw new Error("bad point: is not on curve, wrong x");let H=O(M),$;try{$=n.sqrt(H)}catch(ce){let ie=ce instanceof Error?": "+ce.message:"";throw new Error("bad point: is not on curve, sqrt error"+ie)}x();let j=n.isOdd($);return(P&1)===1!==j&&($=n.neg($)),{x:M,y:$}}else if(v===y&&P===4){let M=n.BYTES,H=n.fromBytes(N.subarray(0,M)),$=n.fromBytes(N.subarray(M,M*2));if(!I(H,$))throw new Error("bad point: is not on curve");return{x:H,y:$}}else throw new Error(`bad point: got length ${v}, expected compressed=${h} or uncompressed=${y}`)}let A=p===void 0?E:p,L=d===void 0?w:d,R=n.mul(o.b,Aa),q=n.is0(o.a)?S=>n.ZERO:S=>n.mul(o.a,S);function O(S){let h=n.sqr(S),y=n.mul(h,S);return n.add(n.add(y,n.mul(S,o.a)),o.b)}function I(S,h){let y=n.sqr(h),v=O(S);return n.eql(y,v)}if(!I(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let D=n.mul(n.pow(o.a,Aa),lm),k=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(D,k)))throw new Error("bad curve params: a or b");function K(S,h,y=!1){if(!n.isValid(h)||y&&n.is0(h))throw new Error(`bad point coordinate ${S}`);return typeof h=="object"&&h!==null?n.create(h):h}function z(S){if(!(S instanceof B))throw new Error("Weierstrass Point expected")}function _(S){if(!g||!g.basises)throw new Error("no endo");return fm(S,g.basises,s.ORDER)}function U(S,h,y,v){if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:P,k1:N,k2neg:M,k2:H}=_(v),$=new B(n.mul(y.X,g.beta),y.Y,y.Z);S.push(P?y.negate():y,M?$.negate():$),h.push(N,H)}else S.push(y),h.push(v)}let T=new WeakSet;class B{static BASE=new B(o.Gx,o.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(h,y,v){this.X=K("x",h),this.Y=K("y",y,!0),this.Z=K("z",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(h){let{x:y,y:v}=h||{};if(!h||!n.isValid(y)||!n.isValid(v))throw new Error("invalid affine point");if(h instanceof B)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(v)?B.ZERO:new B(y,v,n.ONE)}static fromBytes(h){let y=B.fromAffine(L(Z(h,void 0,"point")));return y.assertValidity(),y}static fromHex(h){return B.fromBytes(vr(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,y=!0){return C.setWindowSize(this,h),y||this.multiply(Aa),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(T.has(h))return;let{x:y,y:v}=h.toAffine();if(!n.isValid(y)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!I(y,v))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");T.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){z(h);let{X:y,Y:v,Z:P}=this,{X:N,Y:M,Z:H}=h,$=n.eql(n.mul(y,H),n.mul(N,P)),j=n.eql(n.mul(v,H),n.mul(M,P));return $&&j}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:y,Z:v}=this,P=n.ZERO,N=n.ZERO,M=n.ZERO,H=n.mul(h,h),$=n.mul(y,y),j=n.mul(v,v),Y=n.mul(h,y);return Y=n.add(Y,Y),M=n.mul(h,v),M=n.add(M,M),P=q(M),N=n.mul(R,j),N=n.add(P,N),P=n.sub($,N),N=n.add($,N),N=n.mul(P,N),P=n.mul(Y,P),M=n.mul(R,M),j=q(j),Y=n.sub(H,j),Y=q(Y),Y=n.add(Y,M),M=n.add(H,H),H=n.add(M,H),H=n.add(H,j),H=n.mul(H,Y),N=n.add(N,H),j=n.mul(y,v),j=n.add(j,j),H=n.mul(j,Y),P=n.sub(P,H),M=n.mul(j,$),M=n.add(M,M),M=n.add(M,M),new B(P,N,M)}add(h){z(h);let{X:y,Y:v,Z:P}=this,{X:N,Y:M,Z:H}=h,$=n.ZERO,j=n.ZERO,Y=n.ZERO,ce=n.mul(y,N),ie=n.mul(v,M),ye=n.mul(P,H),Pe=n.add(y,v),ae=n.add(N,M);Pe=n.mul(Pe,ae),ae=n.add(ce,ie),Pe=n.sub(Pe,ae),ae=n.add(y,P);let he=n.add(N,H);return ae=n.mul(ae,he),he=n.add(ce,ye),ae=n.sub(ae,he),he=n.add(v,P),$=n.add(M,H),he=n.mul(he,$),$=n.add(ie,ye),he=n.sub(he,$),Y=q(ae),$=n.mul(R,ye),Y=n.add($,Y),$=n.sub(ie,Y),Y=n.add(ie,Y),j=n.mul($,Y),ie=n.add(ce,ce),ie=n.add(ie,ce),ye=q(ye),ae=n.mul(R,ae),ie=n.add(ie,ye),ye=n.sub(ce,ye),ye=q(ye),ae=n.add(ae,ye),ce=n.mul(ie,ae),j=n.add(j,ce),ce=n.mul(he,ae),$=n.mul(Pe,$),$=n.sub($,ce),ce=n.mul(Pe,ie),Y=n.mul(he,Y),Y=n.add(Y,ce),new B($,j,Y)}subtract(h){return z(h),this.add(h.negate())}is0(){return this.equals(B.ZERO)}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:y,f:v}=C.mulSecret(this,h,i,F);return F([y,v])[0]}multiplyUnsafe(h){let y=this,v=h;if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===pt||y.is0())return B.ZERO;if(v===nr)return y;if(C.hasWindowSize(this))return C.mulUnsafe(y,v,F);let P=[],N=[];return U(P,N,y,v),Ls(B,P,N)}mulAddUnsafe(h,y,v){z(y);let P=[],N=[];return U(P,N,this,h),U(P,N,y,v),Ls(B,P,N)}toAffine(h){let y=this,v=h;if(v!=null&&!n.isValid(v))throw new RangeError('"invertedZ" expected valid field element');let{X:P,Y:N,Z:M}=y;if(n.eql(M,n.ONE))return{x:P,y:N};let H=y.is0();v==null&&(v=H?n.ONE:n.inv(M));let $=n.mul(P,v),j=n.mul(N,v),Y=n.mul(M,v);if(H)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Y,n.ONE))throw new Error("invZ was invalid");return{x:$,y:j}}isTorsionFree(){return i===nr?!0:l?l(B,this):C.mulUnsafe(this,a).is0()}clearCofactor(){return i===nr?this:f?f(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===nr?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Ue(h,"isCompressed"),this.assertValidity(),A(B,this,h)}toHex(h=!0){return Xr(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let F=S=>Bs(B,S),C=new _r(B,b);return C.bits>=6&&B.BASE.precompute(6),Object.freeze(B.prototype),Object.freeze(B),B}function Tf(t){return Uint8Array.of(t?2:3)}function Cf(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function hm(t,e={}){Ct(t);let{Fn:r}=t,n=e.randomBytes===void 0?ft:e.randomBytes,s=Object.assign(Cf(t.Fp,r),{seed:Math.max(vs(r.ORDER),16)});function o(p){try{let b=r.fromBytes(p);return r.isValidNot0(b)}catch{return!1}}function i(p,b){let{publicKey:g,publicKeyUncompressed:m}=s;try{let x=p.length;return b===!0&&x!==g||b===!1&&x!==m?!1:!t.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(s.seed):p,As(Z(p,s.seed,"seed"),r.ORDER)}function c(p,b=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(b)}function u(p){let{secretKey:b,publicKey:g,publicKeyUncompressed:m}=s,x=r._lengths;if(!Lt(p))return;let E=Z(p,void 0,"key").length,w=E===g||E===m,A=E===b||!!x?.includes(E);if(!(w&&A))return w}function f(p,b,g=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(b)===!1)throw new Error("second arg must be public key");let m=r.fromBytes(p),x=t.fromBytes(b);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(m).toBytes(g)}let l={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},d=Tr(a,c);return Object.freeze(l),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:t,utils:l,lengths:s})}function If(t,e,r={}){Ct(t);let n=e;jt(n),Ie(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?ft:s.randomBytes,i=s.hmac===void 0?(S,h)=>on(n,S,h):s.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=vs(u),d=Ni(o,l),{keygen:p,getPublicKey:b,getSharedSecret:g,utils:m,lengths:x}=hm(t,s),E={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},w=u*Lf+nr<a.ORDER;function A(S){let h=u>>nr;return S>h}function L(S,h){if(!c.isValidNot0(h))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return h}function R(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function q(S,h,y){return R(),(S===y?0:2)|Number(a.isOdd(h))}function O(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function I(S,h){Ba(h);let y=x.signature,v=h==="compact"?y:h==="recovered"?y+1:void 0;return Z(S,v)}class D{r;s;recovery;constructor(h,y,v){if(this.r=L("r",h),this.s=L("s",y),v!=null){if(O(),![0,1,2,3].includes(v))throw new Error("invalid recovery id");this.recovery=v}Object.freeze(this)}static fromBytes(h,y=E.format){I(h,y);let v;if(y==="der"){if(h.length>2*c.BYTES+16)throw new $s.Err("invalid signature: DER signature too long");let{r:H,s:$}=$s.toSig(Z(h),c.BYTES+1);return new D(H,$)}y==="recovered"&&(v=h[0],y="compact",h=h.subarray(1));let P=x.signature/2,N=h.subarray(0,P),M=h.subarray(P,P*2);return new D(c.fromBytes(N),c.fromBytes(M),v)}static fromHex(h,y){return this.fromBytes(vr(h),y)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new D(this.r,this.s,h)}recoverPublicKey(h){let{r:y,s:v}=this,P=this.assertRecovery(),N=P===2||P===3?y+u:y;if(!a.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let M=a.toBytes(N),H=t.fromBytes(qe(Tf((P&1)===0),M)),$=c.inv(N),j=K(Z(h,void 0,"msgHash")),Y=c.create(-j*$),ce=c.create(v*$),ie=t.BASE.mulAddUnsafe(Y,H,ce);if(ie.is0())throw new Error("invalid recovery: point at infinify");return ie.assertValidity(),ie}hasHighS(){return A(this.s)}toBytes(h=E.format){if(Ba(h),h==="der")return vr($s.hexFromSig(this));let{r:y,s:v}=this,P=c.toBytes(y),N=c.toBytes(v);return h==="recovered"?(O(),qe(Uint8Array.of(this.assertRecovery()),P,N)):qe(P,N)}toHex(h){return Xr(this.toBytes(h))}}Object.freeze(D.prototype),Object.freeze(D);let k=s.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let y=tt(h),v=h.length*8-f;return v>0?y>>BigInt(v):y}:s.bits2int,K=s.bits2int_modN===void 0?function(h){return c.create(k(h))}:s.bits2int_modN,z=en(f);function _(S){return nt("num < 2^"+f,S,pt,z),c.toBytes(S)}function U(S,h){return Z(S,void 0,"message"),h?Z(n(S),void 0,"prehashed message"):S}function T(S,h,y){let{lowS:v,prehash:P,extraEntropy:N}=va(y,E);S=U(S,P);let M=K(S),H=c.fromBytes(h);if(!c.isValidNot0(H))throw new Error("invalid private key");let $=[_(H),_(M)];if(N!=null&&N!==!1){let ie=N===!0?o(x.secretKey):N;$.push(Z(ie,void 0,"extraEntropy"))}let j=qe(...$),Y=M;function ce(ie){let ye=k(ie);if(!c.isValidNot0(ye))return;let Pe=t.BASE.multiply(ye).toAffine(),ae=c.create(Pe.x);if(ae===pt)return;let he;if(d!==void 0){let mt=tt(As(d(l),u)),Qf=c.inv(c.mul(mt,ye)),Jf=c.mul(mt,Y),el=c.mul(mt,H);he=c.create(Qf*c.create(Jf+el*ae))}else{let mt=Tu(ye,u);he=c.create(mt*c.create(Y+ae*H))}if(he===pt)return;let or=q(Pe.x,Pe.y,ae),Nr=he;return v&&A(he)&&(Nr=c.neg(he),or^=1),new D(ae,Nr,w?void 0:or)}return{seed:j,k2sig:ce}}function B(S,h,y={}){let{seed:v,k2sig:P}=T(S,h,y);return xu(n.outputLen,c.BYTES,i)(v,P).toBytes(y.format)}function F(S,h,y,v={}){let{lowS:P,prehash:N,format:M}=va(v,E);if(y=Z(y,void 0,"publicKey"),h=U(h,N),!Lt(S)){let H=S instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}I(S,M);try{let H=D.fromBytes(S,M),$=t.fromBytes(y);if($.is0()||P&&H.hasHighS())return!1;let{r:j,s:Y}=H,ce=K(h),ie=c.inv(Y),ye=c.create(ce*ie),Pe=c.create(j*ie),ae=t.BASE.mulAddUnsafe(ye,$,Pe);if(ae.is0())return!1;let he=ae.toAffine();return!(c.create(he.x)!==j||M==="recovered"&&H.recovery!==q(he.x,he.y,j))}catch{return!1}}function C(S,h,y={}){let{prehash:v}=va(y,E);return h=U(h,v),D.fromBytes(S,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:p,getPublicKey:b,getSharedSecret:g,utils:m,lengths:x,Point:t,sign:B,verify:F,recoverPublicKey:C,Signature:D,hash:n})}var _a={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},dm={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Df=BigInt(2);function pm(t){let e=_a.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=le(f,r,e)*f%e,d=le(l,r,e)*f%e,p=le(d,Df,e)*u%e,b=le(p,s,e)*p%e,g=le(b,o,e)*b%e,m=le(g,a,e)*g%e,x=le(m,c,e)*m%e,E=le(x,a,e)*g%e,w=le(E,r,e)*f%e,A=le(w,i,e)*b%e,L=le(A,n,e)*u%e,R=le(L,Df,e);if(!La.eql(La.sqr(R),t))throw new Error("Cannot find square root");return R}var La=Lr(_a.p,{sqrt:pm}),mm=_f(_a,{Fp:La,endo:dm}),Ur=If(mm,et);function Rf(t,e,r,n){let s=Fr.digest(r instanceof Uint8Array?r:r.subarray());if(Ms(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),Ur.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new ln(String(o))});try{return n?.signal?.throwIfAborted(),Ur.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new ln(String(o))}}var Vs=class{type="secp256k1";raw;_key;constructor(e){this._key=Pf(e),this.raw=Of(this._key)}toMultihash(){return je.digest(Dt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}verify(e,r,n){return Rf(this._key,r,e,n)}};function Ta(t){return new Vs(t)}function Of(t){return Ur.Point.fromBytes(t).toBytes()}function Pf(t){try{return Ur.Point.fromBytes(t),t}catch(e){throw new Ot(String(e))}}function Uf(t,e){let{Type:r,Data:n}=st.decode(t),s=n??new Uint8Array;switch(r){case de.RSA:return wa(s,e);case de.Ed25519:return Ji(s);case de.secp256k1:return Ta(s);case de.ECDSA:return Zi(s);default:throw new Ut}}function Nf(t){let{Type:e,Data:r}=st.decode(t.digest),n=r??new Uint8Array;switch(e){case de.Ed25519:return Ji(n);case de.secp256k1:return Ta(n);case de.ECDSA:return Zi(n);default:throw new Ut}}function Dt(t){return st.encode({Type:de[t.type],Data:t.raw})}var kf=Symbol.for("nodejs.util.inspect.custom"),ym=114,gn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Zs]=!0;toString(){return this.string==null&&(this.string=me.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return xe.createV1(ym,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return we(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return we(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[kf](){return`PeerId(${this.toString()})`}},bn=class extends gn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},wn=class extends gn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},xn=class extends gn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},gm=2336,En=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=je.digest(ee(this.url))}[kf](){return`PeerId(${this.url})`}[Zs]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return xe.createV1(gm,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=W(e)),e.toString()===this.toString())}};var bm=114,Mf=2336;function Kf(t,e){let r;if(t.charAt(0)==="1"||t.charAt(0)==="Q")r=hr(me.decode(`z${t}`));else{if(t.startsWith("k51qzi5uqu5")||t.startsWith("kzwfwjn5ji4")||t.startsWith("k2k4r8")||t.startsWith("bafz"))return wm(xe.parse(t));if(e==null)throw new se('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=hr(e.decode(t))}return Hf(r)}function Ff(t){if(t.type==="Ed25519")return new wn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new xn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new bn({multihash:t.toCID().multihash,publicKey:t});throw new Ut}function Hf(t){if(Em(t))return new bn({multihash:t});if(xm(t))try{let e=Nf(t);if(e.type==="Ed25519")return new wn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new xn({multihash:t,publicKey:e})}catch{let r=W(t.digest);return new En(new URL(r))}throw new Cn("Supplied PeerID Multihash is invalid")}function wm(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==bm&&t.code!==Mf)throw new Tn("Supplied PeerID CID is invalid");if(t.code===Mf){let e=W(t.multihash.digest);return new En(new URL(e))}return Hf(t.multihash)}function xm(t){return t.code===je.code}function Em(t){return t.code===Fr.code}var Sn;(function(t){let e;t.codec=()=>(e==null&&(e=tr((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.webtransportCerthashes!=null&&o.webtransportCerthashes.length>0)for(let c of o.webtransportCerthashes)i.uint32(10),i.bytes(c);if(o.streamMuxers!=null&&o.streamMuxers.length>0)for(let c of o.streamMuxers)i.uint32(18),i.string(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={webtransportCerthashes:[],streamMuxers:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.webtransportCerthashes!=null&&c.webtransportCerthashes.length===a.limits.webtransportCerthashes)throw new rr('Decode error - repeated field "webtransportCerthashes" had too many elements');c.webtransportCerthashes.push(o.bytes());break}case 2:{if(a.limits?.streamMuxers!=null&&c.streamMuxers.length===a.limits.streamMuxers)throw new rr('Decode error - repeated field "streamMuxers" had too many elements');c.streamMuxers.push(o.string());break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={webtransportCerthashes:0,streamMuxers:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{if(c.limits?.webtransportCerthashes!=null&&u.webtransportCerthashes===c.limits.webtransportCerthashes)throw new rr('Streaming decode error - repeated field "webtransportCerthashes" had too many elements');yield{field:`${a}.webtransportCerthashes[]`,index:u.webtransportCerthashes,value:o.bytes()},u.webtransportCerthashes++;break}case 2:{if(c.limits?.streamMuxers!=null&&u.streamMuxers===c.limits.streamMuxers)throw new rr('Streaming decode error - repeated field "streamMuxers" had too many elements');yield{field:`${a}.streamMuxers[]`,index:u.streamMuxers,value:o.string()},u.streamMuxers++;break}default:{o.skipType(l&7);break}}}})),e);function r(o){return Jt(o,t.codec())}t.encode=r;function n(o,i){return Xt(o,t.codec(),i)}t.decode=n;function s(o,i){return er(o,t.codec(),i)}t.stream=s})(Sn||(Sn={}));var vn;(function(t){let e;t.codec=()=>(e==null&&(e=tr((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.identityKey!=null&&o.identityKey.byteLength>0&&(i.uint32(10),i.bytes(o.identityKey)),o.identitySig!=null&&o.identitySig.byteLength>0&&(i.uint32(18),i.bytes(o.identitySig)),o.extensions!=null&&(i.uint32(34),Sn.codec().encode(o.extensions,i)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={identityKey:be(0),identitySig:be(0)},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.identityKey=o.bytes();break}case 2:{c.identitySig=o.bytes();break}case 4:{c.extensions=Sn.codec().decode(o,o.uint32(),{limits:a.limits?.extensions});break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.identityKey`,value:o.bytes()};break}case 2:{yield{field:`${a}.identitySig`,value:o.bytes()};break}case 4:{yield*Sn.codec().stream(o,o.uint32(),`${a}.extensions`,{limits:c.limits?.extensions});break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Jt(o,t.codec())}t.encode=r;function n(o,i){return Xt(o,t.codec(),i)}t.decode=n;function s(o,i){return er(o,t.codec(),i)}t.stream=s})(vn||(vn={}));async function Ia(t,e,r){let n=await t.sign(zf(e));return vn.encode({identityKey:Dt(t.publicKey),identitySig:n,extensions:r})}async function Da(t,e,r){try{let n=vn.decode(t),s=Uf(n.identityKey),o=Ff(s);if(r!=null&&!r.equals(o))throw new Error(`Payload peer id ${o} does not match expected remote peer id ${r}`);if(!e)throw new Error("Remote static does not exist");let i=zf(e);if(!await s.verify(i,n.identitySig))throw new Error("Invalid payload signature");return{payload:n,remotePeer:o}}catch(n){throw new An(n.message)}}function zf(t){let e=ee("noise-libp2p-static-key:");return t instanceof Uint8Array?Me([e,t],e.length+t.length):(t.prepend(e),t)}var Ca=class extends Xe{stream;handshake;metrics;decoder;constructor(e,r,n){super({log:e.log,inactivityTimeout:e.inactivityTimeout,maxReadBufferLength:e.maxReadBufferLength,direction:e.direction}),this.stream=e,this.handshake=r,this.metrics=n,this.decoder=new cs({lengthDecoder:Ir,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let u of this.decoder.decode(c.data))this.onData(this.decrypt(u))}catch(u){this.abort(u)}};this.stream.addEventListener("message",s);let o=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",o);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let r=new Q;for(let n=0;n<e.byteLength;n+=65519){let s=n+65519;s>e.byteLength&&(s=e.byteLength);let o;e instanceof Uint8Array?o=this.handshake.encrypt(e.subarray(n,s)):o=this.handshake.encrypt(e.sublist(n,s)),this.metrics?.encryptedPackets.increment(),r.append(Cr(o.byteLength)),r.append(o)}return r}decrypt(e){let r=new Q;for(let n=0;n<e.byteLength;n+=65535){let s=n+65535;if(s>e.byteLength&&(s=e.byteLength),s-li<n)throw new Error("Invalid chunk");let o;e instanceof Uint8Array?o=e.subarray(n,s):o=e.sublist(n,s);let i=e.subarray(n,s-li);try{let a=this.handshake.decrypt(o,i);this.metrics?.decryptedPackets.increment(),r.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return r}close(e){return this.stream.close(e)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(e){this.stream.abort(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.stream.send(this.encrypt(e))}}};function Ra(t,e,r){return new Ca(t,e,r)}async function $f(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remotePeer:c,extensions:u}=t,f=await Ia(o,a.publicKey,u),l=new cn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Ki(l.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(l.writeMessageA(Gt),e),r.trace("Stage 0 - Initiator finished sending first message."),Fi(l.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let d=l.readMessageB(await n.read(e));r.trace("Stage 1 - Initiator received the message."),Hi(l.re,r),tf(l.rs,r),r.trace("Initiator going to check remote's signature...");let p=await Da(d,l.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(l.writeMessageC(f),e),r.trace("Stage 2 - Initiator sent message with signed payload.");let[b,g]=l.ss.split();return qi(b,g,r),{payload:p.payload,remotePeer:p.remotePeer,encrypt:m=>b.encryptWithAd(Gt,m),decrypt:(m,x)=>g.decryptWithAd(Gt,m,x)}}async function Vf(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remotePeer:c,extensions:u}=t,f=await Ia(o,a.publicKey,u),l=new cn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Ki(l.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await n.read(e)),r.trace("Stage 0 - Responder received first message."),Hi(l.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(l.writeMessageB(f),e),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Fi(l.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let d=l.readMessageC(await n.read(e));r.trace("Stage 2 - Responder received the message, finished handshake.");let p=await Da(d,l.rs,c),[b,g]=l.ss.split();return qi(b,g,r),{payload:p.payload,remotePeer:p.remotePeer,encrypt:m=>g.encryptWithAd(Gt,m),decrypt:(m,x)=>b.decryptWithAd(Gt,m,x)}}var Ws=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(e,r={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=r,{metrics:a}=e;this.components=e,this.log=e.logger.forComponent("libp2p:noise");let c=o??Qu;this.crypto=Ju(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?ef(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??be(0)}[Symbol.toStringTag]="@libp2p/noise";[On]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,r){let n=e.log?.newScope("noise")??this.log,s=fi(e,{lengthEncoder:Cr,lengthDecoder:Ir,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer,r);return{connection:Ra(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:o.remotePeer,streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let r=this.components.upgrader.getStreamMuxers();if(r!=null)for(let n of e){let s=r.get(n);if(s!=null)return s}if(e.length)throw new ir("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,r){let n=e.log?.newScope("noise")??this.log,s=fi(e,{lengthEncoder:Cr,lengthDecoder:Ir,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer,r);return{connection:Ra(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:o.remotePeer,streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await $f({connection:e,privateKey:r,remotePeer:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}async performHandshakeResponder(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Vf({connection:e,privateKey:r,remotePeer:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}};function jf(t={}){return e=>new Ws(e,t)}var sr=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function Oa(t){throw new Error("Not implemented")}var Pa=class extends is{writer;reader;constructor(e){super(e),this.writer=e.stream.writable.getWriter(),this.reader=e.stream.readable.getReader(),this.writer.closed.then(()=>{this.log("writer closed gracefully")}).catch(r=>{r.message.includes("STOP_SENDING")||r.message.includes("StopSending")?this.onRemoteCloseRead():r.message.includes("RESET_STREAM")||r.message.includes("Reset")?this.onRemoteReset():this.log("writer close promise rejected - %e",r)}),this.readData()}readData(){Promise.resolve().then(async()=>{for(;;){let e=await this.reader.read();if(e.value!=null&&this.onData(e.value),e.done){this.log("remote closed write"),this.onRemoteCloseWrite();return}if(this.readStatus==="paused")break}}).catch(e=>{this.abort(e)}).finally(()=>{this.reader.releaseLock()})}sendData(e){for(let n of e)this.writer.write(n).catch(s=>{this.abort(s)});if(this.log.trace("desired size after sending %d bytes is %d bytes",e.byteLength,this.writer.desiredSize),this.writer.desiredSize==null)return{sentBytes:e.byteLength,canSendMore:!1};let r=this.writer.desiredSize>0;return r||this.writer.ready.then(()=>{this.safeDispatchEvent("drain")},n=>{this.abort(n)}),{sentBytes:e.byteLength,canSendMore:r}}sendReset(e){this.writer.abort(e).catch(r=>{this.log.error("error aborting writer - %e",r)})}async sendCloseWrite(e){this.log("sendCloseWrite closing writer"),await Fe(this.writer.close().catch(()=>{}),e?.signal),this.log("sendCloseWrite closed writer")}async sendCloseRead(e){this.log("sendCloseRead cancelling reader"),await Fe(this.reader.cancel(),e?.signal),this.log("sendCloseRead cancelled reader")}sendPause(){}sendResume(){this.readData()}};function Ua(t,e,r,n,s){return new Pa({...s,stream:t,id:e,direction:r,log:n.newScope(`${r}:${e}`),protocol:""})}var Wf="/webtransport",Na=class extends os{webTransport;streamIDCounter;reader;constructor(e,r){super(r,{protocol:Wf,name:"muxer"}),this.webTransport=e,this.streamIDCounter=0,this.reader=this.webTransport.incomingBidirectionalStreams.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:n,value:s}=await this.reader.read();if(n||s==null)break;this.onRemoteStream(Ua(s,String(this.streamIDCounter++),"inbound",this.log,this.streamOptions))}}).catch(n=>{this.log.error("could not create a new stream - %e",n)})}async onCreateStream(e){let r=await this.webTransport.createBidirectionalStream();return e?.signal?.throwIfAborted(),Ua(r,String(this.streamIDCounter++),"outbound",this.log,e)}onData(){}sendReset(){this.webTransport.close()}};function Yf(t){return{protocol:Wf,createStreamMuxer(e){return new Na(t,e)}}}var ka=class extends ss{cleanUpWTSession;constructor(e){super(e),this.cleanUpWTSession=e.cleanUpWTSession}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}sendReset(){this.cleanUpWTSession("abort")}async sendClose(e){this.cleanUpWTSession("close"),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}},Gf=t=>new ka(t);function Zf(t,e){return e.filter(n=>!!t.find(s=>we(n,s))).length===e.length}var Sm=Object.values(Mt).map(t=>t.decoder).reduce((t,e)=>t.or(e));function vm(t){return ot.decode(Sm.decode(t))}function Ma(t){if(!Qn.matches(t))throw new _n("Invalid multiaddr, was not a WebTransport address");let e=[],r;for(let o of t.getComponents())o.name==="certhash"&&e.push(vm(o.value??"")),o.name==="p2p"&&r==null&&(r=Kf(o.value??""));let n=hc(t),s=n.host;return n.type==="ip6"&&s.includes(":")&&(s=`[${s}]`),{url:`https://${s}:${n.port}`,certhashes:e,remotePeer:r}}var Ys=class extends Xe{writer;reader;constructor(e){super(e),this.writer=e.stream.writable.getWriter(),this.reader=e.stream.readable.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:r,value:n}=await this.reader.read();if(n!=null&&this.onData(n),r)break}}).catch(r=>{this.abort(r)})}async close(e){await Fe(this.writer.close(),e?.signal)}sendData(e){return this.writer.write(e.subarray()).catch(r=>{this.abort(r)}),{sentBytes:e.byteLength,canSendMore:!0}}sendReset(e){this.writer.abort(e).catch(r=>{this.log.error("could not send reset - %e",r)})}sendPause(){}sendResume(){}};var Xf=globalThis.WebTransport;var Ka=class{log;components;config;metrics;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:webtransport"),this.components=e,this.config={...r,certificates:r.certificates??[]},e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webtransport_dialer_events_total",{label:"event",help:"Total count of WebTransport dialer events by type"})})}[Symbol.toStringTag]="@libp2p/webtransport";[Ha]=!0;[On]=["@libp2p/transport"];async dial(e,r){r.signal.throwIfAborted(),this.log("dialing %s",e),r=r??{};let{url:n,certhashes:s,remotePeer:o}=Ma(e),i,a,c=()=>{},u=!1,f=!1,l=!1;try{this.metrics?.dialerEvents.increment({pending:!0});let d=new Xf(`${n}/.well-known/libp2p-webtransport?type=noise`,{serverCertificateHashes:s.map(b=>({algorithm:"sha-256",value:Ae(b.digest)}))});c=b=>{if(!u)try{this.metrics?.dialerEvents.increment({[b]:!0}),d.close()}catch(g){this.log.error("error closing wt session - %e",g)}finally{a!=null&&(a.timeline.close=Date.now()),u=!0}},i=()=>{c(f?"noise_timeout":"ready_timeout")},r.signal.addEventListener("abort",i,{once:!0}),this.log("wait for session to be ready"),r.onProgress?.(new sr("webtransport:wait-for-session")),await Promise.race([d.closed,d.ready]),this.log("session became ready"),f=!0,this.metrics?.dialerEvents.increment({ready:!0}),d.closed.catch(b=>{this.log.error("error on remote wt session close - %e",b)}).finally(()=>{c("remote_close")}),this.metrics?.dialerEvents.increment({open:!0}),a=Gf({remoteAddr:e,cleanUpWTSession:c,direction:"outbound",log:this.components.logger.forComponent("libp2p:webtransport:connection")});let p=await this.authenticateWebTransport({wt:d,maConn:a,remotePeer:o,certhashes:s,...r});if(l=!0,o!=null&&(l=o.equals(p)),!l)throw new ir("Failed to authenticate webtransport");return await r.upgrader.upgradeOutbound(a,{...r,skipEncryption:!0,remotePeer:p,muxerFactory:Yf(d),skipProtection:!0})}catch(d){throw this.log.error("caught wt session err - %e",d),c(l?"upgrade_error":f?"noise_error":"ready_error"),d}finally{i!=null&&r.signal?.removeEventListener("abort",i)}}async authenticateWebTransport({wt:e,maConn:r,remotePeer:n,certhashes:s,onProgress:o,signal:i}){o?.(new sr("webtransport:open-authentication-stream"));let a=await e.createBidirectionalStream();i?.throwIfAborted();let c=new Ys({stream:a,log:r.log.newScope("muxer")}),u=jf()(this.components);o?.(new sr("webtransport:secure-outbound-connection"));let{remoteExtensions:f,remotePeer:l}=await u.secureOutbound(c,{signal:i,remotePeer:n,skipStreamMuxerNegotiation:!0});if(o?.(new sr("webtransport:close-authentication-stream")),await c.close({signal:i}),!Zf(f?.webtransportCerthashes??[],s.map(d=>d.bytes)))throw new se("Our certhashes are not a subset of the remote's reported certhashes");return l}createListener(e){return Oa(this.components,{...e,certificates:this.config.certificates})}listenFilter(){return[]}dialFilter(e){return globalThis.WebTransport==null?[]:e.filter(r=>{if(!Qn.exactMatch(r))return!1;let{url:n,certhashes:s}=Ma(r);return n!=null&&s.length>0})}};function Am(t={}){return e=>new Ka(e,t)}return ol(Bm);})();
3
3
  //! TODO unclear how to add backpressure here?
4
4
  /*! Bundled license information:
5
5