@libp2p/webtransport 6.0.42-6d888970e → 6.0.42-95392efdf
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 +4 -4
- package/dist/index.min.js.map +4 -4
- package/package.json +11 -11
package/dist/index.min.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
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 Xs=Object.defineProperty;var tl=Object.getOwnPropertyDescriptor;var rl=Object.getOwnPropertyNames;var nl=Object.prototype.hasOwnProperty;var Re=(t,e)=>{for(var r in e)Xs(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&&Xs(t,s,{get:()=>e[s],enumerable:!(n=tl(e,s))||n.enumerable});return t};var ol=t=>sl(Xs({},"__esModule",{value:!0}),t);var ym={};Re(ym,{webTransport:()=>mm});var _n=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},or=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"}},ir=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Ln=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Tn=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"}},Ot=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Cn=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},In=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Dn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Pt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Rn=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}},On=class extends ar{constructor(e,r){super(!0,e,r)}},Pn=class extends ar{constructor(e,r){super(!1,e,r)}};var Qs=Symbol.for("@libp2p/peer-id");var za=Symbol.for("@libp2p/transport");var qa;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(qa||(qa={}));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 Js(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 $a(t,e){return Js(t).capture===Js(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=Js(n);if(s?.signal?.aborted===!0)return;let o=f=>{s.once&&this.removeEventListener(e,r,s),il(r)?r.handleEvent(f):r(f)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(f=>f.callback!==r?!1:$a(f.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&&$a(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 Un=Symbol.for("@libp2p/service-capabilities");var so={};Re(so,{base58btc:()=>me,base58flickr:()=>yl});var Ym=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 Me(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ut(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ut(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 Ut(t){return fl(t)?t:t.slice()}function ul(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),f=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),f!==a&&(n[f]=o)}}var u=t.length,l=t.charAt(0),d=Math.log(u)/Math.log(256),p=Math.log(256)/Math.log(u);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,I=0,T=x.length;I!==T&&x[I]===0;)I++,E++;for(var O=(T-I)*p+1>>>0,M=new Uint8Array(O);I!==T;){for(var U=x[I],C=0,D=O-1;(U!==0||C<w)&&D!==-1;D--,C++)U+=256*M[D]>>>0,M[D]=U%u>>>0,U=U/u>>>0;if(U!==0)throw new Error("Non-zero carry");w=C,I++}for(var F=O-w;F!==O&&M[F]===0;)F++;for(var K=l.repeat(E);F<O;++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,I=0;x[E]===l;)w++,E++;for(var T=(x.length-E)*d+1>>>0,O=new Uint8Array(T);x[E];){var M=n[x.charCodeAt(E)];if(M===255)return;for(var U=0,C=T-1;(M!==0||U<I)&&C!==-1;C--,U++)M+=u*O[C]>>>0,O[C]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");I=U,E++}if(x[E]!==" "){for(var D=T-I;D!==T&&O[D]===0;)D++;for(var F=new Uint8Array(w+(T-D)),K=w;D!==T;)F[K++]=O[D++];return F}}}function y(x){var E=b(x);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:g,decodeUnsafe:b,decode:y}}var ll=ul,hl=ll,Za=hl;var eo=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")}},to=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)}},ro=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 ro({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var no=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 eo(e,r,n),this.decoder=new to(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function fr({name:t,prefix:e,encode:r,decode:n}){return new no(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 fr({prefix:e,name:t,encode:s,decode:i=>Me(o(i))})}function dl(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 f=0;f<s;++f){let u=e[t[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,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 pl(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 ml(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=ml(n,s);return fr({prefix:e,name:t,encode(i){return pl(i,n,r)},decode(i){return dl(i,o,r,t)}})}var me=gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yl=gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var oo={};Re(oo,{base32:()=>bt,base32hex:()=>xl,base32hexpad:()=>Sl,base32hexpadupper:()=>vl,base32hexupper:()=>El,base32pad:()=>bl,base32padupper:()=>wl,base32upper:()=>gl,base32z:()=>Al});var bt=pe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),gl=pe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),bl=pe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),wl=pe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),xl=pe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),El=pe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Sl=pe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),vl=pe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Al=pe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var io={};Re(io,{base36:()=>kr,base36upper:()=>Bl});var kr=gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Bl=gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var ot={};Re(ot,{Digest:()=>Nt,create:()=>Ve,decode:()=>hr,equals:()=>co,hasCode:()=>$l});var _l=ec,Qa=128,Ll=127,Tl=~Ll,Cl=Math.pow(2,31);function ec(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Cl;)e[r++]=t&255|Qa,t/=128;for(;t&Tl;)e[r++]=t&255|Qa,t>>>=7;return e[r]=t|0,ec.bytes=r-n+1,e}var Il=ao,Dl=128,Ja=127;function ao(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw ao.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&Ja)<<s:(i&Ja)*Math.pow(2,s),s+=7}while(i>=Dl);return ao.bytes=o-n,r}var Rl=Math.pow(2,7),Ol=Math.pow(2,14),Pl=Math.pow(2,21),Ul=Math.pow(2,28),Nl=Math.pow(2,35),kl=Math.pow(2,42),Ml=Math.pow(2,49),Kl=Math.pow(2,56),Fl=Math.pow(2,63),Hl=function(t){return t<Rl?1:t<Ol?2:t<Pl?3:t<Ul?4:t<Nl?5:t<kl?6:t<Ml?7:t<Kl?8:t<Fl?9:10},ql={encode:_l,decode:Il,encodingLength:Hl},zl=ql,Mr=zl;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 ur(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 ur(t,o,0),ur(r,o,n),o.set(e,s),new Nt(t,r,e,o)}function hr(t){let e=Me(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 Nt(r,s,i,e)}function co(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 Nt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=Ut(n),this.bytes=Ut(s)}};function $l(t,e){return t.code===e}function tc(t,e){let{bytes:r,version:n}=t;return n===0?jl(r,fo(t),e??me.encoder):Wl(r,fo(t),e??bt.encoder)}var rc=new WeakMap;function fo(t){let e=rc.get(t);if(e==null){let r=new Map;return rc.set(t,r),r}return e}var we=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=Ut(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!==Fr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Yl)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&&co(e.multihash,n.multihash)}toString(e){return tc(this,e)}toJSON(){return{"/":tc(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??nc(n,s,o.bytes))}else if(r[Gl]===!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!==Fr)throw new Error(`Version 0 CID must use dag-pb (code: ${Fr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=nc(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Fr,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=Me(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 Nt(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=Fr;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(),f=r+c,u=f-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,s]=Vl(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 fo(o).set(n,e),o}};function Vl(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 jl(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 Wl(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 Fr=112,Yl=18;function nc(t,e,r){let n=lr(t),s=n+lr(e),o=new Uint8Array(s+r.byteLength);return ur(t,o,0),ur(e,o,n),o.set(r,s),o}var Gl=Symbol.for("@ipld/js-cid/CID");var uo={};Re(uo,{identity:()=>je});var sc=0,Zl="identity",oc=Me;function Xl(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(sc,oc(t))}var je={code:sc,name:Zl,encode:oc,digest:Xl};function xe(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 Ql(t){return t.buffer instanceof ArrayBuffer}function Ae(t){return Ql(t)?t:t.slice()}async function ic(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}function be(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function Jl(t){return t?.buffer instanceof ArrayBuffer}function lo(t){if(Jl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ke(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 lo(r)}var cc=Symbol.for("@achingbrain/uint8arraylist");function ac(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 kn(t){return!!t?.[cc]}var Q=class t{bufs;length;[cc]=!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(kn(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(kn(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=ac(this.bufs,e);return r.buf[r.index]}set(e,r){let n=ac(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(kn(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 Ke(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:Ke(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 f=e>=a&&e<c,u=r>a&&r<=c;if(f&&u){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(f){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){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(!kn(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,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let d=f;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){u=Math.max(1,d-a[p]);break}}if(u===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(!xe(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 ho={};Re(ho,{base10:()=>eh});var eh=gt({prefix:"9",name:"base10",alphabet:"0123456789"});var po={};Re(po,{base16:()=>th,base16upper:()=>rh});var th=pe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),rh=pe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var mo={};Re(mo,{base2:()=>nh});var nh=pe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yo={};Re(yo,{base256emoji:()=>ch});var fc=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}"),sh=fc.reduce((t,e,r)=>(t[r]=e,t),[]),oh=fc.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function ih(t){return t.reduce((e,r)=>(e+=sh[r],e),"")}function ah(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=oh[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var ch=fr({prefix:"\u{1F680}",name:"base256emoji",encode:ih,decode:ah});var bo={};Re(bo,{base64:()=>fh,base64pad:()=>uh,base64url:()=>go,base64urlpad:()=>lh});var fh=pe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),uh=pe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),go=pe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),lh=pe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wo={};Re(wo,{base8:()=>hh});var hh=pe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xo={};Re(xo,{identity:()=>dh});var dh=fr({prefix:"\0",name:"identity",encode:t=>Ya(Me(t)),decode:t=>Me(Wa(t))});var O0=new TextEncoder,P0=new TextDecoder;var vo={};Re(vo,{sha256:()=>Hr,sha512:()=>gh});var yh=20;function So({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new Eo(t,e,r,n,s)}var Eo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??yh,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?uc(n,this.code,r?.truncate):n.then(s=>uc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function uc(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 hc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Hr=So({name:"sha2-256",code:18,encode:hc("SHA-256")}),gh=So({name:"sha2-512",code:19,encode:hc("SHA-512")});var kt={...xo,...mo,...wo,...ho,...po,...oo,...io,...so,...bo,...yo},j0={...vo,...uo};function pc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var dc=pc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ao=pc("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:dc,"utf-8":dc,hex:kt.base16,latin1:Ao,ascii:Ao,binary:Ao,...kt},Mn=bh;function ee(t,e="utf8"){let r=Mn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function W(t,e="utf8"){let r=Mn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var wh=parseInt("11111",2),Bo=parseInt("10000000",2),xh=parseInt("01111111",2),mc={0:qr,1:qr,2:Eh,3:Ah,4:Bh,5:vh,6:Sh,16:qr,22:qr,48:qr};function it(t,e={offset:0}){let r=t[e.offset]&wh;if(e.offset++,mc[r]!=null)return mc[r](t,e);throw new Error("No decoder for tag "+r)}function zr(t,e){let r=0;if((t[e.offset]&Bo)===Bo){let n=t[e.offset]&xh,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 qr(t,e){zr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=it(t,e);if(n===null)break;r.push(n)}return r}function Eh(t,e){let r=zr(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 Sh(t,e){let r=zr(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 f=t[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function vh(t,e){return e.offset++,null}function Ah(t,e){let r=zr(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 Bh(t,e){let r=zr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function _h(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 _o(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=_h(t.byteLength);return new Q(Uint8Array.from([e.byteLength|Bo]),e)}function Ue(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]),_o(e),e)}function Kn(t){let e=Uint8Array.from([0]),r=new Q(e,t);return new Q(Uint8Array.from([3]),_o(r),r)}function wt(t,e=48){let r=new Q;for(let n of t)r.append(n);return new Q(Uint8Array.from([e]),_o(r),r)}var Lh=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Th=Uint8Array.from([6,5,43,129,4,0,34]),Ch=Uint8Array.from([6,5,43,129,4,0,35]),Ih={ext:!0,kty:"EC",crv:"P-256"},Dh={ext:!0,kty:"EC",crv:"P-384"},Rh={ext:!0,kty:"EC",crv:"P-521"},Lo=32,To=48,Co=66;function Io(t){let e=it(t);return yc(e)}function yc(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===Lo*2+1)return n=W(e.subarray(r,r+Lo),"base64url"),s=W(e.subarray(r+Lo),"base64url"),new dr({...Ih,key_ops:["verify"],x:n,y:s});if(e.byteLength===To*2+1)return n=W(e.subarray(r,r+To),"base64url"),s=W(e.subarray(r+To),"base64url"),new dr({...Dh,key_ops:["verify"],x:n,y:s});if(e.byteLength===Co*2+1)return n=W(e.subarray(r,r+Co),"base64url"),s=W(e.subarray(r+Co),"base64url"),new dr({...Rh,key_ops:["verify"],x:n,y:s});throw new se(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function gc(t){return wt([Ue(Uint8Array.from([1])),wt([Oh(t.crv)],160),wt([Kn(new Q(Uint8Array.from([4]),ee(t.x??"","base64url"),ee(t.y??"","base64url")))],161)]).subarray()}function Oh(t){if(t==="P-256")return Lh;if(t==="P-384")return Th;if(t==="P-521")return Ch;throw new se(`Invalid curve ${t}`)}var dr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=gc(this.jwk)),this._raw}toMultihash(){return je.digest(xt(this))}toCID(){return we.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}async verify(e,r,n){return ic(this.jwk,r,e,n)}};var Fn=BigInt(4294967295),bc=BigInt(32);function Ph(t,e=!1){return e?{h:Number(t&Fn),l:Number(t>>bc&Fn)}:{h:Number(t>>bc&Fn)|0,l:Number(t&Fn)|0}}function wc(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}=Ph(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var Uh=t=>t/2**32|0,Nh=t=>t>>>0;function xc(t,e,r,n){let s=Uh(r),o=Nh(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}var Do=(t,e,r)=>t>>>r,Ro=(t,e,r)=>t<<32-r|e>>>r,Mt=(t,e,r)=>t>>>r|e<<32-r,Kt=(t,e,r)=>t<<32-r|e>>>r,$r=(t,e,r)=>t<<64-r|e>>>r-32,Vr=(t,e,r)=>t>>>r-32|e<<64-r;function Xe(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Ec=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Sc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,vc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ac=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,Bc=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),_c=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;function Hn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Oo=t=>t?`"${t}" `:"";function We(t,e=""){if(typeof t!="number")throw new TypeError(Oo(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Oo(e)+"expected integer >= 0, got "+t);return t}function Oe(t,e,r=""){if(Hn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&We(e,"length");let n=Hn(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=Oo(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}function Ft(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(We(t.outputLen),We(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Mh=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Lc=(t,e)=>{Mh(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 pr(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function qn(t,e){Oe(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Fe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function zn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ye(t,e){return t<<32-e|t>>>e}var Cc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kh=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function $n(t){if(Oe(t),Cc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Kh[t[r]];return e}function Tc(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Vn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Cc)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=Tc(t.charCodeAt(o)),a=Tc(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 Po(...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 Fh(t,e,r="opts"){return Lc(t,"defaults"),e!==void 0&&Lc(e,r),Object.assign(Object.create(null),t,e)}function Uo(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Fh({},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 Ic(t=32){We(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 No=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Dc(t,e,r){return t&e^~t&r}function Rc(t,e,r){return t&e^t&r^e&r}var jr=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=zn(this.buffer)}update(e){pr(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 f=zn(e);for(;s<=o-a;a+=s)this.process(f,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){pr(this),qn(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)),xc(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let a=e===r?n:zn(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let l=0;l<f;l++)a.setUint32(4*l,u[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()}},Oc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Pc=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Hh=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),ko=class extends jr{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=Ye(d,7)^Ye(d,18)^d>>>3,b=Ye(p,17)^Ye(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:f,H:u}=this;for(let l=0;l<64;l++){let d=Ye(a,6)^Ye(a,11)^Ye(a,25),p=u+d+Dc(a,c,f)+Hh[l]+Et[l]|0,b=(Ye(n,2)^Ye(n,13)^Ye(n,22))+Rc(n,s,o)|0;u=f,f=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,f=f+this.G|0,u=u+this.H|0,this.set(n,s,o,i,a,c,f,u)}roundClean(){Fe(Et)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Fe(this.buffer)}},Mo=class extends ko{constructor(){super(32,Oc)}};var Uc=wc(["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))),qh=Uc[0],zh=Uc[1],St=new Uint32Array(80),vt=new Uint32Array(80),Ko=class extends jr{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:f,El:u,Fh:l,Fl:d,Gh:p,Gl:g,Hh:b,Hl:y}=this;return[e,r,n,s,o,i,a,c,f,u,l,d,p,g,b,y]}set(e,r,n,s,o,i,a,c,f,u,l,d,p,g,b,y){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=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=g|0,this.Hh=b|0,this.Hl=y|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 I=St[w-15]|0,T=vt[w-15]|0,O=Mt(I,T,1)^Mt(I,T,8)^Do(I,T,7),M=Kt(I,T,1)^Kt(I,T,8)^Ro(I,T,7),U=St[w-2]|0,C=vt[w-2]|0,D=Mt(U,C,19)^$r(U,C,61)^Do(U,C,6),F=Kt(U,C,19)^Vr(U,C,61)^Ro(U,C,6),K=vc(M,F,vt[w-7],vt[w-16]),$=Ac(K,O,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:f,Dl:u,Eh:l,El:d,Fh:p,Fl:g,Gh:b,Gl:y,Hh:x,Hl:E}=this;for(let w=0;w<80;w++){let I=Mt(l,d,14)^Mt(l,d,18)^$r(l,d,41),T=Kt(l,d,14)^Kt(l,d,18)^Vr(l,d,41),O=l&p^~l&b,M=d&g^~d&y,U=Bc(E,T,M,zh[w],vt[w]),C=_c(U,x,I,O,qh[w],St[w]),D=U|0,F=Mt(n,s,28)^$r(n,s,34)^$r(n,s,39),K=Kt(n,s,28)^Vr(n,s,34)^Vr(n,s,39),$=n&o^n&a^o&a,B=s&i^s&c^i&c;x=b|0,E=y|0,b=p|0,y=g|0,p=l|0,g=d|0,{h:l,l:d}=Xe(f|0,u|0,C|0,D|0),f=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let P=Ec(D,K,B);n=Sc(P,C,F,$),s=P|0}({h:n,l:s}=Xe(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Xe(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Xe(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Xe(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=Xe(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:g}=Xe(this.Fh|0,this.Fl|0,p|0,g|0),{h:b,l:y}=Xe(this.Gh|0,this.Gl|0,b|0,y|0),{h:x,l:E}=Xe(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,o,i,a,c,f,u,l,d,p,g,b,y,x,E)}roundClean(){Fe(St,vt)}destroy(){this.destroyed=!0,Fe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Fo=class extends Ko{constructor(){super(64,Pc)}};var Qe=Uo(()=>new Mo,No(1));var Ho=Uo(()=>new Fo,No(3));function Wn(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),qo=We;function kc(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 Ht(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Wr=$n,He=(...t)=>Po(...t),mr=t=>Vn(t),_t=Hn,at=t=>Ic(t),jn=BigInt(0),Nc=BigInt(1),$h=t=>t?`"${t}" `:"";function Ne(t,e=""){if(typeof t!="boolean")throw new TypeError($h(e)+"expected boolean, got type="+typeof t);return t}function Yn(t){if(typeof t=="bigint"){if(!Bt(t))throw new RangeError("positive bigint expected, got "+t)}else qo(t);return t}function ct(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 Yr(t){let e=Yn(t).toString(16);return e.length&1?"0"+e:e}function Mc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?jn:BigInt("0x"+t)}function Je(t){return Mc($n(t))}function et(t){return Mc($n(Lt(Oe(t)).reverse()))}function Gn(t,e){if(We(e),e===0)throw new Error("zero output length is invalid");t=Yn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Vn(n.padStart(r,"0"))}function Gr(t,e){return Gn(t,e).reverse()}function Lt(t){return Uint8Array.from(Z(t))}function Bt(t){return typeof t=="bigint"&&jn<=t}function zo(t,e,r){return Bt(t)&&Bt(e)&&Bt(r)&&e<=t&&t<r}function tt(t,e,r,n){if(!zo(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function yr(t){if(t<jn)throw new Error("expected non-negative bigint, got "+t);return t===jn?0:t.toString(2).length}var Zr=t=>(ct(t,"n"),(Nc<<BigInt(t))-Nc);function Kc(t,e,r){if(We(t,"hashLen"),We(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,l=()=>{c.fill(1),f.fill(0),u=0},d=(...y)=>r(f,He(c,...y)),p=(y=s)=>{f=d(o,y),c=d(),y.length!==0&&(f=d(i,y),c=d())},g=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,x=[];for(;y<e;){c=d();let E=c.slice();x.push(E),y+=c.length}return He(...x)};return(y,x)=>{l(),p(y);let E;for(;(E=x(g()))===void 0;)p();return l(),E}}function Le(t,e={},r={},n="object"){At(t,n),At(e,"fields"),At(r,"optFields");function s(i,a,c){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,u=t[i];if(!Object.hasOwn(t,i)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let l=typeof u;if(l!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${l}`)}let o=(i,a)=>Object.entries(i).forEach(([c,f])=>s(c,f,a));o(e,!1),o(r,!0)}var Ee=BigInt(0),te=BigInt(1),Tt=BigInt(2),qc=BigInt(3),$o=BigInt(4),zc=BigInt(5),Vh=BigInt(7),$c=BigInt(8),jh=BigInt(9),Wh=BigInt(15),Vc=BigInt(16),Yh=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 jc(t,e,r){if(r<=te)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 te;if(e===te)return t;let n=t%r;if(n<Ee&&(n+=r),e<Yh){let a=te;for(;e>Ee;)e&te&&(a=a*n%r),n=n*n%r,e>>=te;return a}let s=[];for(;e>Ee;)s.push(Number(e&Wh)),e>>=$o;let o=new Array(16);o[0]=te,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 fe(t,e,r){if(r<=te)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 Fc(t,e){if(t===Ee)throw new Error("invert: expected non-zero number");if(e<=te)throw new Error("invert: expected modulus > 1, got "+e);let r=ne(t,e),n=e,s=Ee,o=te;for(;r!==Ee;){let a=n/r,c=n-r*a,f=s-o*a;n=r,r=c,s=o,o=f}if(n!==te)throw new Error("invert: does not exist");return ne(s,e)}function Wc(t,e){if(e<=te)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=jc(r,e-Tt,e);if(ne(r*n,e)!==te)throw new Error("invertCt: does not exist");return n}function Vo(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function jo(t,e){if((t&te)===Ee)throw new Error(e+": expected odd modulus, got "+t)}function Yc(t,e){let r=t,n=(r.ORDER+te)/$o,s=r.pow(e,n);return Vo(r,s,e),s}function Gh(t,e){let r=t,n=(r.ORDER-zc)/$c,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 Vo(r,c,e),c}function Zh(t){let e=br(t),r=Gc(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Vh)/Vc;return((a,c)=>{let f=a,u=f.pow(c,i),l=f.mul(u,n),d=f.mul(u,s),p=f.mul(u,o),g=f.eql(f.sqr(l),c),b=f.eql(f.sqr(d),c);u=f.cmov(u,l,g),l=f.cmov(p,d,b);let y=f.eql(f.sqr(l),c),x=f.cmov(u,l,y);return Vo(f,x,c),x})}function Gc(t){if(t<qc)throw new Error("sqrt is not defined for small field");jo(t,"tonelliShanks");let e=t-te,r=0;for(;e%Tt===Ee;)e/=Tt,r++;let n=Tt,s=br(t);for(;Xr(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Yc;let o=s.pow(n,e),i=(e+te)/Tt;return function(c,f){let u=c;if(u.is0(f))return f;if(Xr(u,f)!==1)throw new Error("Cannot find square root");let l=r,d=u.mul(u.ONE,o),p=u.pow(f,e),g=u.pow(f,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))throw new Error("Cannot find square root: probably non-prime P");let b=1,y=u.sqr(p);for(;!u.eql(y,u.ONE);)if(b++,y=u.sqr(y),b===l)throw new Error("Cannot find square root");let x=te<<BigInt(l-b-1),E=u.pow(d,x);l=b,d=u.sqr(E),p=u.mul(p,d),g=u.mul(g,E)}return g}}function Xh(t){return jo(t,"Fp.sqrt"),t%$o===qc?Yc:t%$c===zc?Gh:t%Vc===jh?Zh(t):Gc(t)}var Zc=(t,e)=>(ne(t,e)&te)===te,Qh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function gr(t){if(At(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);ct(t.BYTES,"BYTES"),ct(t.BITS,"BITS");for(let e of Qh)Ht(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=te)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Xn(t,e,r=!1){gr(t),Wn(e,"nums"),Ne(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,f)=>n.is0(c)?a:(s[f]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,f)=>n.is0(c)?a:(s[f]=n.mul(a,s[f]),n.mul(a,c)),i),s}function Xr(t,e){gr(t);let r=t;jo(r.ORDER,"FpLegendre");let n=(r.ORDER-te)/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 Jh(t,e){if(e!==void 0&&qo(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=yr(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 Hc=new WeakMap,Zn=class{ORDER;BITS;BYTES;isLE;ZERO=Ee;ONE=te;_lengths;_mod;constructor(e,r={}){if(e<=te)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}=Jh(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&te)===te}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 jc(e,r,this.ORDER)}div(e,r){return ne(e*Fc(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 Fc(e,this.ORDER)}sqrt(e){let r=Hc.get(this);return r||Hc.set(this,r=Xh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Gr(e,this.BYTES):Gn(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 f=new Uint8Array(s);f.set(e,o?0:f.length-e.length),e=f}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?et(e):Je(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 Xn(this,e,!0)}cmov(e,r,n){return Ne(n,"condition"),n?r:e}};function br(t,e={}){return Object.freeze(Zn.prototype),new Zn(t,e)}function Xc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=te)throw new Error("field order must be greater than 1");let e=yr(t-te);return Math.ceil(e/8)}function Qn(t){let e=Xc(t);return e+Math.ceil(e/2)}function Jn(t,e,r=!1){Z(t);let n=t.length,s=Xc(e),o=Math.max(Qn(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?et(t):Je(t),a=ne(i,e-te)+te;return r?Gr(a,s):Gn(a,s)}var Go=BigInt(0),Qr=BigInt(1),ed=BigInt(4),Wo=16,Qc=128,td=5,Jc=2**31;function Ct(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ht(e.fromAffine,"Point.fromAffine"),Ht(e.fromBytes,"Point.fromBytes"),Ht(e.fromHex,"Point.fromHex"),At(e.BASE,"Point.BASE"),At(e.ZERO,"Point.ZERO"),gr(e.Fp),gr(e.Fn)}function es(t,e){Ct(t),tf(e,t);let r=Xn(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function rd(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 nd(t,e){let r=t*(4*e+128);if(r>Jc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Jc/2**20+" MiB")}function Zo(t,e){if(t!==void 0){Ht(t,"randomBytes");try{let r=t(e);if(!_t(r)||r.length!==e)return}catch{return}return t}}function tf(t,e){Wn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function sd(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 rf=new WeakMap;function Yo(t){return rf.get(t)||1}function od(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 id(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>Go;){let i=0;t&Qr&&(i=Number(t&s),i>=n&&(i-=r),t-=BigInt(i)),o.push(i),t>>=Qr}return o}function ad(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 f=Number(t&o);t>>=i,f>s&&(f-=n,t+=Qr),a.push(f)}if(t!==Go)throw new Error("invalid wnaf");return a}function cd(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 wr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Ct(e),this.randomBytes=Zo(r,Wo),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 f=a;for(let u=0;u<o;u++)i.push(f),f=f.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=ad(r,n,s),c=this.ZERO,f=this.BASE;for(let u=0;u<s;u++){let l=a[u],d=u*i,p=Math.abs(l)-1,g=o[d];for(let y=1;y<i;y++)g=y===p?o[d+y]:g;let b=g.negate();l===0?f=f.add(o[d]):c=c.add(l<0?b:g)}return{p:c,f}}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),!zo(r,Qr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Yo(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+Qc,o=this.randomBytes(Wo);if(!_t(o)||o.length!==Wo)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let i=r+Je(o)*this.Point.Fn.ORDER;return this.runCT(e,i,s,n)}fixedWindowCT(e,r,n){let s=td,o=1<<s,i=Zr(s),a=new Array(o);a[0]=this.ZERO;for(let u=1;u<o;u++)a[u]=a[u-1].add(e);let c=Math.ceil(n/s),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let p=0;p<s;p++)f=f.double();let l=Number(r>>BigInt(u*s)&i),d=a[0];for(let p=1;p<o;p++)d=p===l?a[p]:d;f=f.add(d)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Qr?!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=Yo(e);if(s===1||r>=this.Point.Fn.ORDER)return ts(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),rd(r,this.bits);let n=Math.ceil((this.bits+Qc)/r)+1;nd(n*2**(r-1),this.Point.Fp.BYTES),rf.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Yo(e)!==1}};function ts(t,e,r,n=!1){if(Ct(t),tf(e,t),Ne(n,"allowOversized"),sd(r,t.Fn,n?t.Fn.ORDER**ed:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(i=>od(i,4)),o=r.map(i=>id(i,4));return cd(t.ZERO,s,o)}function ef(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return gr(e),e}else return br(t,{isLE:r})}function rs(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`);Le(r);for(let c of["p","n","h"]){let f=e[c];if(!(Bt(f)&&f!==Go))throw new Error(`CURVE.${c} must be positive bigint`)}let s=ef(e.p,r.Fp,n),o=ef(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 xr(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var ns=BigInt(0),ss=BigInt(1),os=BigInt(2),fd=BigInt(4),nf=BigInt(8);function ud(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 sf(t,e={}){Le(e,{},{},"extraOpts");let r=e,n=rs("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;if(Xr(s,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Xr(s,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Le(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?at:r.randomBytes,f=os<<BigInt(s.BYTES*8)-ss;function u(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:ns}}}:r.uvRatio;if(!ud(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,I=!1){let T=I?ss:ns;return tt("coordinate "+E,w,T,f),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,I,T,O){this.X=p("x",w),this.Y=p("y",I),this.Z=p("z",T,!0),this.T=p("t",O),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:I,y:T}=w||{};return p("x",I),p("y",T),new b(I,T,s.ONE,s.mul(I,T))}static fromBytes(w,I=!1){let T=s.BYTES,{a:O,d:M}=i;w=Lt(Z(w,T,"point")),Ne(I,"zip215");let U=Lt(w),C=w[T-1];U[T-1]=C&-129;let D=et(U),F=I?f:s.ORDER;tt("point.y",D,ns,F);let K=s.sqr(D),$=s.sub(K,s.ONE),B=s.sub(s.mulN(M,K),O),{isValid:P,value:_}=l($,B);if(!P)throw new Error("bad point: invalid y coordinate");let A=u(_),H=(C&128)!==0;if(!I&&s.is0(_)&&H)throw new Error("bad point: x=0 and x_0=1");return H!==A&&(_=s.neg(_)),b.fromAffine({x:_,y:D})}static fromHex(w,I=!1){return b.fromBytes(mr(w),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=6,I=!0){return x.setWindowSize(this,w),I||this.multiply(os),this}assertValidity(){let w=this,{a:I,d:T}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:O,Y:M,Z:U,T:C}=w,D=s.sqr(O),F=s.sqr(M),K=s.sqr(U),$=s.sqr(K),B=s.mul(D,I),P=s.mul(s.add(B,F),K),_=s.add($,s.mul(T,s.mul(D,F)));if(!s.eql(P,_))throw new Error("bad point: equation left != right (1)");let A=s.mul(O,M),H=s.mul(U,C);if(!s.eql(A,H))throw new Error("bad point: equation left != right (2)")}equals(w){g(w);let{X:I,Y:T,Z:O}=this,{X:M,Y:U,Z:C}=w,D=s.mul(I,C),F=s.mul(M,O),K=s.mul(T,C),$=s.mul(U,O);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:I,Z:T}=this,O=s.sqr(w),M=s.sqr(I),U=s.mul(s.sqr(T),os),C=d(O),D=s.addN(w,I),F=s.sub(s.subN(s.sqr(D),O),M),K=s.addN(C,M),$=s.subN(K,U),B=s.subN(C,M),P=s.mul(F,$),_=s.mul(K,B),A=s.mul(F,B),H=s.mul($,K);return new b(P,_,H,A)}add(w){g(w);let{d:I}=i,{X:T,Y:O,Z:M,T:U}=this,{X:C,Y:D,Z:F,T:K}=w,$=s.mul(T,C),B=s.mul(O,D),P=s.mul(s.mulN(U,I),K),_=s.mul(M,F),A=s.sub(s.subN(s.mulN(s.addN(T,O),s.addN(C,D)),$),B),H=s.subN(_,P),L=s.addN(_,P),S=s.sub(B,d($)),h=s.mul(A,H),m=s.mul(L,S),v=s.mul(A,S),R=s.mul(H,L);return new b(h,m,R,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:I,f:T}=x.mulSecret(this,w,a,y);return y([I,T])[0]}multiplyUnsafe(w){if(!o.isValid(w))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return w===ns?b.ZERO:this.is0()||w===ss?this:x.mulUnsafe(this,w,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(w){let I=this,T=w;if(T!=null&&typeof T!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof T);let{X:O,Y:M,Z:U}=I,C=I.is0();T==null&&(T=C?s.create(nf):s.inv(U));let D=s.mul(O,T),F=s.mul(M,T),K=s.mul(U,T);if(C)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===ss?this:a===os?this.double():a===fd?this.double().double():a===nf?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:w,y:I}=this.toAffine(),T=s.toBytes(I);return T[T.length-1]|=u(w)?128:0,T}toHex(){return Wr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=E=>es(b,E),x=new wr(b,c);return x.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function of(t,e,r={}){if(Ct(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;Le(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,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(ct(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let l=s.randomBytes===void 0?at:s.randomBytes,d=s.toMontgomery,p=s.toMontgomerySecret,g=s.adjustScalarBytes===void 0?B=>B:s.adjustScalarBytes,b=s.domain===void 0?(B,P,_)=>{if(Ne(_,"phflag"),P.length||_)throw new Error("Contexts/pre-hash are not supported");return B}:s.domain;function y(B){return c.create(et(B))}function x(B){let P=C.secretKey;Z(B,C.secretKey,"secretKey");let _=Z(n(B),2*P,"hashedSecretKey"),A=g(_.slice(0,P)),H=_.slice(P,2*P),L=y(A);return{head:A,prefix:H,scalar:L}}function E(B){let{head:P,prefix:_,scalar:A}=x(B),H=i.multiply(A),L=H.toBytes();return{head:P,prefix:_,scalar:A,point:H,pointBytes:L}}function w(B){return E(B).pointBytes}function I(B=Uint8Array.of(),...P){let _=He(...P);return y(n(b(_,Z(B,void 0,"context"),!!o)))}function T(B,P,_={}){Le(_,{},{},"options"),B=Lt(Z(B,void 0,"message")),o&&(B=o(B));let{prefix:A,scalar:H,pointBytes:L}=E(P),S=I(_.context,A,B),h=i.multiply(S).toBytes(),m=I(_.context,h,L,B),v=c.create(S+m*H);if(!c.isValid(v))throw new Error("sign failed: invalid s");let R=He(h,c.toBytes(v));return Z(R,C.signature,"result")}let O={zip215:s.zip215};function M(B,P,_,A=O){Le(A);let{context:H}=A,L=A.zip215===void 0?!!O.zip215:A.zip215,S=C.signature;B=Z(B,S,"signature"),P=Z(P,void 0,"message"),_=Z(_,C.publicKey,"publicKey"),L!==void 0&&Ne(L,"zip215"),o&&(P=o(P));let h=S/2,m=B.subarray(0,h),v=et(B.subarray(h,S)),R,N,k;try{R=t.fromBytes(_,L),N=t.fromBytes(m,L),k=i.multiplyUnsafe(v)}catch{return!1}if(!L&&R.isSmallOrder())return!1;let q=I(H,m,_,P);return N.add(R.multiplyUnsafe(q)).subtract(k).clearCofactor().is0()}let U=a.BYTES,C={secretKey:U,publicKey:U,signature:2*U,seed:U};function D(B){return B=B===void 0?l(C.seed):B,Z(B,C.seed,"seed")}function F(B){return _t(B)&&B.length===C.secretKey}function K(B,P){try{return!!t.fromBytes(B,P===void 0?O.zip215:P)}catch{return!1}}let $={getExtendedPublicKey:E,randomSecretKey:D,isValidSecretKey:F,isValidPublicKey:K,toMontgomery(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(t.fromBytes(B))},toMontgomerySecret(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(B)}};return Object.freeze(C),Object.freeze($),Object.freeze({keygen:xr(D,w),getPublicKey:w,sign:T,verify:M,utils:$,Point:t,lengths:C})}var qt=BigInt(0),qe=BigInt(1),is=BigInt(2);function af(t,e){return t+e-(e>>qe<<qe)}function ld(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 hd(t){return Le(t,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function",scalarMultBase:"function"}),Object.freeze({...t})}function cf(t){let e=hd(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 f=i===void 0?at:i,u=c?255:448,l=ld(r),d=c?32:56,p=BigInt(c?9:5),g=BigInt(c?121665:39081),b=c?is**BigInt(254):is**BigInt(447),y=c?BigInt(8)*(is**BigInt(251)-qe):BigInt(4)*(is**BigInt(445)-qe),x=b+y+qe,E=_=>ne(_,r),w=I(p);function I(_){return Gr(E(_),d)}function T(_){let A=Lt(Z(_,d,"uCoordinate"));return c&&(A[31]&=127),E(et(A))}function O(_){return et(s(Lt(Z(_,d,"scalar"))))}let M=new Set(c?[qt,qe,r-qe,BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")]:[qt,qe,r-qe]);function U(_,A){let H=T(A);if(M.has(H))throw new Error("invalid private or public key received");let L=K(H,O(_));if(L===qt)throw new Error("invalid private or public key received");return I(L)}function C(_){if(a===void 0)return U(_,w);let A=O(_);tt("scalar",A,b,x);let H=E(a(A));if(H===qt)throw new Error("invalid private or public key received");return I(H)}let D=C,F=U;function K(_,A){tt("u",_,qt,r),tt("scalar",A,b,x);let H=A,L=_,S=qe,h=qt,m=_,v=qe,R=H^H>>qe;for(let q=BigInt(u-1);q>=qt;q--){let z=af(r,R>>q);({x_2:S,x_3:m}=l(z,S,m)),{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=m+v,ae=m-v,he=E(ae*j),sr=E(Pe*ce),Nr=he+sr,mt=he-sr;m=E(Nr*Nr),v=E(L*E(mt*mt)),S=E(Y*ie),h=E(ye*(Y+E(g*ye)))}let N=af(r,H);({x_2:S,x_3:m}=l(N,S,m)),{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},B=_=>(_=_===void 0?f(d):_,Z(_,$.seed,"seed"),_),P={randomSecretKey:B};return Object.freeze($),Object.freeze(P),Object.freeze({keygen:xr(B,D),getSharedSecret:F,getPublicKey:D,scalarMult:U,scalarMultBase:C,utils:P,GuBytes:w.slice(),lengths:$})}var ff=BigInt(0),Xo=BigInt(1),uf=BigInt(2),dd=BigInt(3),pd=BigInt(5),md=BigInt(8),as=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yd={p:as,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:md,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function df(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=as,a=t*t%o*t%o,c=fe(a,uf,o)*a%o,f=fe(c,Xo,o)*t%o,u=fe(f,pd,o)*f%o,l=fe(u,e,o)*u%o,d=fe(l,r,o)*l%o,p=fe(d,n,o)*d%o,g=fe(p,s,o)*p%o,b=fe(g,s,o)*p%o,y=fe(b,e,o)*u%o;return{pow_p_5_8:fe(y,uf,o)*t%o,b2:a}}function Qo(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var lf=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function gd(t,e){let r=as,n=ne(e*e*e,r),s=ne(n*n*e,r),o=df(t*s).pow_p_5_8,i=ne(t*n*o,r),a=ne(e*i*i,r),c=i,f=ne(i*lf,r),u=a===t,l=a===ne(-t,r),d=a===ne(-t*lf,r);return u&&(i=c),(l||d)&&(i=f),Zc(i,r)&&(i=ne(-i,r)),{isValid:u||l,value:i}}var Jr=sf(yd,{uvRatio:gd}),hf=Jr.Fp;function bd(t){let{y:e}=t;return hf.toBytes(hf.div(Xo+e,Xo-e))}function wd(t){let e=Jr.Fp.BYTES;return Oe(t,e),Qo(Ho(t.subarray(0,e))).subarray(0,e)}function xd(t){return of(Jr,Ho,Object.assign({adjustScalarBytes:Qo,toMontgomery:bd,toMontgomerySecret:wd,zip215:!0},t))}var pf=xd({});var en=(()=>{let t=as,e=r=>{let{pow_p_5_8:n,b2:s}=df(r);return ne(fe(n,dd,t)*s,t)};return cf({P:t,type:"x25519",powPminus2:e,adjustScalarBytes:Qo,scalarMultBase:r=>{let n=ne(r,Jr.Fn.ORDER);if(n===ff)return ff;let s=Jr.BASE.multiply(n);return ne((s.Z+s.Y)*e(ne(s.Z-s.Y,t)),t)}})})();var tn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},cs=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var ze={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new cs("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 fs=32;var Jo,Ed=(async()=>{try{return await ze.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sd(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await ze.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await ze.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 vd(t,e,r){return pf.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function mf(t,e,r){return Jo==null&&(Jo=await Ed),Jo?Sd(t,e,r):vd(t,e,r)}function us(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var ls=class{type="Ed25519";raw;constructor(e){this.raw=ei(e,fs)}toMultihash(){return je.digest(xt(this))}toCID(){return we.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=mf(this.raw,r,e);return us(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function ti(t){return t=ei(t,fs),new ls(t)}function ei(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 Bd=Math.pow(2,7),_d=Math.pow(2,14),Ld=Math.pow(2,21),ri=Math.pow(2,28),ni=Math.pow(2,35),si=Math.pow(2,42),oi=Math.pow(2,49),re=128,Te=127;function Ce(t){if(t<Bd)return 1;if(t<_d)return 2;if(t<Ld)return 3;if(t<ri)return 4;if(t<ni)return 5;if(t<si)return 6;if(t<oi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Er(t,e,r=0){switch(Ce(t)){case 8:e[r++]=t&255|re,t/=128;case 7:e[r++]=t&255|re,t/=128;case 6:e[r++]=t&255|re,t/=128;case 5:e[r++]=t&255|re,t/=128;case 4:e[r++]=t&255|re,t>>>=7;case 3:e[r++]=t&255|re,t>>>=7;case 2:e[r++]=t&255|re,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Td(t,e,r=0){switch(Ce(t)){case 8:e.set(r++,t&255|re),t/=128;case 7:e.set(r++,t&255|re),t/=128;case 6:e.set(r++,t&255|re),t/=128;case 5:e.set(r++,t&255|re),t/=128;case 4:e.set(r++,t&255|re),t>>>=7;case 3:e.set(r++,t&255|re),t>>>=7;case 2:e.set(r++,t&255|re),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function ii(t,e){let r=t[e],n=0;if(n+=r&Te,r<re||(r=t[e+1],n+=(r&Te)<<7,r<re)||(r=t[e+2],n+=(r&Te)<<14,r<re)||(r=t[e+3],n+=(r&Te)<<21,r<re)||(r=t[e+4],n+=(r&Te)*ri,r<re)||(r=t[e+5],n+=(r&Te)*ni,r<re)||(r=t[e+6],n+=(r&Te)*si,r<re)||(r=t[e+7],n+=(r&Te)*oi,r<re))return n;throw new RangeError("Could not decode varint")}function Cd(t,e){let r=t.get(e),n=0;if(n+=r&Te,r<re||(r=t.get(e+1),n+=(r&Te)<<7,r<re)||(r=t.get(e+2),n+=(r&Te)<<14,r<re)||(r=t.get(e+3),n+=(r&Te)<<21,r<re)||(r=t.get(e+4),n+=(r&Te)*ri,r<re)||(r=t.get(e+5),n+=(r&Te)*ni,r<re)||(r=t.get(e+6),n+=(r&Te)*si,r<re)||(r=t.get(e+7),n+=(r&Te)*oi,r<re))return n;throw new RangeError("Could not decode varint")}function gf(t,e,r=0){return e==null&&(e=Se(Ce(t))),e instanceof Uint8Array?Er(t,e,r):Td(t,e,r)}function zt(t,e=0){return t instanceof Uint8Array?ii(t,e):Cd(t,e)}var ci=new Float32Array([-0]),It=new Uint8Array(ci.buffer);function bf(t,e,r){ci[0]=t,e[r]=It[0],e[r+1]=It[1],e[r+2]=It[2],e[r+3]=It[3]}function wf(t,e){return It[0]=t[e],It[1]=t[e+1],It[2]=t[e+2],It[3]=t[e+3],ci[0]}var fi=new Float64Array([-0]),Ie=new Uint8Array(fi.buffer);function xf(t,e,r){fi[0]=t,e[r]=Ie[0],e[r+1]=Ie[1],e[r+2]=Ie[2],e[r+3]=Ie[3],e[r+4]=Ie[4],e[r+5]=Ie[5],e[r+6]=Ie[6],e[r+7]=Ie[7]}function Ef(t,e){return Ie[0]=t[e],Ie[1]=t[e+1],Ie[2]=t[e+2],Ie[3]=t[e+3],Ie[4]=t[e+4],Ie[5]=t[e+5],Ie[6]=t[e+6],Ie[7]=t[e+7],fi[0]}var Id=BigInt(Number.MAX_SAFE_INTEGER),Dd=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 $t;if(e<Id&&e>Dd)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>Sf&&(s=0n,++n>Sf&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return $t;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):$t}},$t=new ke(0,0);$t.toBigInt=function(){return 0n};$t.zzEncode=$t.zzDecode=function(){return this};$t.length=function(){return 1};var Sf=4294967296n;function vf(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 Af(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 ui(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 Ge(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function hs(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var li=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,Ge(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 Ge(this,4);return hs(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ge(this,4);return hs(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ge(this,4);let e=wf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ge(this,4);let e=Ef(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 Ge(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Af(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ge(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ge(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 Ge(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 Ge(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 Ge(this,8);let e=hs(this.buf,this.pos+=4),r=hs(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=ii(this.buf,this.pos);return this.pos+=Ce(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 rn(t){return new li(t instanceof Uint8Array?t:t.subarray())}function Vt(t,e,r){let n=rn(t);return e.decode(n,void 0,r)}function hi(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 jt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function di(){}var mi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Rd=hi();function Od(t){return globalThis.Buffer!=null?Se(t):Rd(t)}var sn=class{len;head;tail;states;constructor(){this.len=0,this.head=new jt(di,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new jt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new yi((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(ds,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(ds,r.length(),r)}uint64Number(e){return this._push(Er,Ce(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(ds,r.length(),r)}sint64Number(e){let r=ke.fromNumber(e).zzEncode();return this._push(ds,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(pi,1,e?1:0)}fixed32(e){return this._push(nn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ke.fromBigInt(e);return this._push(nn,4,r.lo)._push(nn,4,r.hi)}fixed64Number(e){let r=ke.fromNumber(e);return this._push(nn,4,r.lo)._push(nn,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(bf,4,e)}double(e){return this._push(xf,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(pi,1,0):this.uint32(r)._push(Ud,r,e)}string(e){let r=vf(e);return r!==0?this.uint32(r)._push(ui,r,e):this._push(pi,1,0)}fork(){return this.states=new mi(this),this.head=this.tail=new jt(di,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 jt(di,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=Od(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function pi(t,e,r){e[r]=t&255}function Pd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var yi=class extends jt{next;constructor(e,r){super(Pd,e,r),this.next=void 0}};function ds(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 nn(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 Ud(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(sn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Nd,e,t),this},sn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(kd,e,t),this});function Nd(t,e,r){e.set(t,r)}function kd(t,e,r){t.length<40?ui(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ee(t),r)}function gi(){return new sn}function Wt(t,e){let r=gi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Yt(t,e,r){let n=rn(t);yield*e.stream(n,void 0,".",r)}var ps={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function ms(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function bi(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 ms("enum",ps.VARINT,r,n,s)}function Gt(t,e,r){return ms("message",ps.LENGTH_DELIMITED,t,e,r)}var Zt=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 wi;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(wi||(wi={}));(function(t){t.codec=()=>bi(wi)})(de||(de={}));var rt;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((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={},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>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(u&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(rt||(rt={}));var xi;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((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={},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>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(u&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(xi||(xi={}));var an={};Re(an,{MAX_RSA_KEY_SIZE:()=>Ei,generateRSAKeyPair:()=>If,jwkToJWKKeyPair:()=>Df,jwkToPkcs1:()=>Hd,jwkToPkix:()=>Bi,jwkToRSAPrivateKey:()=>Ci,pkcs1MessageToJwk:()=>vi,pkcs1MessageToRSAPrivateKey:()=>_i,pkcs1ToJwk:()=>Fd,pkcs1ToRSAPrivateKey:()=>Cf,pkixMessageToJwk:()=>Ai,pkixMessageToRSAPublicKey:()=>Ti,pkixToJwk:()=>qd,pkixToRSAPublicKey:()=>Li});var Sr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=an.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return we.createV1(114,this._multihash)}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){return Tf(this.jwk,r,e,n)}},on=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=an.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}sign(e,r){return Lf(this.jwk,e,r)}};var Ei=8192,Si=18,Md=1062,Kd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Fd(t){let e=it(t);return vi(e)}function vi(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 Hd(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 wt([Ue(Uint8Array.from([0])),Ue(ee(t.n,"base64url")),Ue(ee(t.e,"base64url")),Ue(ee(t.d,"base64url")),Ue(ee(t.p,"base64url")),Ue(ee(t.q,"base64url")),Ue(ee(t.dp,"base64url")),Ue(ee(t.dq,"base64url")),Ue(ee(t.qi,"base64url"))]).subarray()}function qd(t){let e=it(t,{offset:0});return Ai(e)}function Ai(t){let e=it(t[1],{offset:0});return{kty:"RSA",n:W(e[0],"base64url"),e:W(e[1],"base64url")}}function Bi(t){if(t.n==null||t.e==null)throw new se("JWK was missing components");return wt([Kd,Kn(wt([Ue(ee(t.n,"base64url")),Ue(ee(t.e,"base64url"))]))]).subarray()}function Cf(t){let e=it(t);return _i(e)}function _i(t){let e=vi(t);return Ci(e)}function Li(t,e){if(t.byteLength>=Md)throw new ir("Key size is too large");let r=it(t,{offset:0});return Ti(r,t,e)}function Ti(t,e,r){let n=Ai(t);if(r==null){let s=Qe(rt.encode({Type:de.RSA,Data:e}));r=Ve(Si,s)}return new Sr(n,r)}function Ci(t){if(Of(t)>Ei)throw new se("Key size is too large");let e=Df(t),r=Qe(rt.encode({Type:de.RSA,Data:Bi(e.publicKey)})),n=Ve(Si,r);return new on(e.privateKey,new Sr(e.publicKey,n))}async function If(t){if(t>Ei)throw new se("Key size is too large");let e=await Rf(t),r=Qe(rt.encode({Type:de.RSA,Data:Bi(e.publicKey)})),n=Ve(Si,r);return new on(e.privateKey,new Sr(e.publicKey,n))}function Df(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 Rf(t,e){let r=await ze.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 zd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Lf(t,e,r){let n=await ze.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await ze.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 Tf(t,e,r,n){let s=await ze.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await ze.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 zd(t,e){if(t.privateKey==null||t.publicKey==null)throw new se("Private and public key are required");let r=await Promise.all([ze.get().subtle.exportKey("jwk",t.privateKey),ze.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Of(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 ys=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(Ft(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),Fe(s)}update(e){return pr(this),this.iHash.update(e),this}digestInto(e){pr(this),qn(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()}},cn=(()=>{let t=((e,r,n)=>new ys(e,r).update(n).digest());return t.create=(e,r)=>new ys(e,r),t})();var $d=BigInt(0),Ii=class extends Error{constructor(e=""){super(e)}},ft={Err:Ii,_tlv:{encode:(t,e)=>{let{Err:r}=ft;if(ct(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(kc(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=Yr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Yr(s.length/2|128):"";return Yr(t)+o+s+e},decode(t,e){let{Err:r}=ft;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 f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;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}=ft;if(Yn(t),t<$d)throw new e("integer: negative integers are not allowed");let r=Yr(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}=ft;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 Je(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=ft;if(e!==void 0&&(ct(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:f}=s.decode(2,i),{v:u,l}=s.decode(2,f);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||u.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=ft;Le(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)}},gs=(Object.freeze(ft._tlv),Object.freeze(ft._int),Object.freeze(ft));var Pf=(t,e)=>(t+(t>=0?e:-e)/Uf)/e;function Vd(t,e,r){tt("scalar",t,ut,r);let[[n,s],[o,i]]=e,a=Pf(i*t,r),c=Pf(-s*t,r),f=t-a*n-c*o,u=-a*s-c*i,l=f<ut,d=u<ut;l&&(f=-f),d&&(u=-u);let p=Zr(Math.ceil(yr(r)/2))+Xt;if(f<ut||f>=p||u<ut||u>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:f,k2neg:d,k2:u}}function Oi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Di(t,e){Le(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ne(r.lowS,"lowS"),Ne(r.prehash,"prehash"),r.format!==void 0&&Oi(r.format),r}var ut=BigInt(0),Xt=BigInt(1),Uf=BigInt(2),Ri=BigInt(3),jd=BigInt(4);function Nf(t,e={}){let r=rs("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;Le(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f,clearCofactor:u,isTorsionFree:l,fromBytes:d,toBytes:p}=e,g=e.randomBytes===void 0?at: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,y=Mf(n,s);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function E(S,h,m){if(h.is0()){if(!f)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:v,y:R}=h.toAffine(),N=n.toBytes(v);if(Ne(m,"isCompressed"),m){x();let k=!n.isOdd(R);return He(kf(k),N)}else return He(Uint8Array.of(4),N,n.toBytes(R))}function w(S){Z(S,void 0,"Point");let{publicKey:h,publicKeyUncompressed:m}=y,v=S.length,R=S[0],N=S.subarray(1);if(f&&v===1&&R===0)return{x:n.ZERO,y:n.ZERO};if(v===h&&(R===2||R===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(R&1)===1!==j&&(z=n.neg(z)),{x:k,y:z}}else if(v===m&&R===4){let k=n.BYTES,q=n.fromBytes(N.subarray(0,k)),z=n.fromBytes(N.subarray(k,k*2));if(!C(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=${m}`)}let I=p===void 0?E:p,T=d===void 0?w:d,O=n.mul(o.b,Ri),M=n.is0(o.a)?S=>n.ZERO:S=>n.mul(o.a,S);function U(S){let h=n.sqr(S),m=n.mul(h,S);return n.add(n.add(m,n.mul(S,o.a)),o.b)}function C(S,h){let m=n.sqr(h),v=U(S);return n.eql(m,v)}if(!C(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let D=n.mul(n.pow(o.a,Ri),jd),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,m=!1){if(!n.isValid(h)||m&&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 A))throw new Error("Weierstrass Point expected")}function B(S){if(!b||!b.basises)throw new Error("no endo");return Vd(S,b.basises,s.ORDER)}function P(S,h,m,v){if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:R,k1:N,k2neg:k,k2:q}=B(v),z=new A(n.mul(m.X,b.beta),m.Y,m.Z);S.push(R?m.negate():m,k?z.negate():z),h.push(N,q)}else S.push(m),h.push(v)}let _=new WeakSet;class A{static BASE=new A(o.Gx,o.Gy,n.ONE);static ZERO=new A(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(h,m,v){this.X=K("x",h),this.Y=K("y",m,!0),this.Z=K("z",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(h){let{x:m,y:v}=h||{};if(!h||!n.isValid(m)||!n.isValid(v))throw new Error("invalid affine point");if(h instanceof A)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(v)?A.ZERO:new A(m,v,n.ONE)}static fromBytes(h){let m=A.fromAffine(T(Z(h,void 0,"point")));return m.assertValidity(),m}static fromHex(h){return A.fromBytes(mr(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,m=!0){return L.setWindowSize(this,h),m||this.multiply(Ri),this}assertValidity(){let h=this;if(h.is0()){if(f&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(_.has(h))return;let{x:m,y:v}=h.toAffine();if(!n.isValid(m)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!C(m,v))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");_.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:m,Y:v,Z:R}=this,{X:N,Y:k,Z:q}=h,z=n.eql(n.mul(m,q),n.mul(N,R)),j=n.eql(n.mul(v,q),n.mul(k,R));return z&&j}negate(){return new A(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:m,Z:v}=this,R=n.ZERO,N=n.ZERO,k=n.ZERO,q=n.mul(h,h),z=n.mul(m,m),j=n.mul(v,v),Y=n.mul(h,m);return Y=n.add(Y,Y),k=n.mul(h,v),k=n.add(k,k),R=M(k),N=n.mul(O,j),N=n.add(R,N),R=n.sub(z,N),N=n.add(z,N),N=n.mul(R,N),R=n.mul(Y,R),k=n.mul(O,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(m,v),j=n.add(j,j),q=n.mul(j,Y),R=n.sub(R,q),k=n.mul(j,z),k=n.add(k,k),k=n.add(k,k),new A(R,N,k)}add(h){$(h);let{X:m,Y:v,Z:R}=this,{X:N,Y:k,Z:q}=h,z=n.ZERO,j=n.ZERO,Y=n.ZERO,ce=n.mul(m,N),ie=n.mul(v,k),ye=n.mul(R,q),Pe=n.add(m,v),ae=n.add(N,k);Pe=n.mul(Pe,ae),ae=n.add(ce,ie),Pe=n.sub(Pe,ae),ae=n.add(m,R);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,R),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(O,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(O,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 A(z,j,Y)}subtract(h){return $(h),this.add(h.negate())}is0(){return this.equals(A.ZERO)}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:m,f:v}=L.mulSecret(this,h,i,H);return H([m,v])[0]}multiplyUnsafe(h){let m=this,v=h;if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===ut||m.is0())return A.ZERO;if(v===Xt)return m;if(L.hasWindowSize(this))return L.mulUnsafe(m,v,H);let R=[],N=[];return P(R,N,m,v),ts(A,R,N)}mulAddUnsafe(h,m,v){$(m);let R=[],N=[];return P(R,N,this,h),P(R,N,m,v),ts(A,R,N)}toAffine(h){let m=this,v=h;if(v!=null&&!n.isValid(v))throw new RangeError('"invertedZ" expected valid field element');let{X:R,Y:N,Z:k}=m;if(n.eql(k,n.ONE))return{x:R,y:N};let q=m.is0();v==null&&(v=q?n.ONE:n.inv(k));let z=n.mul(R,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===Xt?!0:l?l(A,this):L.mulUnsafe(this,a).is0()}clearCofactor(){return i===Xt?this:u?u(A,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Xt?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Ne(h,"isCompressed"),this.assertValidity(),I(A,this,h)}toHex(h=!0){return Wr(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let H=S=>es(A,S),L=new wr(A,g);return L.bits>=6&&A.BASE.precompute(6),Object.freeze(A.prototype),Object.freeze(A),A}function kf(t){return Uint8Array.of(t?2:3)}function Mf(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Wd(t,e={}){Ct(t);let{Fn:r}=t,n=e.randomBytes===void 0?at:e.randomBytes,s=Object.assign(Mf(t.Fp,r),{seed:Math.max(Qn(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:y}=s;try{let x=p.length;return g===!0&&x!==b||g===!1&&x!==y?!1:!t.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(s.seed):p,Jn(Z(p,s.seed,"seed"),r.ORDER)}function c(p,g=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(g)}function f(p){let{secretKey:g,publicKey:b,publicKeyUncompressed:y}=s,x=r._lengths;if(!_t(p))return;let E=Z(p,void 0,"key").length,w=E===b||E===y,I=E===g||!!x?.includes(E);if(!(w&&I))return w}function u(p,g,b=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(g)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(p),x=t.fromBytes(g);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(y).toBytes(b)}let l={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},d=xr(a,c);return Object.freeze(l),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:d,Point:t,utils:l,lengths:s})}function Kf(t,e,r={}){Ct(t);let n=e;Ft(n),Le(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?at:s.randomBytes,i=s.hmac===void 0?(S,h)=>cn(n,S,h):s.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,l=Qn(f),d=Zo(o,l),{keygen:p,getPublicKey:g,getSharedSecret:b,utils:y,lengths:x}=Wd(t,s),E={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},w=f*Uf+Xt<a.ORDER;function I(S){let h=f>>Xt;return S>h}function T(S,h){if(!c.isValidNot0(h))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return h}function O(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(S,h,m){return O(),(S===m?0:2)|Number(a.isOdd(h))}function U(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(S,h){Oi(h);let m=x.signature,v=h==="compact"?m:h==="recovered"?m+1:void 0;return Z(S,v)}class D{r;s;recovery;constructor(h,m,v){if(this.r=T("r",h),this.s=T("s",m),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,m=E.format){C(h,m);let v;if(m==="der"){if(h.length>2*c.BYTES+16)throw new gs.Err("invalid signature: DER signature too long");let{r:q,s:z}=gs.toSig(Z(h),c.BYTES+1);return new D(q,z)}m==="recovered"&&(v=h[0],m="compact",h=h.subarray(1));let R=x.signature/2,N=h.subarray(0,R),k=h.subarray(R,R*2);return new D(c.fromBytes(N),c.fromBytes(k),v)}static fromHex(h,m){return this.fromBytes(mr(h),m)}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:m,s:v}=this,R=this.assertRecovery(),N=R===2||R===3?m+f:m;if(!a.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=a.toBytes(N),q=t.fromBytes(He(kf((R&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 I(this.s)}toBytes(h=E.format){if(Oi(h),h==="der")return mr(gs.hexFromSig(this));let{r:m,s:v}=this,R=c.toBytes(m),N=c.toBytes(v);return h==="recovered"?(U(),He(Uint8Array.of(this.assertRecovery()),R,N)):He(R,N)}toHex(h){return Wr(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 m=Je(h),v=h.length*8-u;return v>0?m>>BigInt(v):m}:s.bits2int,K=s.bits2int_modN===void 0?function(h){return c.create(F(h))}:s.bits2int_modN,$=Zr(u);function B(S){return tt("num < 2^"+u,S,ut,$),c.toBytes(S)}function P(S,h){return Z(S,void 0,"message"),h?Z(n(S),void 0,"prehashed message"):S}function _(S,h,m){let{lowS:v,prehash:R,extraEntropy:N}=Di(m,E);S=P(S,R);let k=K(S),q=c.fromBytes(h);if(!c.isValidNot0(q))throw new Error("invalid private key");let z=[B(q),B(k)];if(N!=null&&N!==!1){let ie=N===!0?o(x.secretKey):N;z.push(Z(ie,void 0,"extraEntropy"))}let j=He(...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===ut)return;let he;if(d!==void 0){let mt=Je(Jn(d(l),f)),Qu=c.inv(c.mul(mt,ye)),Ju=c.mul(mt,Y),el=c.mul(mt,q);he=c.create(Qu*c.create(Ju+el*ae))}else{let mt=Wc(ye,f);he=c.create(mt*c.create(Y+ae*q))}if(he===ut)return;let sr=M(Pe.x,Pe.y,ae),Nr=he;return v&&I(he)&&(Nr=c.neg(he),sr^=1),new D(ae,Nr,w?void 0:sr)}return{seed:j,k2sig:ce}}function A(S,h,m={}){let{seed:v,k2sig:R}=_(S,h,m);return Kc(n.outputLen,c.BYTES,i)(v,R).toBytes(m.format)}function H(S,h,m,v={}){let{lowS:R,prehash:N,format:k}=Di(v,E);if(m=Z(m,void 0,"publicKey"),h=P(h,N),!_t(S)){let q=S instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}C(S,k);try{let q=D.fromBytes(S,k),z=t.fromBytes(m);if(z.is0()||R&&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 L(S,h,m={}){let{prehash:v}=Di(m,E);return h=P(h,v),D.fromBytes(S,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:p,getPublicKey:g,getSharedSecret:b,utils:y,lengths:x,Point:t,sign:A,verify:H,recoverPublicKey:L,Signature:D,hash:n})}var Ui={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ff=BigInt(2);function Gd(t){let e=Ui.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,l=fe(u,r,e)*u%e,d=fe(l,r,e)*u%e,p=fe(d,Ff,e)*f%e,g=fe(p,s,e)*p%e,b=fe(g,o,e)*g%e,y=fe(b,a,e)*b%e,x=fe(y,c,e)*y%e,E=fe(x,a,e)*b%e,w=fe(E,r,e)*u%e,I=fe(w,i,e)*g%e,T=fe(I,n,e)*f%e,O=fe(T,Ff,e);if(!Pi.eql(Pi.sqr(O),t))throw new Error("Cannot find square root");return O}var Pi=br(Ui.p,{sqrt:Gd}),Zd=Nf(Ui,{Fp:Pi,endo:Yd}),vr=Kf(Zd,Qe);function Hf(t,e,r,n){let s=Hr.digest(r instanceof Uint8Array?r:r.subarray());if(us(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),vr.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new tn(String(o))});try{return n?.signal?.throwIfAborted(),vr.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new tn(String(o))}}var bs=class{type="secp256k1";raw;_key;constructor(e){this._key=zf(e),this.raw=qf(this._key)}toMultihash(){return je.digest(xt(this))}toCID(){return we.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){return Hf(this._key,r,e,n)}};function Ni(t){return new bs(t)}function qf(t){return vr.Point.fromBytes(t).toBytes()}function zf(t){try{return vr.Point.fromBytes(t),t}catch(e){throw new ir(String(e))}}function fn(t,e){let{Type:r,Data:n}=rt.decode(t),s=n??new Uint8Array;switch(r){case de.RSA:return Li(s,e);case de.Ed25519:return ti(s);case de.secp256k1:return Ni(s);case de.ECDSA:return Io(s);default:throw new Pt}}function $f(t){let{Type:e,Data:r}=rt.decode(t.digest),n=r??new Uint8Array;switch(e){case de.Ed25519:return ti(n);case de.secp256k1:return Ni(n);case de.ECDSA:return Io(n);default:throw new Pt}}function xt(t){return rt.encode({Type:de[t.type],Data:t.raw})}var Vf=Symbol.for("nodejs.util.inspect.custom"),Xd=114,un=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()})`}[Qs]=!0;toString(){return this.string==null&&(this.string=me.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return we.createV1(Xd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return xe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return xe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Vf](){return`PeerId(${this.toString()})`}},ln=class extends un{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},hn=class extends un{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},dn=class extends un{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Qd=2336,pn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=je.digest(ee(this.url))}[Vf](){return`PeerId(${this.url})`}[Qs]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return we.createV1(Qd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=W(e)),e.toString()===this.toString())}};var Jd=114,jf=2336;function Wf(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 ep(we.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 Yf(r)}function mn(t){if(t.type==="Ed25519")return new hn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new dn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new ln({multihash:t.toCID().multihash,publicKey:t});throw new Pt}function Yf(t){if(rp(t))return new ln({multihash:t});if(tp(t))try{let e=$f(t);if(e.type==="Ed25519")return new hn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new dn({multihash:t,publicKey:e})}catch{let r=W(t.digest);return new pn(new URL(r))}throw new Dn("Supplied PeerID Multihash is invalid")}function ep(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Jd&&t.code!==jf)throw new In("Supplied PeerID CID is invalid");if(t.code===jf){let e=W(t.multihash.digest);return new pn(new URL(e))}return Yf(t.multihash)}function tp(t){return t.code===je.code}function rp(t){return t.code===Hr.code}function np(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 Gf(t){let e=np(t);if(e==null)throw new se(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var ws=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",f=2**(8*s)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(u===void 0)break;if(o*=e,o+=u,o>f||(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 sp=45,op=15,xs=new ws;function Zf(t){if(!(t.length>op))return xs.new(t).parseWith(()=>xs.readIPv4Addr())}function Xf(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>sp))return xs.new(t).parseWith(()=>xs.readIPv6Addr())}function Es(t){return!!Zf(t)}function Qf(t){return!!Xf(t)}var Be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},lt=class extends Error{static name="ValidationError";name="ValidationError"},Ss=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},vs=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Mi(t){return e=>W(e,t)}function Ki(t){return e=>ee(e,t)}function Ar(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Qt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Jf(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=Qt(n);return Ke([r,s],r.length+s.length)}function eu(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=Qt(n);return Ke([r,s],r.length+s.length)}function Fi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=W(e,"base32"),s=Ar(r);return`${n}:${s}`}var Hi=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},tu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let o=Es(r[n]),i;o&&(i=Hi(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},ru=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(".")},nu=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 su(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 ki=Object.values(kt).map(t=>t.decoder),ip=(function(){let t=ki[0].or(ki[1]);return ki.slice(2).forEach(e=>t=t.or(e)),t})();function ou(t){return ip.decode(t)}function iu(t){return e=>t.encoder.encode(e)}function ap(t){if(parseInt(t).toString()!==t)throw new lt("Value must be an integer")}function cp(t){if(t<0)throw new lt("Value must be a positive integer, or zero")}function fp(t){return e=>{if(e>t)throw new lt(`Value must be smaller than or equal to ${t}`)}}function up(...t){return e=>{for(let r of t)r(e)}}var yn=up(ap,cp,fp(65535));var ve=-1,qi=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 vs(`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)}))}},dt=new qi,Ap=[{code:4,name:"ip4",size:32,valueToBytes:Hi,bytesToValue:ru,validate:t=>{if(!Es(t))throw new lt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:yn},{code:273,name:"udp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:yn},{code:33,name:"dccp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:yn},{code:41,name:"ip6",size:128,valueToBytes:tu,bytesToValue:nu,stringToValue:su,validate:t=>{if(!Qf(t))throw new lt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ve},{code:43,name:"ipcidr",size:8,bytesToValue:Mi("base10"),valueToBytes:Ki("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:Qt,bytesToValue:Ar,validate:yn},{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:Mi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?Ki("base58btc")(t):we.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Fi,valueToBytes:Jf},{code:445,name:"onion3",size:296,bytesToValue:Fi,valueToBytes:eu},{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:iu(go),valueToBytes:ou},{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}];Ap.forEach(t=>{dt.addProtocol(t)});function au(t){let e=[],r=0;for(;r<t.length;){let n=zt(t,r),s=dt.getProtocol(n),o=Ce(n),i=Bp(s,t,r+o),a=0;i>0&&s.size===ve&&(a=Ce(i));let c=o+a+i,f={code:n,name:s.name,bytes:Ae(t.subarray(r,r+c))};if(i>0){let u=r+o+a,l=t.subarray(u,u+i);f.value=s.bytesToValue?.(l)??W(l)}e.push(f),r+=c}return e}function cu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let s=dt.getProtocol(n.code),o=Ce(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=Ce(a)));let f=new Uint8Array(o+c+a),u=0;Er(n.code,f,u),u+=o,i!=null&&(s.size===ve&&(Er(a,f,u),u+=c),f.set(i,u)),n.bytes=f}r.push(n.bytes),e+=n.bytes.byteLength}return Ke(r,e)}function fu(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=dt.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 f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Be(`Component ${s} was missing value`);f.value=c.stringToValue?.(n)??n}e.push(f),n="",s="",r="protocol"}}}if(s!==""&&n!=="")throw new Be("Incomplete multiaddr");return e}function uu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=dt.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 Bp(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:zt(e,r)}var _p=Symbol.for("nodejs.util.inspect.custom"),ia=Symbol.for("@multiformats/multiaddr");function Lp(t){if(t==null&&(t="/"),lu(t))return t.getComponents();if(t instanceof Uint8Array)return au(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),fu(t);if(Array.isArray(t))return t;throw new Be("Must be a string, Uint8Array, Component[], or another Multiaddr")}var oa=class t{[ia]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Lp(e),r.validate!==!1&&Tp(this)}get bytes(){return this.#r==null&&(this.#r=cu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=uu(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 Ss(`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 xe(this.bytes,e.bytes)}[_p](){return`Multiaddr(${this.toString()})`}};function Tp(t){t.getComponents().forEach(e=>{let r=dt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function lu(t){return!!t?.[ia]}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)}}),hu=t=>({match:e=>t.match(e)===!1?e:!1}),G=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),De=(...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 le(...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 Cp=V(421),e1=le(Cp),Is=V(54),Ds=V(55),Rs=V(56),ca=V(53),t1=le(Is,G(V(421))),r1=le(Ds,G(V(421))),n1=le(Rs,G(V(421))),s1=le(De(ca,Rs,Is,Ds),G(V(421))),du=J(V(4),G(V(43))),pu=J(G(V(42)),V(41),G(V(43))),fa=De(du,pu),Tr=De(fa,ca,Is,Ds,Rs),o1=le(De(fa,J(De(ca,Rs,Is,Ds),G(V(421))))),i1=le(du),a1=le(pu),c1=le(fa),ua=J(Tr,V(6)),gn=J(Tr,V(273)),f1=le(J(ua,G(V(421)))),u1=le(gn),la=J(gn,ue(460),G(V(421))),Os=J(gn,ue(461),G(V(421))),Ip=De(la,Os),l1=le(la),h1=le(Os),aa=De(Tr,ua,gn,la,Os),mu=De(J(aa,ue(477),G(V(421)))),d1=le(mu),yu=De(J(aa,ue(478),G(V(421))),J(aa,ue(448),G(V(449)),ue(477),G(V(421)))),p1=le(yu),gu=J(gn,ue(280),G(V(466)),G(V(466)),G(V(421))),m1=le(gu),bu=J(Os,ue(465),G(V(466)),G(V(466)),G(V(421))),Ps=le(bu),Cs=De(mu,yu,J(ua,G(V(421))),J(Ip,G(V(421))),J(Tr,G(V(421))),gu,bu,V(421)),y1=le(Cs),Dp=J(G(Cs),ue(290),hu(ue(281)),G(V(421))),g1=le(Dp),Rp=De(J(Cs,ue(290),ue(281),G(V(421))),J(Cs,ue(281),G(V(421))),J(ue(281),G(V(421)))),b1=le(Rp),Op=J(Tr,De(J(V(6,"80")),J(V(6),ue(480)),ue(480)),G(V(481)),G(V(421))),w1=le(Op),Pp=J(Tr,De(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))),x1=le(Pp),Up=De(J(V(777),G(V(421)))),E1=le(Up),Np=De(J(V(400),G(V(421)))),S1=le(Np);function Us(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Ns=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}},Cr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ns(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 Ns(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 ha=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ks(t={}){return kp(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 kp(t,e){e=e??{};let r=e.onEnd,n=new Cr,s,o,i,a=Us(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,x)=>{o=E=>{o=null,n.push(E);try{y(t(n))}catch(w){x(w)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Us()})}},f=y=>o!=null?o(y):(n.push(y),s),u=y=>(n=new Cr,o!=null?o({error:y}):(n.push({error:y}),s)),l=y=>{if(i)return s;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:y})},d=y=>i?s:(i=!0,y!=null?u(y):f({done:!0})),p=()=>(n=new Cr,d(),{done:!0}),g=y=>(d(y),{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 y=>{let x=y?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,w;x!=null&&(E=new Promise((I,T)=>{w=()=>{T(new ha)},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(y){return b.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(y){return b.end(y),r!=null&&(r(y),r=void 0),s},get readableLength(){return b.readableLength},onEmpty:y=>b.onEmpty(y)},s}var da=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},wu=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function pa(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,u=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(wu(i)),t.then(l,d);return}if(i&&(c=()=>{d(wu(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,d),r===Number.POSITIVE_INFINITY)return;let p=new da;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(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},u}var Mp=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Kp(t,e,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:u}=Mp(t),l=async(...p)=>{let g=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(g))return}catch(b){n(),i(b);return}c.push(g),r.count===c.length&&(n(),o(c))},d=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)u(p,l);for(let p of r.rejectionEvents)a.includes(p)||u(p,d)};for(let p of a)f(p,l);for(let p of r.rejectionEvents)a.includes(p)||f(p,d);r.signal&&r.signal.addEventListener("abort",()=>{d(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=pa(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function Dt(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Kp(t,e,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var er=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},Ms=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},Ks=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Fp(t){return t.reason}function $e(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Fp;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 Hp=Math.pow(2,20)*4,nt=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??Hp,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 Ks)};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()),$e(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){let e=ks(),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 On(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 Tn;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 Pn(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 Rn(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 Ot(`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 Ot(`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 Fs=class extends nt{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 Dt(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 Dt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function xu(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Hs=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 $e(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 Ln;let r=this.onCreateStream({...this.streamOptions,...e});return xu(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 Ms(`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 qs=class extends nt{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 Dt(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 Dt(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 qp=4194304,zs=class extends Error{static name="UnwrappedError";name="UnwrappedError"},bn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ya=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ga=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function zp(t){return typeof t?.closeRead=="function"}function $p(t){return typeof t?.close=="function"}function ma(t){return zp(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:$p(t)?t.status!=="open":!1}function Vp(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function jp(t,e){let r=e?.maxBufferSize??qp,n=new Q,s,o=!1,i;if(!Vp(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 Ot(`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 f=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",f);let u={readBuffer:n,async read(l){if(o===!0)throw new zs("Stream was unwrapped");if(i!=null)throw i;if(ma(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 er(`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 $e(s.promise,l?.signal),ma(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(ma(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new er(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return u.read(l)}let g=n.sublist(0,p);return n.consume(p),g},async write(l,d){if(o===!0)throw new zs("Stream was unwrapped");t.send(l)||await Dt(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",f),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return u}function ba(t,e={}){let r=jp(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ce(e.maxDataLength));let n=e?.lengthDecoder??zt,s=e?.lengthEncoder??gf;return{async read(i){let a=-1,c=new Q;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new bn("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ga(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ya(`Message length too long - ${a} > ${e.maxDataLength}`);let f=await r.read({...i,bytes:a});if(f==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new er(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new er(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await r.write(new Q(s(i.byteLength),i),a)},async writeV(i,a){let c=new Q(...i.flatMap(f=>[s(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var Wp=1024*1024*4,Yp=1024*1024*4,$s=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new Q,this.maxBufferSize=e.maxBufferSize??Wp,this.maxDataLength=e.maxDataLength??Yp,this.lengthDecoder=e.lengthDecoder??zt,this.encodingLength=e.encodingLength??Ce}*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 bn("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 Ir=!!globalThis.process?.env?.DUMP_SESSION_KEYS,wa=16;function xa(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Vs=t=>t?`"${t}" `:"";function js(t,e=""){if(typeof t!="boolean")throw new TypeError(Vs(e)+"expected boolean, got type="+typeof t);return t}function tr(t,e=""){if(typeof t!="number")throw new TypeError(Vs(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Vs(e)+"expected integer >= 0, got "+t);return t}function ge(t,e,r=""){if(xa(t)&&(e===void 0||t.length===e))return t;e!==void 0&&tr(e,"length");let n=xa(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=Vs(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}var Eu=(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 Ea(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Su(t,e){ge(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function st(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Ze(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Gp(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var Rt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Zp(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Xp(t){for(let e=0;e<t.length;e++)t[e]=Zp(t[e]);return t}var pt=Rt?t=>t:Xp;function Qp(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 vu(t,e){if(Qp(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function Au(t,e){return Eu(t,"defaults"),Eu(e,"opts"),Object.assign(t,e)}function Bu(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 _u(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 Lu=(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(xa(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")}},f=!1;return{encrypt(l,d){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!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 wn(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(ge(e,t,"output"),r&&!xn(e))throw new Error("invalid output, must be aligned");return e}function Tu(t,e,r){tr(t),tr(e),js(r);let n=new Uint8Array(16),s=Gp(n);return s.setBigUint64(0,BigInt(e),r),s.setBigUint64(8,BigInt(t),r),n}function xn(t){return t.byteOffset%4===0}function Dr(t){return Uint8Array.from(ge(t))}var Iu=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),Jp=pt(st(Iu("expand 16-byte k"))),em=pt(st(Iu("expand 32-byte k")));function X(t,e){return t<<e|t>>>32-e}var En=64,tm=16,Sa=2**32-1,Cu=Uint32Array.of();function rm(t,e,r,n,s,o,i,a){let c=s.length,f=new Uint8Array(En),u=st(f),l=Rt&&xn(s)&&xn(o),d=l?st(s):Cu,p=l?st(o):Cu;if(!Rt){for(let g=0;g<c;i++){if(t(e,r,n,u,i,a),pt(u),i>=Sa)throw new Error("arx: counter overflow");let b=Math.min(En,c-g);for(let y=0,x;y<b;y++)x=g+y,o[x]=s[x]^f[y];g+=b}return}for(let g=0;g<c;i++){if(t(e,r,n,u,i,a),i>=Sa)throw new Error("arx: counter overflow");let b=Math.min(En,c-g);if(l&&b===En){let y=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let x=0,E;x<tm;x++)E=y+x,p[E]=d[E]^u[x];g+=En;continue}for(let y=0,x;y<b;y++)x=g+y,o[x]=s[x]^f[y];g+=b}}function Du(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Au({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return tr(s),tr(i),js(o),js(r),(a,c,f,u,l=0)=>{ge(a,void 0,"key"),ge(c,void 0,"nonce"),ge(f,void 0,"data");let d=f.length,p=u!==void 0;if(u=wn(d,u,!1),p&&vu(f,u),tr(l),l<0||l>=Sa)throw new Error("arx: counter overflow");let g=[],b=a.length,y,x;if(b===32)g.push(y=Dr(a)),x=em;else if(b===16&&r)y=new Uint8Array(32),y.set(a),y.set(a,16),x=Jp,g.push(y);else throw ge(a,32,"arx key"),new Error("invalid key size");(!Rt||!xn(c))&&g.push(c=Dr(c));let E=st(y);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let T=c.subarray(0,16);if(Rt)n(x,E,st(T),E);else{let O=pt(Uint32Array.from(x));n(O,E,st(T),E),Ze(O),pt(E)}c=c.subarray(16)}else Rt||pt(E);let w=16-s;if(w!==c.length)throw new Error(`arx: nonce must be ${w} or 16 bytes`);if(w!==12){let T=new Uint8Array(12);T.set(c,o?0:12-c.length),c=T,g.push(c)}let I=pt(st(c));try{return rm(t,x,E,I,f,u,l,i),u}finally{Ze(...g)}}}function _e(t,e){return t[e++]&255|(t[e++]&255)<<8}var va=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=Dr(ge(e,32,"key"));let r=_e(e,0),n=_e(e,2),s=_e(e,4),o=_e(e,6),i=_e(e,8),a=_e(e,10),c=_e(e,12),f=_e(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|f<<8)&8191,this.r[9]=f>>>5&127;for(let u=0;u<8;u++)this.pad[u]=_e(e,16+2*u)}process(e,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],f=i[2],u=i[3],l=i[4],d=i[5],p=i[6],g=i[7],b=i[8],y=i[9],x=_e(e,r+0),E=_e(e,r+2),w=_e(e,r+4),I=_e(e,r+6),T=_e(e,r+8),O=_e(e,r+10),M=_e(e,r+12),U=_e(e,r+14),C=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|I<<9)&8191),$=o[4]+((I>>>4|T<<12)&8191),B=o[5]+(T>>>1&8191),P=o[6]+((T>>>14|O<<2)&8191),_=o[7]+((O>>>11|M<<5)&8191),A=o[8]+((M>>>8|U<<8)&8191),H=o[9]+(U>>>5|s),L=0,S=L+C*a+D*(5*y)+F*(5*b)+K*(5*g)+$*(5*p);L=S>>>13,S&=8191,S+=B*(5*d)+P*(5*l)+_*(5*u)+A*(5*f)+H*(5*c),L+=S>>>13,S&=8191;let h=L+C*c+D*a+F*(5*y)+K*(5*b)+$*(5*g);L=h>>>13,h&=8191,h+=B*(5*p)+P*(5*d)+_*(5*l)+A*(5*u)+H*(5*f),L+=h>>>13,h&=8191;let m=L+C*f+D*c+F*a+K*(5*y)+$*(5*b);L=m>>>13,m&=8191,m+=B*(5*g)+P*(5*p)+_*(5*d)+A*(5*l)+H*(5*u),L+=m>>>13,m&=8191;let v=L+C*u+D*f+F*c+K*a+$*(5*y);L=v>>>13,v&=8191,v+=B*(5*b)+P*(5*g)+_*(5*p)+A*(5*d)+H*(5*l),L+=v>>>13,v&=8191;let R=L+C*l+D*u+F*f+K*c+$*a;L=R>>>13,R&=8191,R+=B*(5*y)+P*(5*b)+_*(5*g)+A*(5*p)+H*(5*d),L+=R>>>13,R&=8191;let N=L+C*d+D*l+F*u+K*f+$*c;L=N>>>13,N&=8191,N+=B*a+P*(5*y)+_*(5*b)+A*(5*g)+H*(5*p),L+=N>>>13,N&=8191;let k=L+C*p+D*d+F*l+K*u+$*f;L=k>>>13,k&=8191,k+=B*c+P*a+_*(5*y)+A*(5*b)+H*(5*g),L+=k>>>13,k&=8191;let q=L+C*g+D*p+F*d+K*l+$*u;L=q>>>13,q&=8191,q+=B*f+P*c+_*a+A*(5*y)+H*(5*b),L+=q>>>13,q&=8191;let z=L+C*b+D*g+F*p+K*d+$*l;L=z>>>13,z&=8191,z+=B*u+P*f+_*c+A*a+H*(5*y),L+=z>>>13,z&=8191;let j=L+C*y+D*b+F*g+K*p+$*d;L=j>>>13,j&=8191,j+=B*l+P*u+_*f+A*c+H*a,L+=j>>>13,j&=8191,L=(L<<2)+L|0,L=L+S|0,S=L&8191,L=L>>>13,h+=L,o[0]=S,o[1]=h,o[2]=m,o[3]=v,o[4]=R,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;Ze(n)}update(e){Ea(this),ge(e),e=Dr(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,Ze(this.h,this.r,this.buffer,this.pad)}digestInto(e){Ea(this),Su(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}},Ru=_u(32,t=>new va(t));function nm(t,e,r,n,s,o=20){let i=t[0],a=t[1],c=t[2],f=t[3],u=e[0],l=e[1],d=e[2],p=e[3],g=e[4],b=e[5],y=e[6],x=e[7],E=s,w=r[0],I=r[1],T=r[2],O=i,M=a,U=c,C=f,D=u,F=l,K=d,$=p,B=g,P=b,_=y,A=x,H=E,L=w,S=I,h=T;for(let v=0;v<o;v+=2)O=O+D|0,H=X(H^O,16),B=B+H|0,D=X(D^B,12),O=O+D|0,H=X(H^O,8),B=B+H|0,D=X(D^B,7),M=M+F|0,L=X(L^M,16),P=P+L|0,F=X(F^P,12),M=M+F|0,L=X(L^M,8),P=P+L|0,F=X(F^P,7),U=U+K|0,S=X(S^U,16),_=_+S|0,K=X(K^_,12),U=U+K|0,S=X(S^U,8),_=_+S|0,K=X(K^_,7),C=C+$|0,h=X(h^C,16),A=A+h|0,$=X($^A,12),C=C+$|0,h=X(h^C,8),A=A+h|0,$=X($^A,7),O=O+F|0,h=X(h^O,16),_=_+h|0,F=X(F^_,12),O=O+F|0,h=X(h^O,8),_=_+h|0,F=X(F^_,7),M=M+K|0,H=X(H^M,16),A=A+H|0,K=X(K^A,12),M=M+K|0,H=X(H^M,8),A=A+H|0,K=X(K^A,7),U=U+$|0,L=X(L^U,16),B=B+L|0,$=X($^B,12),U=U+$|0,L=X(L^U,8),B=B+L|0,$=X($^B,7),C=C+D|0,S=X(S^C,16),P=P+S|0,D=X(D^P,12),C=C+D|0,S=X(S^C,8),P=P+S|0,D=X(D^P,7);let m=0;n[m++]=i+O|0,n[m++]=a+M|0,n[m++]=c+U|0,n[m++]=f+C|0,n[m++]=u+D|0,n[m++]=l+F|0,n[m++]=d+K|0,n[m++]=p+$|0,n[m++]=g+B|0,n[m++]=b+P|0,n[m++]=y+_|0,n[m++]=x+A|0,n[m++]=E+H|0,n[m++]=w+L|0,n[m++]=I+S|0,n[m++]=T+h|0}var sm=Du(nm,{counterRight:!1,counterLength:4,allowShortKeys:!1});var om=new Uint8Array(16),Ou=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(om.subarray(r))},im=new Uint8Array(32);function Pu(t,e,r,n,s){s!==void 0&&ge(s,void 0,"AAD");let o=t(e,r,im),i=Tu(n.length,s?s.length:0,!0),a=Ru.create(o);s&&Ou(a,s),Ou(a,n),a.update(i);let c=a.digest();return Ze(o,i),c}var am=t=>(e,r,n)=>({encrypt(o,i){let a=o.length;i=wn(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);t(e,r,c,c,1);let f=Pu(t,e,r,c,n);return i.set(f,a),Ze(f),i},decrypt(o,i){i=wn(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),f=Pu(t,e,r,a,n);if(!Bu(c,f))throw Ze(f),new Error("invalid tag");return i.set(o.subarray(0,-16)),t(e,r,i,i,1),Ze(f),i}}),Aa=Lu({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},am(sm));function Uu(t,e,r){return Ft(t),r===void 0&&(r=new Uint8Array(t.outputLen)),cn(t,r,e)}var Sn=Uint8Array.of(0),cm=Uint8Array.of();function Nu(t,e,r,n=32,s){Ft(t),We(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=cm:Oe(r,void 0,"info"),!i)return s&&Fe(e),new Uint8Array;let a=s&&i===1?e:new Uint8Array(i*o),{iHash:c,oHash:f}=cn.create(t,e),u=s?e:new Uint8Array(o),l=i>1?s?.iHash||t.create():void 0;for(let p=0;p<i-1;p++){Sn[0]=p+1;let g=c._cloneInto(l);p&&g.update(u),g.update(r).update(Sn).digestInto(u),f._cloneInto(l).update(u).digestInto(u),a.set(u,o*p)}if(Sn[0]=i,i>1&&c.update(u),c.update(r).update(Sn).digestInto(u),f.update(u).digestInto(u),a.set(u,o*(i-1)),c.destroy(),f.destroy(),l?.destroy(),u!==a&&Fe(u),Fe(Sn),n===a.length)return a;let d=a.slice(0,n);return Fe(a),d}var ku={hashSHA256(t){return Qe(t.subarray())},getHKDF(t,e){let r=Uu(Qe,e,t),s=Nu(Qe,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=en.utils.randomSecretKey();return{publicKey:en.getPublicKey(t),privateKey:t}},generateX25519KeyPairFromSeed(t){return{publicKey:en.getPublicKey(t),privateKey:t}},generateX25519SharedKey(t,e){return en.getSharedSecret(t.subarray(),e.subarray())},chaCha20Poly1305Encrypt(t,e,r,n){return Aa(n,e,r).encrypt(t.subarray())},chaCha20Poly1305Decrypt(t,e,r,n,s){return Aa(n,e,r).decrypt(t.subarray(),s)}};var Mu=ku;function Ku(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 Rr=t=>{let e=Se(2);return e[0]=t>>8,e[1]=t,e};Rr.bytes=2;var Or=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)};Or.bytes=2;function Fu(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 Ba(t,e){!e.enabled||!Ir||(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 _a(t,e){!e.enabled||!Ir||(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 Hu(t,e){!e.enabled||!Ir||e(t?`REMOTE_STATIC_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote static public key.")}function La(t,e){!e.enabled||!Ir||e(t?`REMOTE_EPHEMERAL_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Ta(t,e,r){!r.enabled||!Ir||(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 Pr=class t extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=t.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var fm=0,um=4294967295,lm="Cipherstate has reached maximum n, a new handshake must be performed",Ws=class{n;bytes;view;constructor(e=fm){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>um)throw new Error(lm)}};var rr=be(0),Ur=class{k;n;crypto;constructor(e,r=void 0,n=0){this.crypto=e,this.k=r,this.n=new Ws(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}},Ca=class{cs;ck;h;crypto;constructor(e,r){this.crypto=e;let n=ee(r,"utf-8");this.h=hm(e,n),this.ck=this.h,this.cs=new Ur(e)}mixKey(e){let[r,n]=this.crypto.hkdf(this.ck,e);this.ck=r,this.cs=new Ur(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,rr);return[new Ur(this.crypto,e),new Ur(this.crypto,r)]}},Ia=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:f}=e;this.crypto=r,this.ss=new Ca(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=f}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()}},vn=class extends Ia{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 Pr(`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 Pr(`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 Pr(`handshake stage 2 validation fail: ${r.message}`)}}};function hm(t,e){if(e.length<=32){let r=be(32);return r.set(e),r}else return t.hash(e)}var An;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((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:[]},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{if(a.limits?.webtransportCerthashes!=null&&c.webtransportCerthashes.length===a.limits.webtransportCerthashes)throw new Zt('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 Zt('Decode error - repeated field "streamMuxers" had too many elements');c.streamMuxers.push(o.string());break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f={webtransportCerthashes:0,streamMuxers:0},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{if(c.limits?.webtransportCerthashes!=null&&f.webtransportCerthashes===c.limits.webtransportCerthashes)throw new Zt('Streaming decode error - repeated field "webtransportCerthashes" had too many elements');yield{field:`${a}.webtransportCerthashes[]`,index:f.webtransportCerthashes,value:o.bytes()},f.webtransportCerthashes++;break}case 2:{if(c.limits?.streamMuxers!=null&&f.streamMuxers===c.limits.streamMuxers)throw new Zt('Streaming decode error - repeated field "streamMuxers" had too many elements');yield{field:`${a}.streamMuxers[]`,index:f.streamMuxers,value:o.string()},f.streamMuxers++;break}default:{o.skipType(l&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(An||(An={}));var Bn;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((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),An.codec().encode(o.extensions,i)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={identityKey:be(0),identitySig:be(0)},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.identityKey=o.bytes();break}case 2:{c.identitySig=o.bytes();break}case 4:{c.extensions=An.codec().decode(o,o.uint32(),{limits:a.limits?.extensions});break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.identityKey`,value:o.bytes()};break}case 2:{yield{field:`${a}.identitySig`,value:o.bytes()};break}case 4:{yield*An.codec().stream(o,o.uint32(),`${a}.extensions`,{limits:c.limits?.extensions});break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(Bn||(Bn={}));async function Ra(t,e,r){let n=await t.sign(zu(e));return Bn.encode({identityKey:xt(t.publicKey),identitySig:n,extensions:r})}async function Oa(t,e,r){try{let n=Bn.decode(t),s=fn(n.identityKey);if(r!=null){let i=mn(s);if(!r.equals(i))throw new Error(`Payload peer id ${i} does not match expected remote peer id ${r}`)}if(!e)throw new Error("Remote static does not exist");let o=zu(e);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new _n(n.message)}}function zu(t){let e=ee("noise-libp2p-static-key:");return t instanceof Uint8Array?Ke([e,t],e.length+t.length):(t.prepend(e),t)}var Da=class extends nt{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 $s({lengthDecoder:Or,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let f of this.decoder.decode(c.data))this.onData(this.decrypt(f))}catch(f){this.abort(f)}};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(Rr(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-wa<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-wa);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 Pa(t,e,r){return new Da(t,e,r)}async function $u(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remotePeer:c,extensions:f}=t,u=await Ra(o,a.publicKey,f),l=new vn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Ba(l.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(l.writeMessageA(rr),e),r.trace("Stage 0 - Initiator finished sending first message."),_a(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."),La(l.re,r),Hu(l.rs,r),r.trace("Initiator going to check remote's signature...");let p=await Oa(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(u),e),r.trace("Stage 2 - Initiator sent message with signed payload.");let[g,b]=l.ss.split();return Ta(g,b,r),{payload:p,encrypt:y=>g.encryptWithAd(rr,y),decrypt:(y,x)=>b.decryptWithAd(rr,y,x)}}async function Vu(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remotePeer:c,extensions:f}=t,u=await Ra(o,a.publicKey,f),l=new vn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Ba(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."),La(l.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(l.writeMessageB(u),e),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),_a(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 Oa(d,l.rs,c),[g,b]=l.ss.split();return Ta(g,b,r),{payload:p,encrypt:y=>b.encryptWithAd(rr,y),decrypt:(y,x)=>g.decryptWithAd(rr,y,x)}}var Gs=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??Mu;this.crypto=Ku(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?Fu(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??be(0)}[Symbol.toStringTag]="@libp2p/noise";[Un]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,r){let n=e.log?.newScope("noise")??this.log,s=ba(e,{lengthEncoder:Rr,lengthDecoder:Or,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer,r),i=fn(o.payload.identityKey);return{connection:Pa(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:mn(i),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 or("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=ba(e,{lengthEncoder:Rr,lengthDecoder:Or,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer,r),i=fn(o.payload.identityKey);return{connection:Pa(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:mn(i),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 $u({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 Vu({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 ju(t={}){return e=>new Gs(e,t)}var nr=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function Ua(t){throw new Error("Not implemented")}var Na=class extends qs{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 $e(this.writer.close().catch(()=>{}),e?.signal),this.log("sendCloseWrite closed writer")}async sendCloseRead(e){this.log("sendCloseRead cancelling reader"),await $e(this.reader.cancel(),e?.signal),this.log("sendCloseRead cancelled reader")}sendPause(){}sendResume(){this.readData()}};function ka(t,e,r,n,s){return new Na({...s,stream:t,id:e,direction:r,log:n.newScope(`${r}:${e}`),protocol:""})}var Wu="/webtransport",Ma=class extends Hs{webTransport;streamIDCounter;reader;constructor(e,r){super(r,{protocol:Wu,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(ka(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(),ka(r,String(this.streamIDCounter++),"outbound",this.log,e)}onData(){}sendReset(){this.webTransport.close()}};function Yu(t){return{protocol:Wu,createStreamMuxer(e){return new Ma(t,e)}}}var Ka=class extends Fs{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(){}},Gu=t=>new Ka(t);function Zu(t,e){return e.filter(n=>!!t.find(s=>xe(n,s))).length===e.length}var dm=Object.values(kt).map(t=>t.decoder).reduce((t,e)=>t.or(e));function pm(t){return ot.decode(dm.decode(t))}function Fa(t){if(!Ps.matches(t))throw new Cn("Invalid multiaddr, was not a WebTransport address");let e=[],r;for(let o of t.getComponents())o.name==="certhash"&&e.push(pm(o.value??"")),o.name==="p2p"&&r==null&&(r=Wf(o.value??""));let n=Gf(t),s=n.host;return n.type==="ip6"&&s.includes(":")&&(s=`[${s}]`),{url:`https://${s}:${n.port}`,certhashes:e,remotePeer:r}}var Zs=class extends nt{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 $e(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 Xu=globalThis.WebTransport;var Ha=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";[za]=!0;[Un]=["@libp2p/transport"];async dial(e,r){r.signal.throwIfAborted(),this.log("dialing %s",e),r=r??{};let{url:n,certhashes:s,remotePeer:o}=Fa(e),i,a,c=()=>{},f=!1,u=!1,l=!1;try{this.metrics?.dialerEvents.increment({pending:!0});let d=new Xu(`${n}/.well-known/libp2p-webtransport?type=noise`,{serverCertificateHashes:s.map(g=>({algorithm:"sha-256",value:Ae(g.digest)}))});c=g=>{if(!f)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()),f=!0}},i=()=>{c(u?"noise_timeout":"ready_timeout")},r.signal.addEventListener("abort",i,{once:!0}),this.log("wait for session to be ready"),r.onProgress?.(new nr("webtransport:wait-for-session")),await Promise.race([d.closed,d.ready]),this.log("session became ready"),u=!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=Gu({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 or("Failed to authenticate webtransport");return await r.upgrader.upgradeOutbound(a,{...r,skipEncryption:!0,remotePeer:p,muxerFactory:Yu(d),skipProtection:!0})}catch(d){throw this.log.error("caught wt session err - %e",d),c(l?"upgrade_error":u?"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 nr("webtransport:open-authentication-stream"));let a=await e.createBidirectionalStream();i?.throwIfAborted();let c=new Zs({stream:a,log:r.log.newScope("muxer")}),f=ju()(this.components);o?.(new nr("webtransport:secure-outbound-connection"));let{remoteExtensions:u,remotePeer:l}=await f.secureOutbound(c,{signal:i,remotePeer:n,skipStreamMuxerNegotiation:!0});if(o?.(new nr("webtransport:close-authentication-stream")),await c.close({signal:i}),!Zu(u?.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 Ua(this.components,{...e,certificates:this.config.certificates})}listenFilter(){return[]}dialFilter(e){return globalThis.WebTransport==null?[]:e.filter(r=>{if(!Ps.exactMatch(r))return!1;let{url:n,certhashes:s}=Fa(r);return n!=null&&s.length>0})}};function mm(t={}){return e=>new Ha(e,t)}return ol(ym);})();
|
|
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);})();
|
|
3
3
|
//! TODO unclear how to add backpressure here?
|
|
4
4
|
/*! Bundled license information:
|
|
5
5
|
|
|
6
|
+
@noble/ciphers/utils.js:
|
|
7
|
+
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
8
|
+
|
|
6
9
|
@noble/curves/utils.js:
|
|
7
10
|
@noble/curves/abstract/modular.js:
|
|
8
11
|
@noble/curves/abstract/curve.js:
|
|
@@ -13,9 +16,6 @@
|
|
|
13
16
|
@noble/curves/abstract/weierstrass.js:
|
|
14
17
|
@noble/curves/secp256k1.js:
|
|
15
18
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
16
|
-
|
|
17
|
-
@noble/ciphers/utils.js:
|
|
18
|
-
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
19
19
|
*/
|
|
20
20
|
return Libp2PWebtransport}));
|
|
21
21
|
//# sourceMappingURL=index.min.js.map
|