@libp2p/webtransport 6.0.38 → 6.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PWebtransport = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PWebtransport=(()=>{var Ks=Object.defineProperty;var cd=Object.getOwnPropertyDescriptor;var fd=Object.getOwnPropertyNames;var ud=Object.prototype.hasOwnProperty;var st=(r,t)=>{for(var e in t)Ks(r,e,{get:t[e],enumerable:!0})},hd=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of fd(t))!ud.call(r,o)&&o!==e&&Ks(r,o,{get:()=>t[o],enumerable:!(n=cd(t,o))||n.enumerable});return r};var ld=r=>hd(Ks({},"__esModule",{value:!0}),r);var qg={};st(qg,{webTransport:()=>Vg});var to=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},gr=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},rt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},br=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var eo=class extends Error{static name="MuxerClosedError";constructor(t="The muxer is closed"){super(t),this.name="MuxerClosedError"}},ro=class extends Error{static name="StreamResetError";constructor(t="The stream has been reset"){super(t),this.name="StreamResetError"}};var Ie=class extends Error{static name="StreamStateError";constructor(t="The stream is in an invalid state"){super(t),this.name="StreamStateError"}},We=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var no=class extends Error{static name="InvalidMultiaddrError";constructor(t="Invalid multiaddr"){super(t),this.name="InvalidMultiaddrError"}},oo=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},so=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ge=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var io=class extends Event{data;constructor(t,e){super("message",e),this.data=t}},wr=class extends Event{error;local;constructor(t,e,n){super("close",n),this.error=e,this.local=t}},ao=class extends wr{constructor(t,e){super(!0,t,e)}},co=class extends wr{constructor(t,e){super(!1,t,e)}};var Fs=Symbol.for("@libp2p/peer-id");var pf=Symbol.for("@libp2p/transport");var df;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(df||(df={}));function dd(r){return typeof r?.handleEvent=="function"}function pd(r){return r===!0||r===!1}function md(r){return pd(r)?r:r?.capture??!1}function Hs(r){let t={capture:md(r),once:!!r?.once};return r?.passive!=null&&(t.passive=r?.passive),r?.signal!=null&&(t.signal=r?.signal),t}function mf(r,t){return Hs(r).capture===Hs(t).capture}var xr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){let o=Hs(n);if(o?.signal?.aborted===!0)return;let s=f=>{o.once&&this.removeEventListener(t,e,o),dd(e)?e.handleEvent(f):e(f)},i=this.#t.get(t);if(i==null&&(i=[],this.#t.set(t,i)),i.some(f=>f.callback!==e?!1:mf(f.options,o)))return;super.addEventListener(t,s,o);let c=()=>{this.removeEventListener(t,e,o)};o.signal?.addEventListener("abort",c),i.push({callback:e,wrapper:s,options:o,onAbort:c})}removeEventListener(t,e,n){let o=this.#t.get(t);if(o==null){super.removeEventListener(t,e??null,n);return}this.#t.set(t,o.filter(s=>s.callback===e&&mf(s.options,n)?(super.removeEventListener(t,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var fo=Symbol.for("@libp2p/service-capabilities");var js={};st(js,{base58btc:()=>yt,base58flickr:()=>Ad});var Sb=new Uint8Array(0);function gf(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Vt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return Ye(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return Ye(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function bf(r){let t=new Uint8Array(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}var yf=4096;function wf(r){let t=r.length;if(t<=yf)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.subarray(n,n+=yf));return e}function yd(r){return r?.buffer instanceof ArrayBuffer}function Ye(r){return yd(r)?r:r.slice()}function gd(r,t,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,e){var c=i.toLowerCase().charCodeAt(0),f=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),f!==a&&(n[f]=s)}}var h=r.length,u=r.charAt(0),d=Math.log(h)/Math.log(256),p=Math.log(256)/Math.log(h);function m(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,v=0,B=x.length;v!==B&&x[v]===0;)v++,E++;for(var D=(B-v)*p+1>>>0,P=new Uint8Array(D);v!==B;){for(var R=x[v],L=0,O=D-1;(R!==0||L<w)&&O!==-1;O--,L++)R+=256*P[O]>>>0,P[O]=R%h>>>0,R=R/h>>>0;if(R!==0)throw new Error("Non-zero carry");w=L,v++}for(var F=D-w;F!==D&&P[F]===0;)F++;for(var K=u.repeat(E);F<D;++F)K+=r.charAt(P[F]);return K}function g(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var E=0;if(x[E]!==" "){for(var w=0,v=0;x[E]===u;)w++,E++;for(var B=(x.length-E)*d+1>>>0,D=new Uint8Array(B);x[E];){var P=n[x.charCodeAt(E)];if(P===255)return;for(var R=0,L=B-1;(P!==0||R<v)&&L!==-1;L--,R++)P+=h*D[L]>>>0,D[L]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");v=R,E++}if(x[E]!==" "){for(var O=B-v;O!==B&&D[O]===0;)O++;for(var F=new Uint8Array(w+(B-O)),K=w;O!==B;)F[K++]=D[O++];return F}}}function y(x){var E=g(x);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:m,decodeUnsafe:g,decode:y}}var bd=gd,wd=bd,Ef=wd;var zs=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Vs=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Sf(this,t)}},qs=class{decoders;constructor(t){this.decoders=t}or(t){return Sf(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Sf(r,t){return new qs({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var $s=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new zs(t,e,n),this.decoder=new Vs(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Er({name:r,prefix:t,encode:e,decode:n}){return new $s(r,t,e,n)}function Ce({name:r,prefix:t,alphabet:e,caseInsensitive:n=!1}){let{encode:o,decode:s}=Ef(e,r,n);return Er({prefix:t,name:r,encode:o,decode:i=>Vt(s(i))})}function xd(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let h=t[r[f]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|h,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ed(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Sd(r,t){let e={};for(let n=0;n<r.length;++n)if(e[r[n]]=n,t){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(e[o]=n),s!==r[n]&&(e[s]=n)}return e}function mt({name:r,prefix:t,bitsPerChar:e,alphabet:n,caseInsensitive:o=!1}){let s=Sd(n,o);return Er({prefix:t,name:r,encode(i){return Ed(i,n,e)},decode(i){return xd(i,s,e,r)}})}var yt=Ce({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ad=Ce({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ws={};st(Ws,{base32:()=>Te,base32hex:()=>Id,base32hexpad:()=>Td,base32hexpadupper:()=>_d,base32hexupper:()=>Cd,base32pad:()=>Bd,base32padupper:()=>Ld,base32upper:()=>vd,base32z:()=>Dd});var Te=mt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),vd=mt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Bd=mt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Ld=mt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Id=mt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Cd=mt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Td=mt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),_d=mt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Dd=mt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gs={};st(Gs,{base36:()=>rn,base36upper:()=>Rd});var rn=Ce({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Rd=Ce({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var me={};st(me,{Digest:()=>Ze,create:()=>Yt,decode:()=>vr,equals:()=>Zs,hasCode:()=>Xd});var Od=Bf,Af=128,Pd=127,Ud=~Pd,Nd=Math.pow(2,31);function Bf(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Nd;)t[e++]=r&255|Af,r/=128;for(;r&Ud;)t[e++]=r&255|Af,r>>>=7;return t[e]=r|0,Bf.bytes=e-n+1,t}var kd=Ys,Md=128,vf=127;function Ys(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ys.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&vf)<<o:(i&vf)*Math.pow(2,o),o+=7}while(i>=Md);return Ys.bytes=s-n,e}var Kd=Math.pow(2,7),Fd=Math.pow(2,14),Hd=Math.pow(2,21),zd=Math.pow(2,28),Vd=Math.pow(2,35),qd=Math.pow(2,42),$d=Math.pow(2,49),jd=Math.pow(2,56),Wd=Math.pow(2,63),Gd=function(r){return r<Kd?1:r<Fd?2:r<Hd?3:r<zd?4:r<Vd?5:r<qd?6:r<$d?7:r<jd?8:r<Wd?9:10},Yd={encode:Od,decode:kd,encodingLength:Gd},Zd=Yd,nn=Zd;function on(r,t=0){let e=nn.decode(r,t),n=nn.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[e,n]}function Sr(r,t,e=0){return nn.encode(r,t,e),t}function Ar(r){return nn.encodingLength(r)}function Yt(r,t){let e=t.byteLength,n=Ar(r),o=n+Ar(e),s=new Uint8Array(o+e);return Sr(r,s,0),Sr(e,s,n),s.set(t,o),new Ze(r,e,t,s)}function vr(r){let t=Vt(r),[e,n]=on(t),[o,s]=on(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ze(e,o,i,t)}function Zs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&gf(r.bytes,e.bytes)}}var Ze=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=Ye(n),this.bytes=Ye(o)}};function Xd(r,t){return r.code===t}function Lf(r,t){let{bytes:e,version:n}=r;return n===0?Jd(e,Xs(r),t??yt.encoder):tp(e,Xs(r),t??Te.encoder)}var If=new WeakMap;function Xs(r){let t=If.get(r);if(t==null){let e=new Map;return If.set(r,e),e}return t}var xt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=Ye(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==sn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ep)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Yt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Zs(t.multihash,n.multihash)}toString(t){return Lf(this,t)}toJSON(){return{"/":Lf(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Cf(n,o,s.bytes))}else if(e[rp]===!0){let{version:n,multihash:o,code:s}=e,i=vr(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==sn)throw new Error(`Version 0 CID must use dag-pb (code: ${sn}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Cf(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,sn,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Vt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Ze(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,d]=on(t.subarray(e));return e+=d,u},o=n(),s=sn;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,h=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:f}}static parse(t,e){let[n,o]=Qd(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xs(s).set(n,t),s}};function Qd(r,t){switch(r[0]){case"Q":{let e=t??yt;return[yt.prefix,e.decode(`${yt.prefix}${r}`)]}case yt.prefix:{let e=t??yt;return[yt.prefix,e.decode(r)]}case Te.prefix:{let e=t??Te;return[Te.prefix,e.decode(r)]}case rn.prefix:{let e=t??rn;return[rn.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Jd(r,t,e){let{prefix:n}=e;if(n!==yt.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function tp(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var sn=112,ep=18;function Cf(r,t,e){let n=Ar(r),o=n+Ar(t),s=new Uint8Array(o+e.byteLength);return Sr(r,s,0),Sr(t,s,n),s.set(e,o),s}var rp=Symbol.for("@ipld/js-cid/CID");var Qs={};st(Qs,{identity:()=>Zt});var Tf=0,np="identity",_f=Vt;function op(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Yt(Tf,_f(r))}var Zt={code:Tf,name:np,encode:_f,digest:op};function Et(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function sp(r){return r.buffer instanceof ArrayBuffer}function Bt(r){return sp(r)?r:r.slice()}async function Df(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Bt(t),Bt(e.subarray()));return n?.signal?.throwIfAborted(),s}function re(r=0){return new Uint8Array(r)}function Ct(r=0){return new Uint8Array(r)}function ip(r){return r?.buffer instanceof ArrayBuffer}function Js(r){if(ip(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function ne(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=Ct(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return Js(e)}var Of=Symbol.for("@achingbrain/uint8arraylist");function Rf(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function ho(r){return!!r?.[Of]}var dt=class r{bufs;length;[Of]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(ho(n)){e+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(ho(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Rf(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Rf(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(ho(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return ne(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ne(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,h=e>a&&e<=c;if(f&&h){if(t===a&&e===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(h){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!ho(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,h;for(let u=e;u<=c;u+=h){h=0;for(let d=f;d>=0;d--){let p=this.get(u+d);if(n[d]!==p){h=Math.max(1,d-a[p]);break}}if(h===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=Ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=re(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=re(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=re(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=Ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=re(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=re(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=re(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=re(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=re(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Et(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var ti={};st(ti,{base10:()=>ap});var ap=Ce({prefix:"9",name:"base10",alphabet:"0123456789"});var ei={};st(ei,{base16:()=>cp,base16upper:()=>fp});var cp=mt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),fp=mt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ri={};st(ri,{base2:()=>up});var up=mt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ni={};st(ni,{base256emoji:()=>mp});var Pf=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}"),hp=Pf.reduce((r,t,e)=>(r[e]=t,r),[]),lp=Pf.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function dp(r){return r.reduce((t,e)=>(t+=hp[e],t),"")}function pp(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=lp[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var mp=Er({prefix:"\u{1F680}",name:"base256emoji",encode:dp,decode:pp});var si={};st(si,{base64:()=>yp,base64pad:()=>gp,base64url:()=>oi,base64urlpad:()=>bp});var yp=mt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),gp=mt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oi=mt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bp=mt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ii={};st(ii,{base8:()=>wp});var wp=mt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ai={};st(ai,{identity:()=>xp});var xp=Er({prefix:"\0",name:"identity",encode:r=>wf(Vt(r)),decode:r=>Vt(bf(r))});var aw=new TextEncoder,cw=new TextDecoder;var ui={};st(ui,{sha256:()=>an,sha512:()=>vp});var Ap=20;function fi({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new ci(r,t,e,n,o)}var ci=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Ap,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Uf(n,this.code,e?.truncate):n.then(o=>Uf(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Uf(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Yt(t,r)}function kf(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var an=fi({name:"sha2-256",code:18,encode:kf("SHA-256")}),vp=fi({name:"sha2-512",code:19,encode:kf("SHA-512")});var Xe={...ai,...ri,...ii,...ti,...ei,...Ws,...Gs,...js,...si,...ni},xw={...ui,...Qs};function Kf(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Mf=Kf("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),hi=Kf("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Ct(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Bp={utf8:Mf,"utf-8":Mf,hex:Xe.base16,latin1:hi,ascii:hi,binary:hi,...Xe},lo=Bp;function it(r,t="utf8"){let e=lo[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function X(r,t="utf8"){let e=lo[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Lp=parseInt("11111",2),li=parseInt("10000000",2),Ip=parseInt("01111111",2),Ff={0:cn,1:cn,2:Cp,3:Dp,4:Rp,5:_p,6:Tp,16:cn,22:cn,48:cn};function ye(r,t={offset:0}){let e=r[t.offset]&Lp;if(t.offset++,Ff[e]!=null)return Ff[e](r,t);throw new Error("No decoder for tag "+e)}function fn(r,t){let e=0;if((r[t.offset]&li)===li){let n=r[t.offset]&Ip,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=r.byteLength)throw new Error("invalid DER element length");o+=r[t.offset].toString(16).padStart(2,"0")}e=parseInt(o,16)}else e=r[t.offset],t.offset++;if(!Number.isInteger(e)||e<0||e>r.byteLength-t.offset)throw new Error("invalid DER element length");return e}function cn(r,t){fn(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=ye(r,t);if(n===null)break;e.push(n)}return e}function Cp(r,t){let e=fn(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Tp(r,t){let e=fn(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let h=0;for(let u=0;u<c.length;u++)h+=c[u]<<u*7;a+=`.${h}`,c=[]}}return a}function _p(r,t){return t.offset++,null}function Dp(r,t){let e=fn(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Rp(r,t){let e=fn(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Op(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new dt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function di(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Op(r.byteLength);return new dt(Uint8Array.from([t.byteLength|li]),t)}function Kt(r){let t=new dt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new dt(Uint8Array.from([2]),di(t),t)}function po(r){let t=Uint8Array.from([0]),e=new dt(t,r);return new dt(Uint8Array.from([3]),di(e),e)}function _e(r,t=48){let e=new dt;for(let n of r)e.append(n);return new dt(Uint8Array.from([t]),di(e),e)}var Pp=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Up=Uint8Array.from([6,5,43,129,4,0,34]),Np=Uint8Array.from([6,5,43,129,4,0,35]),kp={ext:!0,kty:"EC",crv:"P-256"},Mp={ext:!0,kty:"EC",crv:"P-384"},Kp={ext:!0,kty:"EC",crv:"P-521"},pi=32,mi=48,yi=66;function gi(r){let t=ye(r);return Hf(t)}function Hf(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===pi*2+1)return n=X(t.subarray(e,e+pi),"base64url"),o=X(t.subarray(e+pi),"base64url"),new Br({...kp,key_ops:["verify"],x:n,y:o});if(t.byteLength===mi*2+1)return n=X(t.subarray(e,e+mi),"base64url"),o=X(t.subarray(e+mi),"base64url"),new Br({...Mp,key_ops:["verify"],x:n,y:o});if(t.byteLength===yi*2+1)return n=X(t.subarray(e,e+yi),"base64url"),o=X(t.subarray(e+yi),"base64url"),new Br({...Kp,key_ops:["verify"],x:n,y:o});throw new rt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function zf(r){return _e([Kt(Uint8Array.from([1])),_e([Fp(r.crv)],160),_e([po(new dt(Uint8Array.from([4]),it(r.x??"","base64url"),it(r.y??"","base64url")))],161)]).subarray()}function Fp(r){if(r==="P-256")return Pp;if(r==="P-384")return Up;if(r==="P-521")return Np;throw new rt(`Invalid curve ${r}`)}var Br=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=zf(this.jwk)),this._raw}toMultihash(){return Zt.digest(De(this))}toCID(){return xt.createV1(114,this.toMultihash())}toString(){return yt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Et(this.raw,t.raw)}async verify(t,e,n){return Df(this.jwk,e,t,n)}};var mo=BigInt(4294967295),Vf=BigInt(32);function Hp(r,t=!1){return t?{h:Number(r&mo),l:Number(r>>Vf&mo)}:{h:Number(r>>Vf&mo)|0,l:Number(r&mo)|0}}function qf(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Hp(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var zp=r=>r/2**32|0,Vp=r=>r>>>0;function $f(r,t,e,n){let o=zp(e),s=Vp(e);r.setUint32(t,n?s:o,n),r.setUint32(t+4,n?o:s,n)}var bi=(r,t,e)=>r>>>e,wi=(r,t,e)=>r<<32-e|t>>>e,Qe=(r,t,e)=>r>>>e|t<<32-e,Je=(r,t,e)=>r<<32-e|t>>>e,un=(r,t,e)=>r<<64-e|t>>>e-32,hn=(r,t,e)=>r>>>e-32|t<<64-e;function oe(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var jf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Wf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Gf=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Yf=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Zf=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Xf=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;function yo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}var xi=r=>r?`"${r}" `:"";function Xt(r,t=""){if(typeof r!="number")throw new TypeError(xi(t)+"expected number, got "+typeof r);if(!Number.isSafeInteger(r)||r<0)throw new RangeError(xi(t)+"expected integer >= 0, got "+r);return r}function Nt(r,t,e=""){if(yo(r)&&(t===void 0||r.length===t))return r;t!==void 0&&Xt(t,"length");let n=yo(r),o=t!==void 0?` of length ${t}`:"",s=n?`length=${r.length}`:`type=${typeof r}`,i=xi(e)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function tr(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Xt(r.outputLen),Xt(r.blockLen),r.outputLen<1||r.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var $p=(r,t)=>{if(r===null||typeof r!="object"||Array.isArray(r))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof r)},Qf=(r,t)=>{$p(r,t);let e=Object.getPrototypeOf(r);if(e!==Object.prototype&&e!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(r,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function Lr(r,t=!0){if(r.destroyed)throw new Error("hash was destroyed");if(t&&r.finished)throw new Error("digest() was already called")}function go(r,t){Nt(r,void 0,"output");let e=t.outputLen;if(!(r.length>=e))throw new RangeError('"output" expected length >= '+e)}function qt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function bo(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Qt(r,t){return r<<32-t|r>>>t}var tu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",jp=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function wo(r){if(Nt(r),tu)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=jp[r[e]];return t}function Jf(r){return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void 0}function xo(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(tu)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Jf(r.charCodeAt(s)),a=Jf(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ei(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Nt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Wp(r,t,e="opts"){return Qf(r,"defaults"),t!==void 0&&Qf(t,e),Object.assign(Object.create(null),r,t)}function Si(r,t={}){if(typeof r!="function")throw new TypeError('"hashCons" expected function, got type='+typeof r);t=Wp({},t,"info");let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function eu(r=32){Xt(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var Ai=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ru(r,t,e){return r&t^~r&e}function nu(r,t,e){return r&t^r&e^t&e}var ln=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=bo(this.buffer)}update(t){Lr(this),Nt(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let f=bo(t);for(;o<=s-a;a+=o)this.process(f,a);i=!0;continue}n.set(a===0&&c===s?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(e,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){Lr(this),go(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,e.fill(0,i),this.padOffset>o-i&&(this.process(n,0),e.fill(0)),$f(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===e?n:bo(t),c=this.outputLen,f=c/4,h=this.get();if(c%4||f>h.length)throw new Error("invalid outputLen");for(let u=0;u<f;u++)a.setUint32(4*u,h[u],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:e,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(e),t}clone(){return this._cloneInto()}},ou=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var su=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Gp=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]),Re=new Uint32Array(64),vi=class extends ln{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,e){super(64,t,8,!1),this.A=e[0]|0,this.B=e[1]|0,this.C=e[2]|0,this.D=e[3]|0,this.E=e[4]|0,this.F=e[5]|0,this.G=e[6]|0,this.H=e[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,e){for(let u=0;u<16;u++,e+=4)Re[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let d=Re[u-15],p=Re[u-2],m=Qt(d,7)^Qt(d,18)^d>>>3,g=Qt(p,17)^Qt(p,19)^p>>>10;Re[u]=g+Re[u-7]+m+Re[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:h}=this;for(let u=0;u<64;u++){let d=Qt(a,6)^Qt(a,11)^Qt(a,25),p=h+d+ru(a,c,f)+Gp[u]+Re[u]|0,g=(Qt(n,2)^Qt(n,13)^Qt(n,22))+nu(n,o,s)|0;h=f,f=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,h=h+this.H|0,this.set(n,o,s,i,a,c,f,h)}roundClean(){qt(Re)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),qt(this.buffer)}},Bi=class extends vi{constructor(){super(32,ou)}};var iu=qf(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Yp=iu[0],Zp=iu[1],Oe=new Uint32Array(80),Pe=new Uint32Array(80),Li=class extends ln{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,e){super(128,t,16,!1),this.Ah=e[0]|0,this.Al=e[1]|0,this.Bh=e[2]|0,this.Bl=e[3]|0,this.Ch=e[4]|0,this.Cl=e[5]|0,this.Dh=e[6]|0,this.Dl=e[7]|0,this.Eh=e[8]|0,this.El=e[9]|0,this.Fh=e[10]|0,this.Fl=e[11]|0,this.Gh=e[12]|0,this.Gl=e[13]|0,this.Hh=e[14]|0,this.Hl=e[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:h,Fh:u,Fl:d,Gh:p,Gl:m,Hh:g,Hl:y}=this;return[t,e,n,o,s,i,a,c,f,h,u,d,p,m,g,y]}set(t,e,n,o,s,i,a,c,f,h,u,d,p,m,g,y){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=h|0,this.Fh=u|0,this.Fl=d|0,this.Gh=p|0,this.Gl=m|0,this.Hh=g|0,this.Hl=y|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,e){for(let w=0;w<16;w++,e+=4)Oe[w]=t.getUint32(e),Pe[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let v=Oe[w-15]|0,B=Pe[w-15]|0,D=Qe(v,B,1)^Qe(v,B,8)^bi(v,B,7),P=Je(v,B,1)^Je(v,B,8)^wi(v,B,7),R=Oe[w-2]|0,L=Pe[w-2]|0,O=Qe(R,L,19)^un(R,L,61)^bi(R,L,6),F=Je(R,L,19)^hn(R,L,61)^wi(R,L,6),K=Gf(P,F,Pe[w-7],Pe[w-16]),q=Yf(K,D,O,Oe[w-7],Oe[w-16]);Oe[w]=q|0,Pe[w]=K|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:h,Eh:u,El:d,Fh:p,Fl:m,Gh:g,Gl:y,Hh:x,Hl:E}=this;for(let w=0;w<80;w++){let v=Qe(u,d,14)^Qe(u,d,18)^un(u,d,41),B=Je(u,d,14)^Je(u,d,18)^hn(u,d,41),D=u&p^~u&g,P=d&m^~d&y,R=Zf(E,B,P,Zp[w],Pe[w]),L=Xf(R,x,v,D,Yp[w],Oe[w]),O=R|0,F=Qe(n,o,28)^un(n,o,34)^un(n,o,39),K=Je(n,o,28)^hn(n,o,34)^hn(n,o,39),q=n&s^n&a^s&a,C=o&i^o&c^i&c;x=g|0,E=y|0,g=p|0,y=m|0,p=u|0,m=d|0,{h:u,l:d}=oe(f|0,h|0,L|0,O|0),f=a|0,h=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let N=jf(O,K,C);n=Wf(N,L,F,q),o=N|0}({h:n,l:o}=oe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=oe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=oe(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:h}=oe(this.Dh|0,this.Dl|0,f|0,h|0),{h:u,l:d}=oe(this.Eh|0,this.El|0,u|0,d|0),{h:p,l:m}=oe(this.Fh|0,this.Fl|0,p|0,m|0),{h:g,l:y}=oe(this.Gh|0,this.Gl|0,g|0,y|0),{h:x,l:E}=oe(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,o,s,i,a,c,f,h,u,d,p,m,g,y,x,E)}roundClean(){qt(Oe,Pe)}destroy(){this.destroyed=!0,qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ii=class extends Li{constructor(){super(64,su)}};var se=Si(()=>new Bi,Ai(1));var Ci=Si(()=>new Ii,Ai(3));function So(r,t,e=()=>{}){if(!Array.isArray(r))throw new TypeError(`"${t}" expected array, got type=${typeof r}`);for(let n=0;n<r.length;n++)e(r[n],`${t}[${n}]`);return r}var Y=(r,t,e)=>Nt(r,t,e),Ti=Xt;function cu(r,t=""){if(typeof r!="string"){let e=t&&`"${t}" `;throw new TypeError(e+"expected string, got type="+typeof r)}return r}function Ue(r,t="object"){if(r===null||typeof r!="object"||Array.isArray(r))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof r}`);return r}function er(r,t){if(typeof r!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof r}`);return r}var dn=wo,$t=(...r)=>Ei(...r),Ir=r=>xo(r),ke=yo,ge=r=>eu(r),Eo=BigInt(0),au=BigInt(1),Xp=r=>r?`"${r}" `:"";function Ft(r,t=""){if(typeof r!="boolean")throw new TypeError(Xp(t)+"expected boolean, got type="+typeof r);return r}function Ao(r){if(typeof r=="bigint"){if(!Ne(r))throw new RangeError("positive bigint expected, got "+r)}else Ti(r);return r}function be(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+r)}}function pn(r){let t=Ao(r).toString(16);return t.length&1?"0"+t:t}function fu(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?Eo:BigInt("0x"+r)}function ie(r){return fu(wo(r))}function ae(r){return fu(wo(Me(Nt(r)).reverse()))}function vo(r,t){if(Xt(t),t===0)throw new Error("zero output length is invalid");r=Ao(r);let e=t*2,n=r.toString(16);if(n.length>e)throw new RangeError("number is too large");return xo(n.padStart(e,"0"))}function mn(r,t){return vo(r,t).reverse()}function Me(r){return Uint8Array.from(Y(r))}function Ne(r){return typeof r=="bigint"&&Eo<=r}function _i(r,t,e){return Ne(r)&&Ne(t)&&Ne(e)&&t<=r&&r<e}function ce(r,t,e,n){if(!_i(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Cr(r){if(r<Eo)throw new Error("expected non-negative bigint, got "+r);return r===Eo?0:r.toString(2).length}var yn=r=>(be(r,"n"),(au<<BigInt(r))-au);function uu(r,t,e){if(Xt(r,"hashLen"),Xt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),h=0,u=()=>{c.fill(1),f.fill(0),h=0},d=(...y)=>e(f,$t(c,...y)),p=(y=o)=>{f=d(s,y),c=d(),y.length!==0&&(f=d(i,y),c=d())},m=()=>{if(h++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,x=[];for(;y<t;){c=d();let E=c.slice();x.push(E),y+=c.length}return $t(...x)};return(y,x)=>{u(),p(y);let E;for(;(E=x(m()))===void 0;)p();return u(),E}}function Tt(r,t={},e={},n="object"){Ue(r,n),Ue(t,"fields"),Ue(e,"optFields");function o(i,a,c){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,h=r[i];if(!Object.hasOwn(r,i)&&(c?h!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&h===void 0)return;let u=typeof h;if(u!==a||h===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${u}`)}let s=(i,a)=>Object.entries(i).forEach(([c,f])=>o(c,f,a));s(t,!1),s(e,!0)}var St=BigInt(0),J=BigInt(1),Ke=BigInt(2),du=BigInt(3),Di=BigInt(4),pu=BigInt(5),Qp=BigInt(7),mu=BigInt(8),Jp=BigInt(9),tm=BigInt(15),yu=BigInt(16),em=BigInt("0x10000000000000000");function et(r,t){if(t<=St)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=St?e:t+e}function gu(r,t,e){if(e<=J)throw new Error("pow: expected modulus > 1, got "+e);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<St)throw new Error("invalid exponent, negatives unsupported");if(t===St)return J;if(t===J)return r;let n=r%e;if(n<St&&(n+=e),t<em){let a=J;for(;t>St;)t&J&&(a=a*n%e),n=n*n%e,t>>=J;return a}let o=[];for(;t>St;)o.push(Number(t&tm)),t>>=Di;let s=new Array(16);s[0]=J,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%e;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%e,i=i*i%e,i=i*i%e,i=i*i%e;let c=o[a];c!==0&&(i=i*s[c]%e)}return i}function ft(r,t,e){if(e<=J)throw new Error("pow2: expected modulus > 1, got "+e);if(t<St)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >St;)n*=n,n%=e;return n}function hu(r,t){if(r===St)throw new Error("invert: expected non-zero number");if(t<=J)throw new Error("invert: expected modulus > 1, got "+t);let e=et(r,t),n=t,o=St,s=J;for(;e!==St;){let a=n/e,c=n-e*a,f=o-s*a;n=e,e=c,o=s,s=f}if(n!==J)throw new Error("invert: does not exist");return et(o,t)}function bu(r,t){if(t<=J)throw new Error("invertCt: expected prime modulus > 1, got "+t);let e=et(r,t);if(e===St)throw new Error("invertCt: expected non-zero number");let n=gu(e,t-Ke,t);if(et(e*n,t)!==J)throw new Error("invertCt: does not exist");return n}function Ri(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Oi(r,t){if((r&J)===St)throw new Error(t+": expected odd modulus, got "+r)}function wu(r,t){let e=r,n=(e.ORDER+J)/Di,o=e.pow(t,n);return Ri(e,o,t),o}function rm(r,t){let e=r,n=(e.ORDER-pu)/mu,o=e.mul(t,Ke),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,Ke),s),c=e.mul(i,e.sub(a,e.ONE));return Ri(e,c,t),c}function nm(r){let t=_r(r),e=xu(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Qp)/yu;return((a,c)=>{let f=a,h=f.pow(c,i),u=f.mul(h,n),d=f.mul(h,o),p=f.mul(h,s),m=f.eql(f.sqr(u),c),g=f.eql(f.sqr(d),c);h=f.cmov(h,u,m),u=f.cmov(p,d,g);let y=f.eql(f.sqr(u),c),x=f.cmov(h,u,y);return Ri(f,x,c),x})}function xu(r){if(r<du)throw new Error("sqrt is not defined for small field");Oi(r,"tonelliShanks");let t=r-J,e=0;for(;t%Ke===St;)t/=Ke,e++;let n=Ke,o=_r(r);for(;gn(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return wu;let s=o.pow(n,t),i=(t+J)/Ke;return function(c,f){let h=c;if(h.is0(f))return f;if(gn(h,f)!==1)throw new Error("Cannot find square root");let u=e,d=h.mul(h.ONE,s),p=h.pow(f,t),m=h.pow(f,i);for(;!h.eql(p,h.ONE);){if(h.is0(p))throw new Error("Cannot find square root: probably non-prime P");let g=1,y=h.sqr(p);for(;!h.eql(y,h.ONE);)if(g++,y=h.sqr(y),g===u)throw new Error("Cannot find square root");let x=J<<BigInt(u-g-1),E=h.pow(d,x);u=g,d=h.sqr(E),p=h.mul(p,d),m=h.mul(m,E)}return m}}function om(r){return Oi(r,"Fp.sqrt"),r%Di===du?wu:r%mu===pu?rm:r%yu===Jp?nm(r):xu(r)}var Eu=(r,t)=>(et(r,t)&J)===J,sm=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Tr(r){if(Ue(r,"field"),typeof r.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof r.ORDER);be(r.BYTES,"BYTES"),be(r.BITS,"BITS");for(let t of sm)er(r[t],"field."+t);if(r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=J)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function Lo(r,t,e=!1){Tr(r),So(t,"nums"),Ft(e,"passZero");let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function gn(r,t){Tr(r);let e=r;Oi(e.ORDER,"FpLegendre");let n=(e.ORDER-J)/Ke,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),a=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function im(r,t){if(t!==void 0&&Ti(t),r<=St)throw new Error("invalid n length: expected positive n, got "+r);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=Cr(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${e})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var lu=new WeakMap,Bo=class{ORDER;BITS;BYTES;isLE;ZERO=St;ONE=J;_lengths;_mod;constructor(t,e={}){if(t<=J)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=im(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return et(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return St<=t&&t<this.ORDER}is0(t){return t===St}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&J)===J}neg(t){return et(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return et(t*t,this.ORDER)}add(t,e){return et(t+e,this.ORDER)}sub(t,e){return et(t-e,this.ORDER)}mul(t,e){return et(t*e,this.ORDER)}pow(t,e){return gu(t,e,this.ORDER)}div(t,e){return et(t*hu(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return hu(t,this.ORDER)}sqrt(t){let e=lu.get(this);return e||lu.set(this,e=om(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?mn(t,this.BYTES):vo(t,this.BYTES)}fromBytes(t,e=!1){Y(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?ae(t):ie(t);if(a&&(c=et(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Lo(this,t,!0)}cmov(t,e,n){return Ft(n,"condition"),n?e:t}};function _r(r,t={}){return Object.freeze(Bo.prototype),new Bo(r,t)}function Su(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=J)throw new Error("field order must be greater than 1");let t=Cr(r-J);return Math.ceil(t/8)}function Io(r){let t=Su(r);return t+Math.ceil(t/2)}function Co(r,t,e=!1){Y(r);let n=r.length,o=Su(t),s=Math.max(Io(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ae(r):ie(r),a=et(i,t-J)+J;return e?mn(a,o):vo(a,o)}var Ni=BigInt(0),bn=BigInt(1),am=BigInt(4),Pi=16,Au=128,cm=5,vu=2**31;function Fe(r){let t=r;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof r);er(t.fromAffine,"Point.fromAffine"),er(t.fromBytes,"Point.fromBytes"),er(t.fromHex,"Point.fromHex"),Ue(t.BASE,"Point.BASE"),Ue(t.ZERO,"Point.ZERO"),Tr(t.Fp),Tr(t.Fn)}function To(r,t){Fe(r),Lu(t,r);let e=Lo(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function fm(r,t,e=1){if(!Number.isSafeInteger(r)||r<e||r>t)throw new Error("invalid window size, expected ["+e+".."+t+"], got W="+r)}function um(r,t){let e=r*(4*t+128);if(e>vu)throw new Error("invalid window size: table would need ~"+Math.ceil(e/2**20)+" MiB, max "+vu/2**20+" MiB")}function ki(r,t){if(r!==void 0){er(r,"randomBytes");try{let e=r(t);if(!ke(e)||e.length!==t)return}catch{return}return r}}function Lu(r,t){So(r,"points"),r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function hm(r,t,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((n,o)=>{if(!(e===void 0?t.isValid(n):Ne(n)&&n<e))throw new Error("invalid scalar at index "+o)})}var Iu=new WeakMap;function Ui(r){return Iu.get(r)||1}function lm(r,t){let e=r.double(),n=[r];for(let o=1;o<t;o++)n.push(n[o-1].add(e));return n}function dm(r,t){let e=2**t,n=e/2,o=BigInt(e-1),s=[];for(;r>Ni;){let i=0;r&bn&&(i=Number(r&o),i>=n&&(i-=e),r-=BigInt(i)),s.push(i),r>>=bn}return s}function pm(r,t,e){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),a=[];for(let c=0;c<e;c++){let f=Number(r&s);r>>=i,f>o&&(f-=n,r+=bn),a.push(f)}if(r!==Ni)throw new Error("invalid wnaf");return a}function mm(r,t,e){let n=0;for(let s of e)n=Math.max(n,s.length);let o=r;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<e.length;i++){let a=e[i][s];if(a){let c=t[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Dr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,e){Fe(t),this.randomBytes=ki(e,Pi),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,e,n){let o=Math.ceil(n/e)+1,s=2**(e-1),i=[],a=t;for(let c=0;c<o;c++){let f=a;for(let h=0;h<s;h++)i.push(f),f=f.add(a);a=i[i.length-1].double()}return{W:e,bits:n,windows:o,comp:i}}wnafCachedCT(t,e){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=pm(e,n,o),c=this.ZERO,f=this.BASE;for(let h=0;h<o;h++){let u=a[h],d=h*i,p=Math.abs(u)-1,m=s[d];for(let y=1;y<i;y++)m=y===p?s[d+y]:m;let g=m.negate();u===0?f=f.add(s[d]):c=c.add(u<0?g:m)}return{p:c,f}}getWnafPrecomputes(t,e,n,o){let s=this.wnafPrecomputes.get(e),i=s?.find(a=>a.W===t&&a.bits===n);return i||(i=this.buildWnafTable(e,t,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(e,s)),s.push(i)),i}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,e){if(this.assertPoint(t),!_i(e,bn,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,e,n,o){let s=Ui(t);return s===1?this.fixedWindowCT(t,e,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),e)}mulCT(t,e,n){return this.validateMulInput(t,e),this.runCT(t,e,this.bits,n)}mulCTBlinded(t,e,n){if(this.validateMulInput(t,e),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Au,s=this.randomBytes(Pi);if(!ke(s)||s.length!==Pi)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=e+ie(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,e,n){let o=cm,s=1<<o,i=yn(o),a=new Array(s);a[0]=this.ZERO;for(let h=1;h<s;h++)a[h]=a[h-1].add(t);let c=Math.ceil(n/o),f=this.ZERO;for(let h=c-1;h>=0;h--){if(h!==c-1)for(let p=0;p<o;p++)f=f.double();let u=Number(e>>BigInt(h*o)&i),d=a[0];for(let p=1;p<s;p++)d=p===u?a[p]:d;f=f.add(d)}return{p:f,f}}shouldBlind(t,e){return this.randomBytes===void 0?!1:e===bn?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,e,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,e,o):this.mulCT(t,e,o)}mulUnsafe(t,e,n){if(this.assertPoint(t),!Ne(e))throw new Error("invalid scalar");let o=Ui(t);if(o===1||e>=this.Point.Fn.ORDER)return _o(this.Point,[t],[e],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,e).p}setWindowSize(t,e){this.assertPoint(t),fm(e,this.bits);let n=Math.ceil((this.bits+Au)/e)+1;um(n*2**(e-1),this.Point.Fp.BYTES),Iu.set(t,e),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return Ui(t)!==1}};function _o(r,t,e,n=!1){if(Fe(r),Lu(t,r),Ft(n,"allowOversized"),hm(e,r.Fn,n?r.Fn.ORDER**am:void 0),t.length!==e.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>lm(i,4)),s=e.map(i=>dm(i,4));return mm(r.ZERO,o,s)}function Bu(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Tr(t),t}else return _r(r,{isLE:e})}function Do(r,t,e={},n){if(r!=="weierstrass"&&r!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);Tt(e);for(let c of["p","n","h"]){let f=t[c];if(!(Ne(f)&&f!==Ni))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Bu(t.p,e.Fp,n),s=Bu(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Rr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Ro=BigInt(0),Oo=BigInt(1),Po=BigInt(2),ym=BigInt(4),Cu=BigInt(8);function gm(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Tu(r,t={}){Tt(t,{},{},"extraOpts");let e=t,n=Do("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(gn(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(gn(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Tt(e,{},{uvRatio:"function",randomBytes:"function"});let c=e.randomBytes===void 0?ge:e.randomBytes,f=Po<<BigInt(o.BYTES*8)-Oo;function h(E){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(E)}let u=e.uvRatio===void 0?(E,w)=>{try{return{isValid:!0,value:o.sqrt(o.div(E,w))}}catch{return{isValid:!1,value:Ro}}}:e.uvRatio;if(!gm(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=o.eql(i.a,o.neg(o.ONE))?E=>o.neg(E):o.eql(i.a,o.ONE)?E=>E:E=>o.mul(i.a,E);function p(E,w,v=!1){let B=v?Oo:Ro;return ce("coordinate "+E,w,B,f),w}function m(E){if(!(E instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new g(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(w,v,B,D){this.X=p("x",w),this.Y=p("y",v),this.Z=p("z",B,!0),this.T=p("t",D),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof g)throw new Error("extended point not allowed");let{x:v,y:B}=w||{};return p("x",v),p("y",B),new g(v,B,o.ONE,o.mul(v,B))}static fromBytes(w,v=!1){let B=o.BYTES,{a:D,d:P}=i;w=Me(Y(w,B,"point")),Ft(v,"zip215");let R=Me(w),L=w[B-1];R[B-1]=L&-129;let O=ae(R),F=v?f:o.ORDER;ce("point.y",O,Ro,F);let K=o.sqr(O),q=o.sub(K,o.ONE),C=o.sub(o.mulN(P,K),D),{isValid:N,value:T}=u(q,C);if(!N)throw new Error("bad point: invalid y coordinate");let I=h(T),H=(L&128)!==0;if(!v&&o.is0(T)&&H)throw new Error("bad point: x=0 and x_0=1");return H!==I&&(T=o.neg(T)),g.fromAffine({x:T,y:O})}static fromHex(w,v=!1){return g.fromBytes(Ir(w),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=6,v=!0){return x.setWindowSize(this,w),v||this.multiply(Po),this}assertValidity(){let w=this,{a:v,d:B}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:D,Y:P,Z:R,T:L}=w,O=o.sqr(D),F=o.sqr(P),K=o.sqr(R),q=o.sqr(K),C=o.mul(O,v),N=o.mul(o.add(C,F),K),T=o.add(q,o.mul(B,o.mul(O,F)));if(!o.eql(N,T))throw new Error("bad point: equation left != right (1)");let I=o.mul(D,P),H=o.mul(R,L);if(!o.eql(I,H))throw new Error("bad point: equation left != right (2)")}equals(w){m(w);let{X:v,Y:B,Z:D}=this,{X:P,Y:R,Z:L}=w,O=o.mul(v,L),F=o.mul(P,D),K=o.mul(B,L),q=o.mul(R,D);return o.eql(O,F)&&o.eql(K,q)}is0(){return this.equals(g.ZERO)}negate(){return new g(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:w,Y:v,Z:B}=this,D=o.sqr(w),P=o.sqr(v),R=o.mul(o.sqr(B),Po),L=d(D),O=o.addN(w,v),F=o.sub(o.subN(o.sqr(O),D),P),K=o.addN(L,P),q=o.subN(K,R),C=o.subN(L,P),N=o.mul(F,q),T=o.mul(K,C),I=o.mul(F,C),H=o.mul(q,K);return new g(N,T,H,I)}add(w){m(w);let{d:v}=i,{X:B,Y:D,Z:P,T:R}=this,{X:L,Y:O,Z:F,T:K}=w,q=o.mul(B,L),C=o.mul(D,O),N=o.mul(o.mulN(R,v),K),T=o.mul(P,F),I=o.sub(o.subN(o.mulN(o.addN(B,D),o.addN(L,O)),q),C),H=o.subN(T,N),_=o.addN(T,N),S=o.sub(C,d(q)),l=o.mul(I,H),b=o.mul(_,S),A=o.mul(I,S),U=o.mul(H,_);return new g(l,b,U,A)}subtract(w){return m(w),this.add(w.negate())}multiply(w){if(!s.isValidNot0(w))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:v,f:B}=x.mulSecret(this,w,a,y);return y([v,B])[0]}multiplyUnsafe(w){if(!s.isValid(w))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return w===Ro?g.ZERO:this.is0()||w===Oo?this:x.mulUnsafe(this,w,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(w){let v=this,B=w;if(B!=null&&typeof B!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof B);let{X:D,Y:P,Z:R}=v,L=v.is0();B==null&&(B=L?o.create(Cu):o.inv(R));let O=o.mul(D,B),F=o.mul(P,B),K=o.mul(R,B);if(L)return{x:o.ZERO,y:o.ONE};if(!o.eql(K,o.ONE))throw new Error("invZ was invalid");return{x:O,y:F}}clearCofactor(){return a===Oo?this:a===Po?this.double():a===ym?this.double().double():a===Cu?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:w,y:v}=this.toAffine(),B=o.toBytes(v);return B[B.length-1]|=h(w)?128:0,B}toHex(){return dn(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=E=>To(g,E),x=new Dr(g,c);return x.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function _u(r,t,e={}){if(Fe(r),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;Tt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,f=n.outputLen,h=2*a.BYTES;if(f!==void 0&&(be(f,"hash.outputLen"),f!==h))throw new Error(`hash.outputLen must be ${h}, got ${f}`);let u=o.randomBytes===void 0?ge:o.randomBytes,d=o.toMontgomery,p=o.toMontgomerySecret,m=o.adjustScalarBytes===void 0?C=>C:o.adjustScalarBytes,g=o.domain===void 0?(C,N,T)=>{if(Ft(T,"phflag"),N.length||T)throw new Error("Contexts/pre-hash are not supported");return C}:o.domain;function y(C){return c.create(ae(C))}function x(C){let N=L.secretKey;Y(C,L.secretKey,"secretKey");let T=Y(n(C),2*N,"hashedSecretKey"),I=m(T.slice(0,N)),H=T.slice(N,2*N),_=y(I);return{head:I,prefix:H,scalar:_}}function E(C){let{head:N,prefix:T,scalar:I}=x(C),H=i.multiply(I),_=H.toBytes();return{head:N,prefix:T,scalar:I,point:H,pointBytes:_}}function w(C){return E(C).pointBytes}function v(C=Uint8Array.of(),...N){let T=$t(...N);return y(n(g(T,Y(C,void 0,"context"),!!s)))}function B(C,N,T={}){Tt(T,{},{},"options"),C=Me(Y(C,void 0,"message")),s&&(C=s(C));let{prefix:I,scalar:H,pointBytes:_}=E(N),S=v(T.context,I,C),l=i.multiply(S).toBytes(),b=v(T.context,l,_,C),A=c.create(S+b*H);if(!c.isValid(A))throw new Error("sign failed: invalid s");let U=$t(l,c.toBytes(A));return Y(U,L.signature,"result")}let D={zip215:o.zip215};function P(C,N,T,I=D){Tt(I);let{context:H}=I,_=I.zip215===void 0?!!D.zip215:I.zip215,S=L.signature;C=Y(C,S,"signature"),N=Y(N,void 0,"message"),T=Y(T,L.publicKey,"publicKey"),_!==void 0&&Ft(_,"zip215"),s&&(N=s(N));let l=S/2,b=C.subarray(0,l),A=ae(C.subarray(l,S)),U,k,M;try{U=r.fromBytes(T,_),k=r.fromBytes(b,_),M=i.multiplyUnsafe(A)}catch{return!1}if(!_&&U.isSmallOrder())return!1;let z=v(H,b,T,N);return k.add(U.multiplyUnsafe(z)).subtract(M).clearCofactor().is0()}let R=a.BYTES,L={secretKey:R,publicKey:R,signature:2*R,seed:R};function O(C){return C=C===void 0?u(L.seed):C,Y(C,L.seed,"seed")}function F(C){return ke(C)&&C.length===L.secretKey}function K(C,N){try{return!!r.fromBytes(C,N===void 0?D.zip215:N)}catch{return!1}}let q={getExtendedPublicKey:E,randomSecretKey:O,isValidSecretKey:F,isValidPublicKey:K,toMontgomery(C){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(r.fromBytes(C))},toMontgomerySecret(C){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(C)}};return Object.freeze(L),Object.freeze(q),Object.freeze({keygen:Rr(O,w),getPublicKey:w,sign:B,verify:P,utils:q,Point:r,lengths:L})}var rr=BigInt(0),jt=BigInt(1),Uo=BigInt(2);function Du(r,t){return r+t-(t>>jt<<jt)}function bm(r){let t=BigInt(6)*r;return(e,n,o)=>{let s=n+o,a=((t+o-n)*e+n)%r;return{x_2:a,x_3:s-a}}}function wm(r){return Tt(r,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function",scalarMultBase:"function"}),Object.freeze({...r})}function Ru(r){let t=wm(r),{P:e,type:n,adjustScalarBytes:o,powPminus2:s,randomBytes:i}=t,a=t.scalarMultBase,c=n==="x25519";if(!c&&n!=="x448")throw new Error("invalid type");let f=i===void 0?ge:i,h=c?255:448,u=bm(e),d=c?32:56,p=BigInt(c?9:5),m=BigInt(c?121665:39081),g=c?Uo**BigInt(254):Uo**BigInt(447),y=c?BigInt(8)*(Uo**BigInt(251)-jt):BigInt(4)*(Uo**BigInt(445)-jt),x=g+y+jt,E=T=>et(T,e),w=v(p);function v(T){return mn(E(T),d)}function B(T){let I=Me(Y(T,d,"uCoordinate"));return c&&(I[31]&=127),E(ae(I))}function D(T){return ae(o(Me(Y(T,d,"scalar"))))}let P=new Set(c?[rr,jt,e-jt,BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")]:[rr,jt,e-jt]);function R(T,I){let H=B(I);if(P.has(H))throw new Error("invalid private or public key received");let _=K(H,D(T));if(_===rr)throw new Error("invalid private or public key received");return v(_)}function L(T){if(a===void 0)return R(T,w);let I=D(T);ce("scalar",I,g,x);let H=E(a(I));if(H===rr)throw new Error("invalid private or public key received");return v(H)}let O=L,F=R;function K(T,I){ce("u",T,rr,e),ce("scalar",I,g,x);let H=I,_=T,S=jt,l=rr,b=T,A=jt,U=H^H>>jt;for(let z=BigInt(h-1);z>=rr;z--){let V=Du(e,U>>z);({x_2:S,x_3:b}=u(V,S,b)),{x_2:l,x_3:A}=u(V,l,A);let j=S+l,W=E(j*j),ct=S-l,ot=E(ct*ct),bt=W-ot,Mt=b+A,at=b-A,lt=E(at*j),yr=E(Mt*ct),en=lt+yr,Le=lt-yr;b=E(en*en),A=E(_*E(Le*Le)),S=E(W*ot),l=E(bt*(W+E(m*bt)))}let k=Du(e,H);({x_2:S,x_3:b}=u(k,S,b)),{x_2:l,x_3:A}=u(k,l,A);let M=s(l);return E(S*M)}let q={secretKey:d,publicKey:d,seed:d},C=T=>(T=T===void 0?f(d):T,Y(T,q.seed,"seed"),T),N={randomSecretKey:C};return Object.freeze(q),Object.freeze(N),Object.freeze({keygen:Rr(C,O),getSharedSecret:F,getPublicKey:O,scalarMult:R,scalarMultBase:L,utils:N,GuBytes:w.slice(),lengths:q})}var Ou=BigInt(0),Mi=BigInt(1),Pu=BigInt(2),xm=BigInt(3),Em=BigInt(5),Sm=BigInt(8),No=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Am={p:No,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Sm,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ku(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=No,a=r*r%s*r%s,c=ft(a,Pu,s)*a%s,f=ft(c,Mi,s)*r%s,h=ft(f,Em,s)*f%s,u=ft(h,t,s)*h%s,d=ft(u,e,s)*u%s,p=ft(d,n,s)*d%s,m=ft(p,o,s)*p%s,g=ft(m,o,s)*p%s,y=ft(g,t,s)*h%s;return{pow_p_5_8:ft(y,Pu,s)*r%s,b2:a}}function Ki(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Uu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function vm(r,t){let e=No,n=et(t*t*t,e),o=et(n*n*t,e),s=ku(r*o).pow_p_5_8,i=et(r*n*s,e),a=et(t*i*i,e),c=i,f=et(i*Uu,e),h=a===r,u=a===et(-r,e),d=a===et(-r*Uu,e);return h&&(i=c),(u||d)&&(i=f),Eu(i,e)&&(i=et(-i,e)),{isValid:h||u,value:i}}var wn=Tu(Am,{uvRatio:vm}),Nu=wn.Fp;function Bm(r){let{y:t}=r;return Nu.toBytes(Nu.div(Mi+t,Mi-t))}function Lm(r){let t=wn.Fp.BYTES;return Nt(r,t),Ki(Ci(r.subarray(0,t))).subarray(0,t)}function Im(r){return _u(wn,Ci,Object.assign({adjustScalarBytes:Ki,toMontgomery:Bm,toMontgomerySecret:Lm,zip215:!0},r))}var Mu=Im({});var xn=(()=>{let r=No,t=e=>{let{pow_p_5_8:n,b2:o}=ku(e);return et(ft(n,xm,r)*o,r)};return Ru({P:r,type:"x25519",powPminus2:t,adjustScalarBytes:Ki,scalarMultBase:e=>{let n=et(e,wn.Fn.ORDER);if(n===Ou)return Ou;let o=wn.BASE.multiply(n);return et((o.Z+o.Y)*t(et(o.Z-o.Y,r)),r)}})})();var En=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},ko=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Wt={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new ko("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Mo=32;var Fi,Cm=(async()=>{try{return await Wt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Tm(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Wt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Wt.get().subtle.verify({name:"Ed25519"},n,Bt(t),Bt(e instanceof Uint8Array?e:e.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function _m(r,t,e){return Mu.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Ku(r,t,e){return Fi==null&&(Fi=await Cm),Fi?Tm(r,t,e):_m(r,t,e)}function Ko(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Fo=class{type="Ed25519";raw;constructor(t){this.raw=Hi(t,Mo)}toMultihash(){return Zt.digest(De(this))}toCID(){return xt.createV1(114,this.toMultihash())}toString(){return yt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Et(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Ku(this.raw,e,t);return Ko(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function zi(r){return r=Hi(r,Mo),new Fo(r)}function Hi(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new rt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Rm=Math.pow(2,7),Om=Math.pow(2,14),Pm=Math.pow(2,21),Vi=Math.pow(2,28),qi=Math.pow(2,35),$i=Math.pow(2,42),ji=Math.pow(2,49),tt=128,_t=127;function Dt(r){if(r<Rm)return 1;if(r<Om)return 2;if(r<Pm)return 3;if(r<Vi)return 4;if(r<qi)return 5;if(r<$i)return 6;if(r<ji)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Or(r,t,e=0){switch(Dt(r)){case 8:t[e++]=r&255|tt,r/=128;case 7:t[e++]=r&255|tt,r/=128;case 6:t[e++]=r&255|tt,r/=128;case 5:t[e++]=r&255|tt,r/=128;case 4:t[e++]=r&255|tt,r>>>=7;case 3:t[e++]=r&255|tt,r>>>=7;case 2:t[e++]=r&255|tt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Um(r,t,e=0){switch(Dt(r)){case 8:t.set(e++,r&255|tt),r/=128;case 7:t.set(e++,r&255|tt),r/=128;case 6:t.set(e++,r&255|tt),r/=128;case 5:t.set(e++,r&255|tt),r/=128;case 4:t.set(e++,r&255|tt),r>>>=7;case 3:t.set(e++,r&255|tt),r>>>=7;case 2:t.set(e++,r&255|tt),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Wi(r,t){let e=r[t],n=0;if(n+=e&_t,e<tt||(e=r[t+1],n+=(e&_t)<<7,e<tt)||(e=r[t+2],n+=(e&_t)<<14,e<tt)||(e=r[t+3],n+=(e&_t)<<21,e<tt)||(e=r[t+4],n+=(e&_t)*Vi,e<tt)||(e=r[t+5],n+=(e&_t)*qi,e<tt)||(e=r[t+6],n+=(e&_t)*$i,e<tt)||(e=r[t+7],n+=(e&_t)*ji,e<tt))return n;throw new RangeError("Could not decode varint")}function Nm(r,t){let e=r.get(t),n=0;if(n+=e&_t,e<tt||(e=r.get(t+1),n+=(e&_t)<<7,e<tt)||(e=r.get(t+2),n+=(e&_t)<<14,e<tt)||(e=r.get(t+3),n+=(e&_t)<<21,e<tt)||(e=r.get(t+4),n+=(e&_t)*Vi,e<tt)||(e=r.get(t+5),n+=(e&_t)*qi,e<tt)||(e=r.get(t+6),n+=(e&_t)*$i,e<tt)||(e=r.get(t+7),n+=(e&_t)*ji,e<tt))return n;throw new RangeError("Could not decode varint")}function Hu(r,t,e=0){return t==null&&(t=Ct(Dt(r))),t instanceof Uint8Array?Or(r,t,e):Um(r,t,e)}function nr(r,t=0){return r instanceof Uint8Array?Wi(r,t):Nm(r,t)}var Yi=new Float32Array([-0]),He=new Uint8Array(Yi.buffer);function zu(r,t,e){Yi[0]=r,t[e]=He[0],t[e+1]=He[1],t[e+2]=He[2],t[e+3]=He[3]}function Vu(r,t){return He[0]=r[t],He[1]=r[t+1],He[2]=r[t+2],He[3]=r[t+3],Yi[0]}var Zi=new Float64Array([-0]),Rt=new Uint8Array(Zi.buffer);function qu(r,t,e){Zi[0]=r,t[e]=Rt[0],t[e+1]=Rt[1],t[e+2]=Rt[2],t[e+3]=Rt[3],t[e+4]=Rt[4],t[e+5]=Rt[5],t[e+6]=Rt[6],t[e+7]=Rt[7]}function $u(r,t){return Rt[0]=r[t],Rt[1]=r[t+1],Rt[2]=r[t+2],Rt[3]=r[t+3],Rt[4]=r[t+4],Rt[5]=r[t+5],Rt[6]=r[t+6],Rt[7]=r[t+7],Zi[0]}var km=BigInt(Number.MAX_SAFE_INTEGER),Mm=BigInt(Number.MIN_SAFE_INTEGER),Ht=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return or;if(t<km&&t>Mm)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ju&&(o=0n,++n>ju&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return or;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):or}},or=new Ht(0,0);or.toBigInt=function(){return 0n};or.zzEncode=or.zzDecode=function(){return this};or.length=function(){return 1};var ju=4294967296n;function Wu(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Gu(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Xi(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Jt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Ho(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Qi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Bt(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Jt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Jt(this,4);return Ho(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Jt(this,4);return Ho(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Jt(this,4);let t=Vu(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Jt(this,4);let t=$u(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Jt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Gu(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Jt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Jt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Ht(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Jt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Jt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Jt(this,8);let t=Ho(this.buf,this.pos+=4),e=Ho(this.buf,this.pos+=4);return new Ht(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Wi(this.buf,this.pos);return this.pos+=Dt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Sn(r){return new Qi(r instanceof Uint8Array?r:r.subarray())}function zo(r,t,e){let n=Sn(r);return t.decode(n,void 0,e)}function Ji(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return Ct(i);o+i>t&&(n=Ct(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var sr=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ta(){}var ra=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Km=Ji();function Fm(r){return globalThis.Buffer!=null?Ct(r):Km(r)}var vn=class{len;head;tail;states;constructor(){this.len=0,this.head=new sr(ta,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new sr(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new na((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Vo,10,Ht.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Ht.fromBigInt(t);return this._push(Vo,e.length(),e)}uint64Number(t){return this._push(Or,Dt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Ht.fromBigInt(t).zzEncode();return this._push(Vo,e.length(),e)}sint64Number(t){let e=Ht.fromNumber(t).zzEncode();return this._push(Vo,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ea,1,t?1:0)}fixed32(t){return this._push(An,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Ht.fromBigInt(t);return this._push(An,4,e.lo)._push(An,4,e.hi)}fixed64Number(t){let e=Ht.fromNumber(t);return this._push(An,4,e.lo)._push(An,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(zu,4,t)}double(t){return this._push(qu,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ea,1,0):this.uint32(e)._push(zm,e,t)}string(t){let e=Wu(t);return e!==0?this.uint32(e)._push(Xi,e,t):this._push(ea,1,0)}fork(){return this.states=new ra(this),this.head=this.tail=new sr(ta,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 sr(ta,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Fm(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ea(r,t,e){t[e]=r&255}function Hm(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var na=class extends sr{next;constructor(t,e){super(Hm,t,e),this.next=void 0}};function Vo(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function An(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function zm(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(vn.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Vm,t,r),this},vn.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(qm,t,r),this});function Vm(r,t,e){t.set(r,e)}function qm(r,t,e){r.length<40?Xi(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(it(r),e)}function oa(){return new vn}function qo(r,t){let e=oa();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*$o(r,t,e){let n=Sn(r);yield*t.stream(n,void 0,"$",e)}var jo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Wo(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function sa(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return Wo("enum",jo.VARINT,e,n,o)}function Go(r,t,e){return Wo("message",jo.LENGTH_DELIMITED,r,t,e)}var pt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(pt||(pt={}));var ia;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ia||(ia={}));(function(r){r.codec=()=>sa(ia)})(pt||(pt={}));var fe;(function(r){let t;r.codec=()=>(t==null&&(t=Go((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let h=s.uint32();switch(h>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(h&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let h=s.uint32();switch(h>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(h&7);break}}}})),t);function e(s){return qo(s,r.codec())}r.encode=e;function n(s,i){return zo(s,r.codec(),i)}r.decode=n;function o(s,i){return $o(s,r.codec(),i)}r.stream=o})(fe||(fe={}));var aa;(function(r){let t;r.codec=()=>(t==null&&(t=Go((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let h=s.uint32();switch(h>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(h&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let h=s.uint32();switch(h>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(h&7);break}}}})),t);function e(s){return qo(s,r.codec())}r.encode=e;function n(s,i){return zo(s,r.codec(),i)}r.decode=n;function o(s,i){return $o(s,r.codec(),i)}r.stream=o})(aa||(aa={}));var Ln={};st(Ln,{MAX_RSA_KEY_SIZE:()=>ca,generateRSAKeyPair:()=>th,jwkToJWKKeyPair:()=>eh,jwkToPkcs1:()=>Gm,jwkToPkix:()=>la,jwkToRSAPrivateKey:()=>ya,pkcs1MessageToJwk:()=>ua,pkcs1MessageToRSAPrivateKey:()=>da,pkcs1ToJwk:()=>Wm,pkcs1ToRSAPrivateKey:()=>Ju,pkixMessageToJwk:()=>ha,pkixMessageToRSAPublicKey:()=>ma,pkixToJwk:()=>Ym,pkixToRSAPublicKey:()=>pa});var Pr=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Ln.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return xt.createV1(114,this._multihash)}toString(){return yt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Et(this.raw,t.raw)}verify(t,e,n){return Qu(this.jwk,e,t,n)}},Bn=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Ln.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Et(this.raw,t.raw)}sign(t,e){return Xu(this.jwk,t,e)}};var ca=8192,fa=18,$m=1062,jm=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Wm(r){let t=ye(r);return ua(t)}function ua(r){return{n:X(r[1],"base64url"),e:X(r[2],"base64url"),d:X(r[3],"base64url"),p:X(r[4],"base64url"),q:X(r[5],"base64url"),dp:X(r[6],"base64url"),dq:X(r[7],"base64url"),qi:X(r[8],"base64url"),kty:"RSA"}}function Gm(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new rt("JWK was missing components");return _e([Kt(Uint8Array.from([0])),Kt(it(r.n,"base64url")),Kt(it(r.e,"base64url")),Kt(it(r.d,"base64url")),Kt(it(r.p,"base64url")),Kt(it(r.q,"base64url")),Kt(it(r.dp,"base64url")),Kt(it(r.dq,"base64url")),Kt(it(r.qi,"base64url"))]).subarray()}function Ym(r){let t=ye(r,{offset:0});return ha(t)}function ha(r){let t=ye(r[1],{offset:0});return{kty:"RSA",n:X(t[0],"base64url"),e:X(t[1],"base64url")}}function la(r){if(r.n==null||r.e==null)throw new rt("JWK was missing components");return _e([jm,po(_e([Kt(it(r.n,"base64url")),Kt(it(r.e,"base64url"))]))]).subarray()}function Ju(r){let t=ye(r);return da(t)}function da(r){let t=ua(r);return ya(t)}function pa(r,t){if(r.byteLength>=$m)throw new br("Key size is too large");let e=ye(r,{offset:0});return ma(e,r,t)}function ma(r,t,e){let n=ha(r);if(e==null){let o=se(fe.encode({Type:pt.RSA,Data:t}));e=Yt(fa,o)}return new Pr(n,e)}function ya(r){if(nh(r)>ca)throw new rt("Key size is too large");let t=eh(r),e=se(fe.encode({Type:pt.RSA,Data:la(t.publicKey)})),n=Yt(fa,e);return new Bn(t.privateKey,new Pr(t.publicKey,n))}async function th(r){if(r>ca)throw new rt("Key size is too large");let t=await rh(r),e=se(fe.encode({Type:pt.RSA,Data:la(t.publicKey)})),n=Yt(fa,e);return new Bn(t.privateKey,new Pr(t.publicKey,n))}function eh(r){if(r==null)throw new rt("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function rh(r,t){let e=await Wt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Zm(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Xu(r,t,e){let n=await Wt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await Wt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Bt(t instanceof Uint8Array?t:t.subarray()));return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Qu(r,t,e,n){let o=await Wt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Wt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,Bt(t),Bt(e instanceof Uint8Array?e:e.subarray()));return n?.signal?.throwIfAborted(),s}async function Zm(r,t){if(r.privateKey==null||r.publicKey==null)throw new rt("Private and public key are required");let e=await Promise.all([Wt.get().subtle.exportKey("jwk",r.privateKey),Wt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function nh(r){if(r.kty!=="RSA")throw new rt("invalid key type");if(r.n==null)throw new rt("invalid key modulus");return it(r.n,"base64url").length*8}var Yo=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(tr(t),Nt(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),qt(o)}update(t){return Lr(this),this.iHash.update(t),this}digestInto(t){Lr(this),go(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.canXOF=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},In=(()=>{let r=((t,e,n)=>new Yo(t,e).update(n).digest());return r.create=(t,e)=>new Yo(t,e),r})();var Xm=BigInt(0),ga=class extends Error{constructor(t=""){super(t)}},we={Err:ga,_tlv:{encode:(r,t)=>{let{Err:e}=we;if(be(r,"tag"),r<0||r>255)throw new e("tlv.encode: wrong tag");if(cu(t,"data"),t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=pn(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?pn(o.length/2|128):"";return pn(r)+s+o+t},decode(r,t){let{Err:e}=we;t=Y(t,void 0,"DER data");let n=0;if(r<0||r>255)throw new e("tlv.decode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let h of f)i=i<<8|h;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=we;if(Ao(r),r<Xm)throw new t("integer: negative integers are not allowed");let e=pn(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=we;if(r.length<1)throw new t("invalid signature integer: empty");if(r[0]&128)throw new t("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ie(r)}},toSig(r,t){let{Err:e,_int:n,_tlv:o}=we;if(t!==void 0&&(be(t,"maxScalarBytes"),t<1))throw new e("invalid signature: maxScalarBytes must be positive");let s=Y(r,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:f}=o.decode(2,i),{v:h,l:u}=o.decode(2,f);if(u.length)throw new e("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||h.length>t))throw new e("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(h)}},hexFromSig(r){let{_tlv:t,_int:e}=we;Tt(r,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Zo=(Object.freeze(we._tlv),Object.freeze(we._int),Object.freeze(we));var oh=(r,t)=>(r+(r>=0?t:-t)/sh)/t;function Qm(r,t,e){ce("scalar",r,xe,e);let[[n,o],[s,i]]=t,a=oh(i*r,e),c=oh(-o*r,e),f=r-a*n-c*s,h=-a*o-c*i,u=f<xe,d=h<xe;u&&(f=-f),d&&(h=-h);let p=yn(Math.ceil(Cr(e)/2))+ir;if(f<xe||f>=p||h<xe||h>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:u,k1:f,k2neg:d,k2:h}}function xa(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ba(r,t){Tt(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Ft(e.lowS,"lowS"),Ft(e.prehash,"prehash"),e.format!==void 0&&xa(e.format),e}var xe=BigInt(0),ir=BigInt(1),sh=BigInt(2),wa=BigInt(3),Jm=BigInt(4);function ih(r,t={}){let e=Do("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;Tt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f,clearCofactor:h,isTorsionFree:u,fromBytes:d,toBytes:p}=t,m=t.randomBytes===void 0?ge:t.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let g=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,y=ch(n,o);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function E(S,l,b){if(l.is0()){if(!f)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:A,y:U}=l.toAffine(),k=n.toBytes(A);if(Ft(b,"isCompressed"),b){x();let M=!n.isOdd(U);return $t(ah(M),k)}else return $t(Uint8Array.of(4),k,n.toBytes(U))}function w(S){Y(S,void 0,"Point");let{publicKey:l,publicKeyUncompressed:b}=y,A=S.length,U=S[0],k=S.subarray(1);if(f&&A===1&&U===0)return{x:n.ZERO,y:n.ZERO};if(A===l&&(U===2||U===3)){let M=n.fromBytes(k);if(!n.isValid(M))throw new Error("bad point: is not on curve, wrong x");let z=R(M),V;try{V=n.sqrt(z)}catch(ct){let ot=ct instanceof Error?": "+ct.message:"";throw new Error("bad point: is not on curve, sqrt error"+ot)}x();let j=n.isOdd(V);return(U&1)===1!==j&&(V=n.neg(V)),{x:M,y:V}}else if(A===b&&U===4){let M=n.BYTES,z=n.fromBytes(k.subarray(0,M)),V=n.fromBytes(k.subarray(M,M*2));if(!L(z,V))throw new Error("bad point: is not on curve");return{x:z,y:V}}else throw new Error(`bad point: got length ${A}, expected compressed=${l} or uncompressed=${b}`)}let v=p===void 0?E:p,B=d===void 0?w:d,D=n.mul(s.b,wa),P=n.is0(s.a)?S=>n.ZERO:S=>n.mul(s.a,S);function R(S){let l=n.sqr(S),b=n.mul(l,S);return n.add(n.add(b,n.mul(S,s.a)),s.b)}function L(S,l){let b=n.sqr(l),A=R(S);return n.eql(b,A)}if(!L(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let O=n.mul(n.pow(s.a,wa),Jm),F=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(O,F)))throw new Error("bad curve params: a or b");function K(S,l,b=!1){if(!n.isValid(l)||b&&n.is0(l))throw new Error(`bad point coordinate ${S}`);return typeof l=="object"&&l!==null?n.create(l):l}function q(S){if(!(S instanceof I))throw new Error("Weierstrass Point expected")}function C(S){if(!g||!g.basises)throw new Error("no endo");return Qm(S,g.basises,o.ORDER)}function N(S,l,b,A){if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:U,k1:k,k2neg:M,k2:z}=C(A),V=new I(n.mul(b.X,g.beta),b.Y,b.Z);S.push(U?b.negate():b,M?V.negate():V),l.push(k,z)}else S.push(b),l.push(A)}let T=new WeakSet;class I{static BASE=new I(s.Gx,s.Gy,n.ONE);static ZERO=new I(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(l,b,A){this.X=K("x",l),this.Y=K("y",b,!0),this.Z=K("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(l){let{x:b,y:A}=l||{};if(!l||!n.isValid(b)||!n.isValid(A))throw new Error("invalid affine point");if(l instanceof I)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(A)?I.ZERO:new I(b,A,n.ONE)}static fromBytes(l){let b=I.fromAffine(B(Y(l,void 0,"point")));return b.assertValidity(),b}static fromHex(l){return I.fromBytes(Ir(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=6,b=!0){return _.setWindowSize(this,l),b||this.multiply(wa),this}assertValidity(){let l=this;if(l.is0()){if(f&&n.is0(l.X)&&n.eql(l.Y,n.ONE)&&n.is0(l.Z))return;throw new Error("bad point: ZERO")}if(T.has(l))return;let{x:b,y:A}=l.toAffine();if(!n.isValid(b)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!L(b,A))throw new Error("bad point: equation left != right");if(!l.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");T.add(l)}hasEvenY(){let{y:l}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(l)}equals(l){q(l);let{X:b,Y:A,Z:U}=this,{X:k,Y:M,Z:z}=l,V=n.eql(n.mul(b,z),n.mul(k,U)),j=n.eql(n.mul(A,z),n.mul(M,U));return V&&j}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{X:l,Y:b,Z:A}=this,U=n.ZERO,k=n.ZERO,M=n.ZERO,z=n.mul(l,l),V=n.mul(b,b),j=n.mul(A,A),W=n.mul(l,b);return W=n.add(W,W),M=n.mul(l,A),M=n.add(M,M),U=P(M),k=n.mul(D,j),k=n.add(U,k),U=n.sub(V,k),k=n.add(V,k),k=n.mul(U,k),U=n.mul(W,U),M=n.mul(D,M),j=P(j),W=n.sub(z,j),W=P(W),W=n.add(W,M),M=n.add(z,z),z=n.add(M,z),z=n.add(z,j),z=n.mul(z,W),k=n.add(k,z),j=n.mul(b,A),j=n.add(j,j),z=n.mul(j,W),U=n.sub(U,z),M=n.mul(j,V),M=n.add(M,M),M=n.add(M,M),new I(U,k,M)}add(l){q(l);let{X:b,Y:A,Z:U}=this,{X:k,Y:M,Z:z}=l,V=n.ZERO,j=n.ZERO,W=n.ZERO,ct=n.mul(b,k),ot=n.mul(A,M),bt=n.mul(U,z),Mt=n.add(b,A),at=n.add(k,M);Mt=n.mul(Mt,at),at=n.add(ct,ot),Mt=n.sub(Mt,at),at=n.add(b,U);let lt=n.add(k,z);return at=n.mul(at,lt),lt=n.add(ct,bt),at=n.sub(at,lt),lt=n.add(A,U),V=n.add(M,z),lt=n.mul(lt,V),V=n.add(ot,bt),lt=n.sub(lt,V),W=P(at),V=n.mul(D,bt),W=n.add(V,W),V=n.sub(ot,W),W=n.add(ot,W),j=n.mul(V,W),ot=n.add(ct,ct),ot=n.add(ot,ct),bt=P(bt),at=n.mul(D,at),ot=n.add(ot,bt),bt=n.sub(ct,bt),bt=P(bt),at=n.add(at,bt),ct=n.mul(ot,at),j=n.add(j,ct),ct=n.mul(lt,at),V=n.mul(Mt,V),V=n.sub(V,ct),ct=n.mul(Mt,ot),W=n.mul(lt,W),W=n.add(W,ct),new I(V,j,W)}subtract(l){return q(l),this.add(l.negate())}is0(){return this.equals(I.ZERO)}multiply(l){if(!o.isValidNot0(l))throw new RangeError("invalid scalar: out of range");let{p:b,f:A}=_.mulSecret(this,l,i,H);return H([b,A])[0]}multiplyUnsafe(l){let b=this,A=l;if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===xe||b.is0())return I.ZERO;if(A===ir)return b;if(_.hasWindowSize(this))return _.mulUnsafe(b,A,H);let U=[],k=[];return N(U,k,b,A),_o(I,U,k)}mulAddUnsafe(l,b,A){q(b);let U=[],k=[];return N(U,k,this,l),N(U,k,b,A),_o(I,U,k)}toAffine(l){let b=this,A=l;if(A!=null&&!n.isValid(A))throw new RangeError('"invertedZ" expected valid field element');let{X:U,Y:k,Z:M}=b;if(n.eql(M,n.ONE))return{x:U,y:k};let z=b.is0();A==null&&(A=z?n.ONE:n.inv(M));let V=n.mul(U,A),j=n.mul(k,A),W=n.mul(M,A);if(z)return{x:n.ZERO,y:n.ZERO};if(!n.eql(W,n.ONE))throw new Error("invZ was invalid");return{x:V,y:j}}isTorsionFree(){return i===ir?!0:u?u(I,this):_.mulUnsafe(this,a).is0()}clearCofactor(){return i===ir?this:h?h(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ir?this.is0():this.clearCofactor().is0()}toBytes(l=!0){return Ft(l,"isCompressed"),this.assertValidity(),v(I,this,l)}toHex(l=!0){return dn(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let H=S=>To(I,S),_=new Dr(I,m);return _.bits>=6&&I.BASE.precompute(6),Object.freeze(I.prototype),Object.freeze(I),I}function ah(r){return Uint8Array.of(r?2:3)}function ch(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function t0(r,t={}){Fe(r);let{Fn:e}=r,n=t.randomBytes===void 0?ge:t.randomBytes,o=Object.assign(ch(r.Fp,e),{seed:Math.max(Io(e.ORDER),16)});function s(p){try{let m=e.fromBytes(p);return e.isValidNot0(m)}catch{return!1}}function i(p,m){let{publicKey:g,publicKeyUncompressed:y}=o;try{let x=p.length;return m===!0&&x!==g||m===!1&&x!==y?!1:!r.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Co(Y(p,o.seed,"seed"),e.ORDER)}function c(p,m=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(m)}function f(p){let{secretKey:m,publicKey:g,publicKeyUncompressed:y}=o,x=e._lengths;if(!ke(p))return;let E=Y(p,void 0,"key").length,w=E===g||E===y,v=E===m||!!x?.includes(E);if(!(w&&v))return w}function h(p,m,g=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(m)===!1)throw new Error("second arg must be public key");let y=e.fromBytes(p),x=r.fromBytes(m);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(y).toBytes(g)}let u={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=Rr(a,c);return Object.freeze(u),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:d,Point:r,utils:u,lengths:o})}function fh(r,t,e={}){Fe(r);let n=t;tr(n),Tt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},e),s=o.randomBytes===void 0?ge:o.randomBytes,i=o.hmac===void 0?(S,l)=>In(n,S,l):o.hmac,{Fp:a,Fn:c}=r,{ORDER:f,BITS:h}=c,u=Io(f),d=ki(s,u),{keygen:p,getPublicKey:m,getSharedSecret:g,utils:y,lengths:x}=t0(r,o),E={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},w=f*sh+ir<a.ORDER;function v(S){let l=f>>ir;return S>l}function B(S,l){if(!c.isValidNot0(l))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return l}function D(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function P(S,l,b){return D(),(S===b?0:2)|Number(a.isOdd(l))}function R(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(S,l){xa(l);let b=x.signature,A=l==="compact"?b:l==="recovered"?b+1:void 0;return Y(S,A)}class O{r;s;recovery;constructor(l,b,A){if(this.r=B("r",l),this.s=B("s",b),A!=null){if(R(),![0,1,2,3].includes(A))throw new Error("invalid recovery id");this.recovery=A}Object.freeze(this)}static fromBytes(l,b=E.format){L(l,b);let A;if(b==="der"){if(l.length>2*c.BYTES+16)throw new Zo.Err("invalid signature: DER signature too long");let{r:z,s:V}=Zo.toSig(Y(l),c.BYTES+1);return new O(z,V)}b==="recovered"&&(A=l[0],b="compact",l=l.subarray(1));let U=x.signature/2,k=l.subarray(0,U),M=l.subarray(U,U*2);return new O(c.fromBytes(k),c.fromBytes(M),A)}static fromHex(l,b){return this.fromBytes(Ir(l),b)}assertRecovery(){let{recovery:l}=this;if(l==null)throw new Error("invalid recovery id: must be present");return l}addRecoveryBit(l){return new O(this.r,this.s,l)}recoverPublicKey(l){let{r:b,s:A}=this,U=this.assertRecovery(),k=U===2||U===3?b+f:b;if(!a.isValid(k))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let M=a.toBytes(k),z=r.fromBytes($t(ah((U&1)===0),M)),V=c.inv(k),j=K(Y(l,void 0,"msgHash")),W=c.create(-j*V),ct=c.create(A*V),ot=r.BASE.mulAddUnsafe(W,z,ct);if(ot.is0())throw new Error("invalid recovery: point at infinify");return ot.assertValidity(),ot}hasHighS(){return v(this.s)}toBytes(l=E.format){if(xa(l),l==="der")return Ir(Zo.hexFromSig(this));let{r:b,s:A}=this,U=c.toBytes(b),k=c.toBytes(A);return l==="recovered"?(R(),$t(Uint8Array.of(this.assertRecovery()),U,k)):$t(U,k)}toHex(l){return dn(this.toBytes(l))}}Object.freeze(O.prototype),Object.freeze(O);let F=o.bits2int===void 0?function(l){if(l.length>8192)throw new Error("input is too large");let b=ie(l),A=l.length*8-h;return A>0?b>>BigInt(A):b}:o.bits2int,K=o.bits2int_modN===void 0?function(l){return c.create(F(l))}:o.bits2int_modN,q=yn(h);function C(S){return ce("num < 2^"+h,S,xe,q),c.toBytes(S)}function N(S,l){return Y(S,void 0,"message"),l?Y(n(S),void 0,"prehashed message"):S}function T(S,l,b){let{lowS:A,prehash:U,extraEntropy:k}=ba(b,E);S=N(S,U);let M=K(S),z=c.fromBytes(l);if(!c.isValidNot0(z))throw new Error("invalid private key");let V=[C(z),C(M)];if(k!=null&&k!==!1){let ot=k===!0?s(x.secretKey):k;V.push(Y(ot,void 0,"extraEntropy"))}let j=$t(...V),W=M;function ct(ot){let bt=F(ot);if(!c.isValidNot0(bt))return;let Mt=r.BASE.multiply(bt).toAffine(),at=c.create(Mt.x);if(at===xe)return;let lt;if(d!==void 0){let Le=ie(Co(d(u),f)),sd=c.inv(c.mul(Le,bt)),id=c.mul(Le,W),ad=c.mul(Le,z);lt=c.create(sd*c.create(id+ad*at))}else{let Le=bu(bt,f);lt=c.create(Le*c.create(W+at*z))}if(lt===xe)return;let yr=P(Mt.x,Mt.y,at),en=lt;return A&&v(lt)&&(en=c.neg(lt),yr^=1),new O(at,en,w?void 0:yr)}return{seed:j,k2sig:ct}}function I(S,l,b={}){let{seed:A,k2sig:U}=T(S,l,b);return uu(n.outputLen,c.BYTES,i)(A,U).toBytes(b.format)}function H(S,l,b,A={}){let{lowS:U,prehash:k,format:M}=ba(A,E);if(b=Y(b,void 0,"publicKey"),l=N(l,k),!ke(S)){let z=S instanceof O?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+z)}L(S,M);try{let z=O.fromBytes(S,M),V=r.fromBytes(b);if(V.is0()||U&&z.hasHighS())return!1;let{r:j,s:W}=z,ct=K(l),ot=c.inv(W),bt=c.create(ct*ot),Mt=c.create(j*ot),at=r.BASE.mulAddUnsafe(bt,V,Mt);if(at.is0())return!1;let lt=at.toAffine();return!(c.create(lt.x)!==j||M==="recovered"&&z.recovery!==P(lt.x,lt.y,j))}catch{return!1}}function _(S,l,b={}){let{prehash:A}=ba(b,E);return l=N(l,A),O.fromBytes(S,"recovered").recoverPublicKey(l).toBytes()}return Object.freeze({keygen:p,getPublicKey:m,getSharedSecret:g,utils:y,lengths:x,Point:r,sign:I,verify:H,recoverPublicKey:_,Signature:O,hash:n})}var Sa={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},e0={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var uh=BigInt(2);function r0(r){let t=Sa.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,h=f*f*r%t,u=ft(h,e,t)*h%t,d=ft(u,e,t)*h%t,p=ft(d,uh,t)*f%t,m=ft(p,o,t)*p%t,g=ft(m,s,t)*m%t,y=ft(g,a,t)*g%t,x=ft(y,c,t)*y%t,E=ft(x,a,t)*g%t,w=ft(E,e,t)*h%t,v=ft(w,i,t)*m%t,B=ft(v,n,t)*f%t,D=ft(B,uh,t);if(!Ea.eql(Ea.sqr(D),r))throw new Error("Cannot find square root");return D}var Ea=_r(Sa.p,{sqrt:r0}),n0=ih(Sa,{Fp:Ea,endo:e0}),Ur=fh(n0,se);function hh(r,t,e,n){let o=an.digest(e instanceof Uint8Array?e:e.subarray());if(Ko(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ur.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new En(String(s))});try{return n?.signal?.throwIfAborted(),Ur.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new En(String(s))}}var Xo=class{type="secp256k1";raw;_key;constructor(t){this._key=dh(t),this.raw=lh(this._key)}toMultihash(){return Zt.digest(De(this))}toCID(){return xt.createV1(114,this.toMultihash())}toString(){return yt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Et(this.raw,t.raw)}verify(t,e,n){return hh(this._key,e,t,n)}};function Aa(r){return new Xo(r)}function lh(r){return Ur.Point.fromBytes(r).toBytes()}function dh(r){try{return Ur.Point.fromBytes(r),r}catch(t){throw new br(String(t))}}function Cn(r,t){let{Type:e,Data:n}=fe.decode(r),o=n??new Uint8Array;switch(e){case pt.RSA:return pa(o,t);case pt.Ed25519:return zi(o);case pt.secp256k1:return Aa(o);case pt.ECDSA:return gi(o);default:throw new Ge}}function ph(r){let{Type:t,Data:e}=fe.decode(r.digest),n=e??new Uint8Array;switch(t){case pt.Ed25519:return zi(n);case pt.secp256k1:return Aa(n);case pt.ECDSA:return gi(n);default:throw new Ge}}function De(r){return fe.encode({Type:pt[r.type],Data:r.raw})}var mh=Symbol.for("nodejs.util.inspect.custom"),o0=114,Tn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Fs]=!0;toString(){return this.string==null&&(this.string=yt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return xt.createV1(o0,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Et(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Et(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[mh](){return`PeerId(${this.toString()})`}},_n=class extends Tn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dn=class extends Tn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Rn=class extends Tn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},s0=2336,On=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Zt.digest(it(this.url))}[mh](){return`PeerId(${this.url})`}[Fs]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return xt.createV1(s0,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=X(t)),t.toString()===this.toString())}};var i0=114,yh=2336;function gh(r,t){let e;if(r.charAt(0)==="1"||r.charAt(0)==="Q")e=vr(yt.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return a0(xt.parse(r));if(t==null)throw new rt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');e=vr(t.decode(r))}return bh(e)}function va(r){if(r.type==="Ed25519")return new Dn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Rn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new _n({multihash:r.toCID().multihash,publicKey:r});throw new Ge}function bh(r){if(f0(r))return new _n({multihash:r});if(c0(r))try{let t=ph(r);if(t.type==="Ed25519")return new Dn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Rn({multihash:r,publicKey:t})}catch{let e=X(r.digest);return new On(new URL(e))}throw new so("Supplied PeerID Multihash is invalid")}function a0(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==i0&&r.code!==yh)throw new oo("Supplied PeerID CID is invalid");if(r.code===yh){let t=X(r.multihash.digest);return new On(new URL(t))}return bh(r.multihash)}function c0(r){return r.code===Zt.code}function f0(r){return r.code===an.code}function u0(r){let t=r.getComponents(),e={},n=0;return t[n]?.name==="ip6zone"&&(e.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(e.type=t[n].name,e.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(e.type=t[n].name,e.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(e.protocol=t[n].name==="tcp"?"tcp":"udp",e.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(e.type==="ip4"?e.cidr=parseInt(`${t[n].value}`):e.type==="ip6"&&(e.cidr=`${t[n].value}`),n++),e.type==null||e.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e)}function wh(r){let t=u0(r);if(t==null)throw new rt(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var Qo=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let d=Number.parseInt(u,t);if(!Number.isNaN(d))return d});if(h===void 0)break;if(s*=t,s+=h,s>f||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var h0=45,l0=15,Jo=new Qo;function xh(r){if(!(r.length>l0))return Jo.new(r).parseWith(()=>Jo.readIPv4Addr())}function Eh(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>h0))return Jo.new(r).parseWith(()=>Jo.readIPv6Addr())}function ts(r){return!!xh(r)}function Sh(r){return!!Eh(r)}var Lt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ee=class extends Error{static name="ValidationError";name="ValidationError"},es=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},rs=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function La(r){return t=>X(t,r)}function Ia(r){return t=>it(t,r)}function Nr(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ar(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Ah(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=it(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ar(n);return ne([e,o],e.length+o.length)}function vh(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Te.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ar(n);return ne([e,o],e.length+o.length)}function Ca(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=X(t,"base32"),o=Nr(e);return`${n}:${o}`}var Ta=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new Lt("Invalid byte value in IP address");t[n]=o}),t},Bh=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ts(e[n]),i;s&&(i=Ta(e[n]),e[n]=X(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,X(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new Lt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Lh=function(r){if(r.byteLength!==4)throw new Lt("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Ih=function(r){if(r.byteLength!==16)throw new Lt("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Lt(`Invalid IPv6 address "${e}"`)}};function Ch(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new Lt(`Invalid IPv6 address "${r}"`)}}var Ba=Object.values(Xe).map(r=>r.decoder),d0=(function(){let r=Ba[0].or(Ba[1]);return Ba.slice(2).forEach(t=>r=r.or(t)),r})();function Th(r){return d0.decode(r)}function _h(r){return t=>r.encoder.encode(t)}function p0(r){if(parseInt(r).toString()!==r)throw new Ee("Value must be an integer")}function m0(r){if(r<0)throw new Ee("Value must be a positive integer, or zero")}function y0(r){return t=>{if(t>r)throw new Ee(`Value must be smaller than or equal to ${r}`)}}function g0(...r){return t=>{for(let e of r)e(t)}}var Pn=g0(p0,m0,y0(65535));var vt=-1,_a=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new rs(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Ae=new _a,D0=[{code:4,name:"ip4",size:32,valueToBytes:Ta,bytesToValue:Lh,validate:r=>{if(!ts(r))throw new Ee(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ar,bytesToValue:Nr,validate:Pn},{code:273,name:"udp",size:16,valueToBytes:ar,bytesToValue:Nr,validate:Pn},{code:33,name:"dccp",size:16,valueToBytes:ar,bytesToValue:Nr,validate:Pn},{code:41,name:"ip6",size:128,valueToBytes:Bh,bytesToValue:Ih,stringToValue:Ch,validate:r=>{if(!Sh(r))throw new Ee(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:vt},{code:43,name:"ipcidr",size:8,bytesToValue:La("base10"),valueToBytes:Ia("base10")},{code:53,name:"dns",size:vt},{code:54,name:"dns4",size:vt},{code:55,name:"dns6",size:vt},{code:56,name:"dnsaddr",size:vt},{code:132,name:"sctp",size:16,valueToBytes:ar,bytesToValue:Nr,validate:Pn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:vt,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:vt,bytesToValue:La("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Ia("base58btc")(r):xt.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ca,valueToBytes:Ah},{code:445,name:"onion3",size:296,bytesToValue:Ca,valueToBytes:vh},{code:446,name:"garlic64",size:vt},{code:447,name:"garlic32",size:vt},{code:448,name:"tls"},{code:449,name:"sni",size:vt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:vt,bytesToValue:_h(oi),valueToBytes:Th},{code:480,name:"http"},{code:481,name:"http-path",size:vt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:vt}];D0.forEach(r=>{Ae.addProtocol(r)});function Dh(r){let t=[],e=0;for(;e<r.length;){let n=nr(r,e),o=Ae.getProtocol(n),s=Dt(n),i=R0(o,r,e+s),a=0;i>0&&o.size===vt&&(a=Dt(i));let c=s+a+i,f={code:n,name:o.name,bytes:Bt(r.subarray(e,e+c))};if(i>0){let h=e+s+a,u=r.subarray(h,h+i);f.value=o.bytesToValue?.(u)??X(u)}t.push(f),e+=c}return t}function Rh(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Ae.getProtocol(n.code),s=Dt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??it(n.value),a=i.byteLength,o.size===vt&&(c=Dt(a)));let f=new Uint8Array(s+c+a),h=0;Or(n.code,f,h),h+=s,i!=null&&(o.size===vt&&(Or(a,f,h),h+=c),f.set(i,h)),n.bytes=f}e.push(n.bytes),t+=n.bytes.byteLength}return ne(e,t)}function Oh(r){if(r.charAt(0)!=="/")throw new Lt('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=Ae.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new Lt(`Component ${o} was missing value`);e="value"}else if(e==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Lt(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new Lt("Incomplete multiaddr");return t}function Ph(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Ae.getProtocol(t.code);if(e==null)throw new Lt(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function R0(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:nr(t,e)}var O0=Symbol.for("nodejs.util.inspect.custom"),Ga=Symbol.for("@multiformats/multiaddr");function P0(r){if(r==null&&(r="/"),Uh(r))return r.getComponents();if(r instanceof Uint8Array)return Dh(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Oh(r);if(Array.isArray(r))return r;throw new Lt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Wa=class r{[Ga]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=P0(t),e.validate!==!1&&U0(this)}get bytes(){return this.#r==null&&(this.#r=Rh(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Ph(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new es(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return Et(this.bytes,t.bytes)}[O0](){return`Multiaddr(${this.toString()})`}};function U0(r){r.getComponents().forEach(t=>{let e=Ae.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function Uh(r){return!!r?.[Ga]}var ut=r=>({match:t=>{let e=t[0];return e==null||e.code!==r||e.value!=null?!1:t.slice(1)}}),$=(r,t)=>({match:e=>{let n=e[0];return n?.code!==r||n.value==null||t!=null&&n.value!==t?!1:e.slice(1)}}),Nh=r=>({match:t=>r.match(t)===!1?t:!1}),G=r=>({match:t=>{let e=r.match(t);return e===!1?t:e}}),Ot=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1}}),Q=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t}});function ht(...r){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function e(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:r,matches:e,exactMatch:n}}var N0=$(421),CS=ht(N0),fs=$(54),us=$(55),hs=$(56),Za=$(53),TS=ht(fs,G($(421))),_S=ht(us,G($(421))),DS=ht(hs,G($(421))),RS=ht(Ot(Za,hs,fs,us),G($(421))),kh=Q($(4),G($(43))),Mh=Q(G($(42)),$(41),G($(43))),Xa=Ot(kh,Mh),Fr=Ot(Xa,Za,fs,us,hs),OS=ht(Ot(Xa,Q(Ot(Za,hs,fs,us),G($(421))))),PS=ht(kh),US=ht(Mh),NS=ht(Xa),Qa=Q(Fr,$(6)),Un=Q(Fr,$(273)),kS=ht(Q(Qa,G($(421)))),MS=ht(Un),Ja=Q(Un,ut(460),G($(421))),ls=Q(Un,ut(461),G($(421))),k0=Ot(Ja,ls),KS=ht(Ja),FS=ht(ls),Ya=Ot(Fr,Qa,Un,Ja,ls),Kh=Ot(Q(Ya,ut(477),G($(421)))),HS=ht(Kh),Fh=Ot(Q(Ya,ut(478),G($(421))),Q(Ya,ut(448),G($(449)),ut(477),G($(421)))),zS=ht(Fh),Hh=Q(Un,ut(280),G($(466)),G($(466)),G($(421))),VS=ht(Hh),zh=Q(ls,ut(465),G($(466)),G($(466)),G($(421))),ds=ht(zh),cs=Ot(Kh,Fh,Q(Qa,G($(421))),Q(k0,G($(421))),Q(Fr,G($(421))),Hh,zh,$(421)),qS=ht(cs),M0=Q(G(cs),ut(290),Nh(ut(281)),G($(421))),$S=ht(M0),K0=Ot(Q(cs,ut(290),ut(281),G($(421))),Q(cs,ut(281),G($(421))),Q(ut(281),G($(421)))),jS=ht(K0),F0=Q(Fr,Ot(Q($(6,"80")),Q($(6),ut(480)),ut(480)),G($(481)),G($(421))),WS=ht(F0),H0=Q(Fr,Ot(Q($(6,"443")),Q($(6,"443"),ut(480)),Q($(6),ut(443)),Q($(6),ut(448),ut(480)),Q(ut(448),ut(480)),ut(448),ut(443)),G($(481)),G($(421))),GS=ht(H0),z0=Ot(Q($(777),G($(421)))),YS=ht(z0),V0=Ot(Q($(400),G($(421)))),ZS=ht(V0);function ps(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var ms=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Hr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new ms(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new ms(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var tc=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ys(r={}){return q0(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function q0(r,t){t=t??{};let e=t.onEnd,n=new Hr,o,s,i,a=ps(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,x)=>{s=E=>{s=null,n.push(E);try{y(r(n))}catch(w){x(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ps()})}},f=y=>s!=null?s(y):(n.push(y),o),h=y=>(n=new Hr,s!=null?s({error:y}):(n.push({error:y}),o)),u=y=>{if(i)return o;if(t?.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?o:(i=!0,y!=null?h(y):f({done:!0})),p=()=>(n=new Hr,d(),{done:!0}),m=y=>(d(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:m,push:u,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((v,B)=>{w=()=>{B(new tc)},x.addEventListener("abort",w)}));try{await Promise.race([a.promise,E])}finally{w!=null&&x!=null&&x?.removeEventListener("abort",w)}}},e==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(y){return g.throw(y),e!=null&&(e(y),e=void 0),{done:!0}},return(){return g.return(),e!=null&&(e(),e=void 0),{done:!0}},push:u,end(y){return g.end(y),e!=null&&(e(y),e=void 0),o},get readableLength(){return g.readableLength},onEmpty:y=>g.onEmpty(y)},o}var ec=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Vh=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function rc(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,h=new Promise((u,d)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){d(Vh(i));return}if(i&&(c=()=>{d(Vh(i))},i.addEventListener("abort",c,{once:!0})),r.then(u,d),e===Number.POSITIVE_INFINITY)return;let p=new ec;a=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(m){d(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?d(o):(p.message=o??`Promise timed out after ${e} milliseconds`,d(p))},e)}).finally(()=>{h.clear(),c&&i&&i.removeEventListener("abort",c)});return h.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},h}var $0=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function j0(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:h}=$0(r),u=async(...p)=>{let m=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(m))return}catch(g){n(),i(g);return}c.push(m),e.count===c.length&&(n(),s(c))},d=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)h(p,u);for(let p of e.rejectionEvents)a.includes(p)||h(p,d)};for(let p of a)f(p,u);for(let p of e.rejectionEvents)a.includes(p)||f(p,d);e.signal&&e.signal.addEventListener("abort",()=>{d(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=rc(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function ze(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=j0(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var fr=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},gs=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},bs=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function W0(r){return r.reason}function Gt(r,t,e){if(t==null||r==null)return r;let n=e?.translateError??W0;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;return Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})]).finally(()=>{o!=null&&t.removeEventListener("abort",o)})}var G0=Math.pow(2,20)*4,ue=class extends xr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#t=!1;onDrainPromise;constructor(t){super(),this.status="open",this.log=t.log,this.direction=t.direction??"outbound",this.inactivityTimeout=t.inactivityTimeout??12e4,this.maxReadBufferLength=t.maxReadBufferLength??G0,this.maxWriteBufferLength=t.maxWriteBufferLength,this.maxMessageSize=t.maxMessageSize,this.readBuffer=new dt,this.writeBuffer=new dt,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 e=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(o){this.log.error("processSendQueue threw - %e",o)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",e);let n=o=>{this.onDrainPromise?.reject(o.error??new bs)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#t}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(t){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Gt(this.onDrainPromise.promise,t?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let t=ys(),e=s=>{t.push(s.data)};this.addEventListener("message",e);let n=s=>{t.end(s.error)};this.addEventListener("close",n);let o=()=>{t.end()};this.addEventListener("remoteCloseWrite",o);try{yield*t}finally{this.removeEventListener("message",e),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(t){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new Ie(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",t.byteLength),this.writeBuffer.append(t),this.processSendQueue()}abort(t){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",t),this.status="aborted",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(t)}catch(e){this.log.error("failed to send reset to remote - %e",e)}this.dispatchEvent(new ao(t))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ie("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 Ie("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(t){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ie(`Cannot push data onto a stream that is ${this.readStatus}`);if(t.byteLength!==0){if(this.readBuffer.append(t),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(t){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ie(`Cannot push data onto a stream that is ${this.readStatus}`);if(t.byteLength!==0){if(this.readBuffer.prepend(t),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(t){if(t.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(t),this.dispatchReadBuffer()}}addEventListener(...t){super.addEventListener.apply(this,t),t[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),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 co(new ro))}onTransportClosed(t){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"),t!=null?this.abort(t):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.maybeDispatchEnd(),this.dispatchEvent(new wr))}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 t=!0,e=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){t=!1;break}let s=this.writeBuffer.sublist(0,o),i=new dt(s);this.writeBuffer.consume(s.byteLength);let a;try{a=this.sendData(s)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}if(t=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!t)break}return t||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,e,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),t}finally{this.sendingData=!1}}maybeDispatchEnd(){this.#t||this.readBuffer.byteLength>0||this.remoteWriteStatus!=="closed"&&this.readStatus!=="closed"||(this.#t=!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 t=this.readBuffer.sublist();this.readBuffer.consume(t.byteLength),this.dispatchEvent(new io(t))}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 We(`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 We(`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 ws=class extends ue{remoteAddr;metricPrefix;metrics;constructor(t){super(t),this.metricPrefix=t.metricPrefix??"",this.metrics=t.metrics,this.remoteAddr=t.remoteAddr,this.addEventListener("close",e=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),e.error!=null?e.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):e.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(t){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 ze(this,"idle",{...t,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 ze(this,"drain",{...t,rejectionEvents:["close"]})),await this.sendClose(t),this.onTransportClosed())}};function qh(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var xs=class extends xr{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(t,e){super(),this.maConn=t,this.protocol=e.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=t.log.newScope(e.name),this.streamOptions=e.streamOptions,this.maxEarlyStreams=e.maxEarlyStreams??10,this.metrics=e.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let s=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",s)}send(t){let e=this.maConn.send(t);return e===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),e}async close(t){this.status==="closed"||this.status==="closing"||(this.status="closing",await Gt(Promise.all([...this.streams].map(async e=>{await e.close(t)})),t?.signal),this.status="closed")}abort(t){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(e=>{e.abort(t)}),this.status="closed")}onTransportClosed(t){this.status="closing";try{[...this.streams].forEach(e=>{e.onTransportClosed(t)})}catch(e){this.abort(e)}this.status="closed"}async createStream(t){if(this.status!=="open")throw new eo;let e=this.onCreateStream({...this.streamOptions,...t});return qh(e)&&(e=await e),this.streams.push(e),this.cleanUpStream(e),e}onRemoteStream(t){if(this.streams.push(t),this.cleanUpStream(t),this.listenerCount("stream")===0){this.earlyStreams.push(t),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new gs(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:t})}cleanUpStream(t){let e=n=>{let o=this.streams.findIndex(s=>s===t);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${t.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${t.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${t.direction}_stream_end`]:!0})};t.addEventListener("close",e),this.metrics?.increment({[`${t.direction}_stream`]:!0})}addEventListener(...t){super.addEventListener.apply(this,t),t[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(e=>{this.safeDispatchEvent("stream",{detail:e})}),this.earlyStreams=[]})}};var Es=class extends ue{id;protocol;constructor(t){super(t),this.id=t.id,this.protocol=t.protocol??""}async close(t){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 ze(this,"idle",{...t,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 ze(this,"drain",{...t,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(t),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(t){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(t),this.readStatus="closed",this.maybeDispatchEnd(),this.log("closed readable end gracefully"))}};var Y0=4194304,Ss=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Nn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},oc=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},sc=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Z0(r){return typeof r?.closeRead=="function"}function X0(r){return typeof r?.close=="function"}function nc(r){return Z0(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:X0(r)?r.status!=="open":!1}function Q0(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function J0(r,t){let e=t?.maxBufferSize??Y0,n=new dt,o,s=!1,i;if(!Q0(r))throw new rt("Argument should be a Stream or a Multiaddr");let a=u=>{if(i==null){if(n.append(u.data),n.byteLength>e){let d=n.byteLength;n.consume(d);let p=new We(`Read buffer overflow - ${d} > ${e}`);i=p,o?.reject(p),queueMicrotask(()=>{r.abort(p)});return}o?.resolve()}};r.addEventListener("message",a);let c=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};r.addEventListener("close",c);let f=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",f);let h={readBuffer:n,async read(u){if(s===!0)throw new Ss("Stream was unwrapped");if(i!=null)throw i;if(nc(r)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new fr(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let d=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=d){o.resolve();break}if(await Gt(o.promise,u?.signal),nc(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let p=u?.bytes??n.byteLength;if(n.byteLength<p){if(nc(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,p),new fr(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return h.read(u)}let m=n.sublist(0,p);return n.consume(p),m},async write(u,d){if(s===!0)throw new Ss("Stream was unwrapped");r.send(u)||await ze(r,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",a),r.removeEventListener("close",c),r.removeEventListener("remoteCloseWrite",f),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return h}function ic(r,t={}){let e=J0(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Dt(t.maxDataLength));let n=t?.lengthDecoder??nr,o=t?.lengthEncoder??Hu;return{async read(i){let a=-1,c=new dt;for(;;){let h=await e.read({...i,bytes:1});if(h==null)break;c.append(h);try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new Nn("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new sc(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new oc(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await e.read({...i,bytes:a});if(f==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new fr(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new fr(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await e.write(new dt(o(i.byteLength),i),a)},async writeV(i,a){let c=new dt(...i.flatMap(f=>[o(f.byteLength),f]));await e.write(c,a)},unwrap(){return e.unwrap()}}}var ty=1024*1024*4,ey=1024*1024*4,As=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(t={}){this.buffer=new dt,this.maxBufferSize=t.maxBufferSize??ty,this.maxDataLength=t.maxDataLength??ey,this.lengthDecoder=t.lengthDecoder??nr,this.encodingLength=t.encodingLength??Dt}*decode(t){if(this.buffer.append(t),this.buffer.byteLength>this.maxBufferSize)throw new rt(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let e;try{e=this.lengthDecoder(this.buffer)}catch(s){if(s instanceof RangeError)break;throw s}if(e<0||e>this.maxDataLength)throw new Nn("Invalid message length");let n=this.encodingLength(e),o=n+e;if(this.buffer.byteLength>=o){let s=this.buffer.sublist(n,o);this.buffer.consume(o),s.byteLength>0&&(yield s)}else break}}};function At(r=0){return new Uint8Array(r)}function Pt(r=0){return new Uint8Array(r)}var zr=!!globalThis.process?.env?.DUMP_SESSION_KEYS,ac=16;function cc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}var vs=r=>r?`"${r}" `:"";function Bs(r,t=""){if(typeof r!="boolean")throw new TypeError(vs(t)+"expected boolean, got type="+typeof r);return r}function ur(r,t=""){if(typeof r!="number")throw new TypeError(vs(t)+"expected number, got "+typeof r);if(!Number.isSafeInteger(r)||r<0)throw new RangeError(vs(t)+"expected integer >= 0, got "+r);return r}function wt(r,t,e=""){if(cc(r)&&(t===void 0||r.length===t))return r;t!==void 0&&ur(t,"length");let n=cc(r),o=t!==void 0?` of length ${t}`:"",s=n?`length=${r.length}`:`type=${typeof r}`,i=vs(e)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}var $h=(r,t)=>{if(r===null||typeof r!="object"||Array.isArray(r))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof r}`)};function fc(r,t=!0){if(r.destroyed)throw new Error("hash was destroyed");if(t&&r.finished)throw new Error("digest() was already called")}function jh(r,t){wt(r,void 0,"output");let e=t.outputLen;if(!(r.length>=e))throw new RangeError('"output" expected length >= '+e)}function he(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function te(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function ry(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var Ve=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ny(r){return r<<24&4278190080|r<<8&16711680|r>>>8&65280|r>>>24&255}function oy(r){for(let t=0;t<r.length;t++)r[t]=ny(r[t]);return r}var ve=Ve?r=>r:oy;function sy(r,t){return!r.byteLength||!t.byteLength?!1:r.buffer===t.buffer&&r.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<r.byteOffset+r.byteLength}function Wh(r,t){if(sy(r,t)&&r.byteOffset<t.byteOffset)throw new Error("complex overlap of input and output is not supported")}function Gh(r,t){return $h(r,"defaults"),$h(t,"opts"),Object.assign(r,t)}function Yh(r,t){if(r=wt(r),t=wt(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Zh(r,t,e){let n=t,o=e||(()=>[]),s=(a,c)=>n(c,...o(a)).update(a).digest(),i=n(new Uint8Array(r),...o(new Uint8Array(0)));return s.outputLen=i.outputLen,s.blockLen=i.blockLen,s.create=(a,...c)=>n(a,...c),s}var Xh=(r,t)=>{function e(n,...o){if(wt(n,void 0,"key"),r.nonceLength!==void 0){let u=o[0];wt(u,r.varSizeNonce?void 0:r.nonceLength,"nonce")}let s=r.tagLength,i=r.nonceLength!==void 0?1:0;if(!r.withAAD){for(let u=i;u<o.length;u++)if(cc(o[u]))throw new Error("AAD not supported")}r.withAAD&&o[i]!==void 0&&wt(o[i],void 0,"AAD");let a=t(n,...o),c=(u,d)=>{if(d!==void 0){if(u!==2)throw new Error("cipher output not supported");wt(d,void 0,"output")}},f=!1;return{encrypt(u,d){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,wt(u,void 0,"data"),c(a.encrypt.length,d),a.encrypt(u,d)},decrypt(u,d){if(wt(u,void 0,"data"),s&&u.length<s)throw new Error('"ciphertext" expected length >= tagLength='+s);return c(a.decrypt.length,d),a.decrypt(u,d)}}}return Object.assign(e,r),e};function kn(r,t,e=!0){if(t===void 0)return new Uint8Array(r);if(wt(t,r,"output"),e&&!Mn(t))throw new Error("invalid output, must be aligned");return t}function Qh(r,t,e){ur(r),ur(t),Bs(e);let n=new Uint8Array(16),o=ry(n);return o.setBigUint64(0,BigInt(t),e),o.setBigUint64(8,BigInt(r),e),n}function Mn(r){return r.byteOffset%4===0}function Vr(r){return Uint8Array.from(wt(r))}var tl=r=>Uint8Array.from(r.split(""),t=>t.charCodeAt(0)),iy=ve(he(tl("expand 16-byte k"))),ay=ve(he(tl("expand 32-byte k")));function Z(r,t){return r<<t|r>>>32-t}var Kn=64,cy=16,uc=2**32-1,Jh=Uint32Array.of();function fy(r,t,e,n,o,s,i,a){let c=o.length,f=new Uint8Array(Kn),h=he(f),u=Ve&&Mn(o)&&Mn(s),d=u?he(o):Jh,p=u?he(s):Jh;if(!Ve){for(let m=0;m<c;i++){if(r(t,e,n,h,i,a),ve(h),i>=uc)throw new Error("arx: counter overflow");let g=Math.min(Kn,c-m);for(let y=0,x;y<g;y++)x=m+y,s[x]=o[x]^f[y];m+=g}return}for(let m=0;m<c;i++){if(r(t,e,n,h,i,a),i>=uc)throw new Error("arx: counter overflow");let g=Math.min(Kn,c-m);if(u&&g===Kn){let y=m/4;if(m%4!==0)throw new Error("arx: invalid block position");for(let x=0,E;x<cy;x++)E=y+x,p[E]=d[E]^h[x];m+=Kn;continue}for(let y=0,x;y<g;y++)x=m+y,s[x]=o[x]^f[y];m+=g}}function el(r,t){let{allowShortKeys:e,extendNonceFn:n,counterLength:o,counterRight:s,rounds:i}=Gh({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof r!="function")throw new Error("core must be a function");return ur(o),ur(i),Bs(s),Bs(e),(a,c,f,h,u=0)=>{wt(a,void 0,"key"),wt(c,void 0,"nonce"),wt(f,void 0,"data");let d=f.length,p=h!==void 0;if(h=kn(d,h,!1),p&&Wh(f,h),ur(u),u<0||u>=uc)throw new Error("arx: counter overflow");let m=[],g=a.length,y,x;if(g===32)m.push(y=Vr(a)),x=ay;else if(g===16&&e)y=new Uint8Array(32),y.set(a),y.set(a,16),x=iy,m.push(y);else throw wt(a,32,"arx key"),new Error("invalid key size");(!Ve||!Mn(c))&&m.push(c=Vr(c));let E=he(y);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let B=c.subarray(0,16);if(Ve)n(x,E,he(B),E);else{let D=ve(Uint32Array.from(x));n(D,E,he(B),E),te(D),ve(E)}c=c.subarray(16)}else Ve||ve(E);let w=16-o;if(w!==c.length)throw new Error(`arx: nonce must be ${w} or 16 bytes`);if(w!==12){let B=new Uint8Array(12);B.set(c,s?0:12-c.length),c=B,m.push(c)}let v=ve(he(c));try{return fy(r,x,E,v,f,h,u,i),h}finally{te(...m)}}}function It(r,t){return r[t++]&255|(r[t++]&255)<<8}var hc=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(t){t=Vr(wt(t,32,"key"));let e=It(t,0),n=It(t,2),o=It(t,4),s=It(t,6),i=It(t,8),a=It(t,10),c=It(t,12),f=It(t,14);this.r[0]=e&8191,this.r[1]=(e>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|s<<9)&8191,this.r[4]=(s>>>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 h=0;h<8;h++)this.pad[h]=It(t,16+2*h)}process(t,e,n=!1){let o=n?0:2048,{h:s,r:i}=this,a=i[0],c=i[1],f=i[2],h=i[3],u=i[4],d=i[5],p=i[6],m=i[7],g=i[8],y=i[9],x=It(t,e+0),E=It(t,e+2),w=It(t,e+4),v=It(t,e+6),B=It(t,e+8),D=It(t,e+10),P=It(t,e+12),R=It(t,e+14),L=s[0]+(x&8191),O=s[1]+((x>>>13|E<<3)&8191),F=s[2]+((E>>>10|w<<6)&8191),K=s[3]+((w>>>7|v<<9)&8191),q=s[4]+((v>>>4|B<<12)&8191),C=s[5]+(B>>>1&8191),N=s[6]+((B>>>14|D<<2)&8191),T=s[7]+((D>>>11|P<<5)&8191),I=s[8]+((P>>>8|R<<8)&8191),H=s[9]+(R>>>5|o),_=0,S=_+L*a+O*(5*y)+F*(5*g)+K*(5*m)+q*(5*p);_=S>>>13,S&=8191,S+=C*(5*d)+N*(5*u)+T*(5*h)+I*(5*f)+H*(5*c),_+=S>>>13,S&=8191;let l=_+L*c+O*a+F*(5*y)+K*(5*g)+q*(5*m);_=l>>>13,l&=8191,l+=C*(5*p)+N*(5*d)+T*(5*u)+I*(5*h)+H*(5*f),_+=l>>>13,l&=8191;let b=_+L*f+O*c+F*a+K*(5*y)+q*(5*g);_=b>>>13,b&=8191,b+=C*(5*m)+N*(5*p)+T*(5*d)+I*(5*u)+H*(5*h),_+=b>>>13,b&=8191;let A=_+L*h+O*f+F*c+K*a+q*(5*y);_=A>>>13,A&=8191,A+=C*(5*g)+N*(5*m)+T*(5*p)+I*(5*d)+H*(5*u),_+=A>>>13,A&=8191;let U=_+L*u+O*h+F*f+K*c+q*a;_=U>>>13,U&=8191,U+=C*(5*y)+N*(5*g)+T*(5*m)+I*(5*p)+H*(5*d),_+=U>>>13,U&=8191;let k=_+L*d+O*u+F*h+K*f+q*c;_=k>>>13,k&=8191,k+=C*a+N*(5*y)+T*(5*g)+I*(5*m)+H*(5*p),_+=k>>>13,k&=8191;let M=_+L*p+O*d+F*u+K*h+q*f;_=M>>>13,M&=8191,M+=C*c+N*a+T*(5*y)+I*(5*g)+H*(5*m),_+=M>>>13,M&=8191;let z=_+L*m+O*p+F*d+K*u+q*h;_=z>>>13,z&=8191,z+=C*f+N*c+T*a+I*(5*y)+H*(5*g),_+=z>>>13,z&=8191;let V=_+L*g+O*m+F*p+K*d+q*u;_=V>>>13,V&=8191,V+=C*h+N*f+T*c+I*a+H*(5*y),_+=V>>>13,V&=8191;let j=_+L*y+O*g+F*m+K*p+q*d;_=j>>>13,j&=8191,j+=C*u+N*h+T*f+I*c+H*a,_+=j>>>13,j&=8191,_=(_<<2)+_|0,_=_+S|0,S=_&8191,_=_>>>13,l+=_,s[0]=S,s[1]=l,s[2]=b,s[3]=A,s[4]=U,s[5]=k,s[6]=M,s[7]=z,s[8]=V,s[9]=j}finalize(){let{h:t,pad:e}=this,n=new Uint16Array(10),o=t[1]>>>13;t[1]&=8191;for(let a=2;a<10;a++)t[a]+=o,o=t[a]>>>13,t[a]&=8191;t[0]+=o*5,o=t[0]>>>13,t[0]&=8191,t[1]+=o,o=t[1]>>>13,t[1]&=8191,t[2]+=o,n[0]=t[0]+5,o=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=t[a]+o,o=n[a]>>>13,n[a]&=8191;n[9]-=8192;let s=(o^1)-1;for(let a=0;a<10;a++)n[a]&=s;s=~s;for(let a=0;a<10;a++)t[a]=t[a]&s|n[a];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+e[0];t[0]=i&65535;for(let a=1;a<8;a++)i=(t[a]+e[a]|0)+(i>>>16)|0,t[a]=i&65535;te(n)}update(t){fc(this),wt(t),t=Vr(t);let{buffer:e,blockLen:n}=this,o=t.length;for(let s=0;s<o;){let i=Math.min(n-this.pos,o-s);if(i===n){for(;n<=o-s;s+=n)this.process(t,s);continue}e.set(t.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===n&&(this.process(e,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,te(this.h,this.r,this.buffer,this.pad)}digestInto(t){fc(this),jh(t,this),this.finished=!0;let{buffer:e,h:n}=this,{pos:o}=this;if(o){for(e[o++]=1;o<16;o++)e[o]=0;this.process(e,0,!0)}this.finalize();let s=0;for(let i=0;i<8;i++)t[s++]=n[i]>>>0,t[s++]=n[i]>>>8}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}},rl=Zh(32,r=>new hc(r));function uy(r,t,e,n,o,s=20){let i=r[0],a=r[1],c=r[2],f=r[3],h=t[0],u=t[1],d=t[2],p=t[3],m=t[4],g=t[5],y=t[6],x=t[7],E=o,w=e[0],v=e[1],B=e[2],D=i,P=a,R=c,L=f,O=h,F=u,K=d,q=p,C=m,N=g,T=y,I=x,H=E,_=w,S=v,l=B;for(let A=0;A<s;A+=2)D=D+O|0,H=Z(H^D,16),C=C+H|0,O=Z(O^C,12),D=D+O|0,H=Z(H^D,8),C=C+H|0,O=Z(O^C,7),P=P+F|0,_=Z(_^P,16),N=N+_|0,F=Z(F^N,12),P=P+F|0,_=Z(_^P,8),N=N+_|0,F=Z(F^N,7),R=R+K|0,S=Z(S^R,16),T=T+S|0,K=Z(K^T,12),R=R+K|0,S=Z(S^R,8),T=T+S|0,K=Z(K^T,7),L=L+q|0,l=Z(l^L,16),I=I+l|0,q=Z(q^I,12),L=L+q|0,l=Z(l^L,8),I=I+l|0,q=Z(q^I,7),D=D+F|0,l=Z(l^D,16),T=T+l|0,F=Z(F^T,12),D=D+F|0,l=Z(l^D,8),T=T+l|0,F=Z(F^T,7),P=P+K|0,H=Z(H^P,16),I=I+H|0,K=Z(K^I,12),P=P+K|0,H=Z(H^P,8),I=I+H|0,K=Z(K^I,7),R=R+q|0,_=Z(_^R,16),C=C+_|0,q=Z(q^C,12),R=R+q|0,_=Z(_^R,8),C=C+_|0,q=Z(q^C,7),L=L+O|0,S=Z(S^L,16),N=N+S|0,O=Z(O^N,12),L=L+O|0,S=Z(S^L,8),N=N+S|0,O=Z(O^N,7);let b=0;n[b++]=i+D|0,n[b++]=a+P|0,n[b++]=c+R|0,n[b++]=f+L|0,n[b++]=h+O|0,n[b++]=u+F|0,n[b++]=d+K|0,n[b++]=p+q|0,n[b++]=m+C|0,n[b++]=g+N|0,n[b++]=y+T|0,n[b++]=x+I|0,n[b++]=E+H|0,n[b++]=w+_|0,n[b++]=v+S|0,n[b++]=B+l|0}var hy=el(uy,{counterRight:!1,counterLength:4,allowShortKeys:!1});var ly=new Uint8Array(16),nl=(r,t)=>{r.update(t);let e=t.length%16;e&&r.update(ly.subarray(e))},dy=new Uint8Array(32);function ol(r,t,e,n,o){o!==void 0&&wt(o,void 0,"AAD");let s=r(t,e,dy),i=Qh(n.length,o?o.length:0,!0),a=rl.create(s);o&&nl(a,o),nl(a,n),a.update(i);let c=a.digest();return te(s,i),c}var py=r=>(t,e,n)=>({encrypt(s,i){let a=s.length;i=kn(a+16,i,!1),i.set(s);let c=i.subarray(0,-16);r(t,e,c,c,1);let f=ol(r,t,e,c,n);return i.set(f,a),te(f),i},decrypt(s,i){i=kn(s.length-16,i,!1);let a=s.subarray(0,-16),c=s.subarray(-16),f=ol(r,t,e,a,n);if(!Yh(c,f))throw te(f),new Error("invalid tag");return i.set(s.subarray(0,-16)),r(t,e,i,i,1),te(f),i}}),lc=Xh({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},py(hy));function sl(r,t,e){return tr(r),e===void 0&&(e=new Uint8Array(r.outputLen)),In(r,e,t)}var Fn=Uint8Array.of(0),my=Uint8Array.of();function il(r,t,e,n=32,o){tr(r),Xt(n,"length"),Nt(t,void 0,"prk");let s=r.outputLen;if(t.length<s)throw new Error('"prk" must be at least HashLen octets');if(n>255*s)throw new Error("Length must be <= 255*HashLen");let i=Math.ceil(n/s);if(e===void 0?e=my:Nt(e,void 0,"info"),!i)return o&&qt(t),new Uint8Array;let a=o&&i===1?t:new Uint8Array(i*s),{iHash:c,oHash:f}=In.create(r,t),h=o?t:new Uint8Array(s),u=i>1?o?.iHash||r.create():void 0;for(let p=0;p<i-1;p++){Fn[0]=p+1;let m=c._cloneInto(u);p&&m.update(h),m.update(e).update(Fn).digestInto(h),f._cloneInto(u).update(h).digestInto(h),a.set(h,s*p)}if(Fn[0]=i,i>1&&c.update(h),c.update(e).update(Fn).digestInto(h),f.update(h).digestInto(h),a.set(h,s*(i-1)),c.destroy(),f.destroy(),u?.destroy(),h!==a&&qt(h),qt(Fn),n===a.length)return a;let d=a.slice(0,n);return qt(a),d}var dc={hashSHA256(r){return se(r.subarray())},getHKDF(r,t){let e=sl(se,t,r),o=il(se,e,void 0,96),s=o.subarray(0,32),i=o.subarray(32,64),a=o.subarray(64,96);return[s,i,a]},generateX25519KeyPair(){let r=xn.utils.randomSecretKey();return{publicKey:xn.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:xn.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,t){return xn.getSharedSecret(r.subarray(),t.subarray())},chaCha20Poly1305Encrypt(r,t,e,n){return lc(n,t,e).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,t,e,n,o){return lc(n,t,e).decrypt(r.subarray(),o)}};var al=dc;function cl(r){return{generateKeypair:r.generateX25519KeyPair,dh:(t,e)=>r.generateX25519SharedKey(t.privateKey,e).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var qr=r=>{let t=Pt(2);return t[0]=r>>8,t[1]=r,t};qr.bytes=2;var $r=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let t=0;return t+=r[0]<<8,t+=r[1],t}return r.getUint16(0)};$r.bytes=2;function fl(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}var bc={};st(bc,{base10:()=>Sy});var A8=new Uint8Array(0);function ul(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Be(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function hl(r){return new TextEncoder().encode(r)}function ll(r){return new TextDecoder().decode(r)}function yy(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function u(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var g=0,y=0,x=0,E=m.length;x!==E&&m[x]===0;)x++,g++;for(var w=(E-x)*h+1>>>0,v=new Uint8Array(w);x!==E;){for(var B=m[x],D=0,P=w-1;(B!==0||D<y)&&P!==-1;P--,D++)B+=256*v[P]>>>0,v[P]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");y=D,x++}for(var R=w-y;R!==w&&v[R]===0;)R++;for(var L=c.repeat(g);R<w;++R)L+=r.charAt(v[R]);return L}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var g=0;if(m[g]!==" "){for(var y=0,x=0;m[g]===c;)y++,g++;for(var E=(m.length-g)*f+1>>>0,w=new Uint8Array(E);m[g];){var v=e[m.charCodeAt(g)];if(v===255)return;for(var B=0,D=E-1;(v!==0||B<x)&&D!==-1;D--,B++)v+=a*w[D]>>>0,w[D]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");x=B,g++}if(m[g]!==" "){for(var P=E-x;P!==E&&w[P]===0;)P++;for(var R=new Uint8Array(y+(E-P)),L=y;P!==E;)R[L++]=w[P++];return R}}}function p(m){var g=d(m);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:d,decode:p}}var gy=yy,by=gy,pl=by;var pc=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},mc=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ml(this,t)}},yc=class{decoders;constructor(t){this.decoders=t}or(t){return ml(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ml(r,t){return new yc({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var gc=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new pc(t,e,n),this.decoder=new mc(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function jr({name:r,prefix:t,encode:e,decode:n}){return new gc(r,t,e,n)}function qe({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=pl(e,r);return jr({prefix:t,name:r,encode:n,decode:s=>Be(o(s))})}function wy(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let h=t[r[f]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|h,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function xy(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ey(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function gt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Ey(n);return jr({prefix:t,name:r,encode(s){return xy(s,n,e)},decode(s){return wy(s,o,e,r)}})}var Sy=qe({prefix:"9",name:"base10",alphabet:"0123456789"});var wc={};st(wc,{base16:()=>Ay,base16upper:()=>vy});var Ay=gt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),vy=gt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var xc={};st(xc,{base2:()=>By});var By=gt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ec={};st(Ec,{base256emoji:()=>_y});var yl=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}"),Ly=yl.reduce((r,t,e)=>(r[e]=t,r),[]),Iy=yl.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Cy(r){return r.reduce((t,e)=>(t+=Ly[e],t),"")}function Ty(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Iy[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var _y=jr({prefix:"\u{1F680}",name:"base256emoji",encode:Cy,decode:Ty});var Sc={};st(Sc,{base32:()=>Wr,base32hex:()=>Py,base32hexpad:()=>Ny,base32hexpadupper:()=>ky,base32hexupper:()=>Uy,base32pad:()=>Ry,base32padupper:()=>Oy,base32upper:()=>Dy,base32z:()=>My});var Wr=gt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Dy=gt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ry=gt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Oy=gt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Py=gt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Uy=gt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ny=gt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ky=gt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),My=gt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ac={};st(Ac,{base36:()=>Hn,base36upper:()=>Ky});var Hn=qe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ky=qe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var vc={};st(vc,{base58btc:()=>le,base58flickr:()=>Fy});var le=qe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Fy=qe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Bc={};st(Bc,{base64:()=>Hy,base64pad:()=>zy,base64url:()=>Vy,base64urlpad:()=>qy});var Hy=gt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),zy=gt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vy=gt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qy=gt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Lc={};st(Lc,{base8:()=>$y});var $y=gt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ic={};st(Ic,{identity:()=>jy});var jy=jr({prefix:"\0",name:"identity",encode:r=>ll(r),decode:r=>hl(r)});var K8=new TextEncoder,F8=new TextDecoder;var Tc={};st(Tc,{identity:()=>mg});var Yy=wl,gl=128,Zy=127,Xy=~Zy,Qy=Math.pow(2,31);function wl(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Qy;)t[e++]=r&255|gl,r/=128;for(;r&Xy;)t[e++]=r&255|gl,r>>>=7;return t[e]=r|0,wl.bytes=e-n+1,t}var Jy=Cc,tg=128,bl=127;function Cc(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Cc.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&bl)<<o:(i&bl)*Math.pow(2,o),o+=7}while(i>=tg);return Cc.bytes=s-n,e}var eg=Math.pow(2,7),rg=Math.pow(2,14),ng=Math.pow(2,21),og=Math.pow(2,28),sg=Math.pow(2,35),ig=Math.pow(2,42),ag=Math.pow(2,49),cg=Math.pow(2,56),fg=Math.pow(2,63),ug=function(r){return r<eg?1:r<rg?2:r<ng?3:r<og?4:r<sg?5:r<ig?6:r<ag?7:r<cg?8:r<fg?9:10},hg={encode:Yy,decode:Jy,encodingLength:ug},lg=hg,zn=lg;function Vn(r,t=0){return[zn.decode(r,t),zn.decode.bytes]}function Gr(r,t,e=0){return zn.encode(r,t,e),t}function Yr(r){return zn.encodingLength(r)}function Xr(r,t){let e=t.byteLength,n=Yr(r),o=n+Yr(e),s=new Uint8Array(o+e);return Gr(r,s,0),Gr(e,s,n),s.set(t,o),new Zr(r,e,t,s)}function xl(r){let t=Be(r),[e,n]=Vn(t),[o,s]=Vn(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Zr(e,o,i,t)}function El(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ul(r.bytes,e.bytes)}}var Zr=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Sl=0,dg="identity",Al=Be;function pg(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Xr(Sl,Al(r))}var mg={code:Sl,name:dg,encode:Al,digest:pg};var Rc={};st(Rc,{sha256:()=>gg,sha512:()=>bg});var yg=20;function Dc({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new _c(r,t,e,n,o)}var _c=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??yg,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?vl(n,this.code,e?.truncate):n.then(o=>vl(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function vl(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Xr(t,r)}function Ll(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var gg=Dc({name:"sha2-256",code:18,encode:Ll("SHA-256")}),bg=Dc({name:"sha2-512",code:19,encode:Ll("SHA-512")});function Il(r,t){let{bytes:e,version:n}=r;return n===0?xg(e,Oc(r),t??le.encoder):Eg(e,Oc(r),t??Wr.encoder)}var Cl=new WeakMap;function Oc(r){let t=Cl.get(r);if(t==null){let e=new Map;return Cl.set(r,e),e}return t}var Is=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==$n)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Sg)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Xr(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&El(t.multihash,n.multihash)}toString(t){return Il(this,t)}toJSON(){return{"/":Il(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Tl(n,o,s.bytes))}else if(e[Ag]===!0){let{version:n,multihash:o,code:s}=e,i=xl(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==$n)throw new Error(`Version 0 CID must use dag-pb (code: ${$n}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Tl(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,$n,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Be(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Zr(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,d]=Vn(t.subarray(e));return e+=d,u},o=n(),s=$n;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,h=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:f}}static parse(t,e){let[n,o]=wg(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Oc(s).set(n,t),s}};function wg(r,t){switch(r[0]){case"Q":{let e=t??le;return[le.prefix,e.decode(`${le.prefix}${r}`)]}case le.prefix:{let e=t??le;return[le.prefix,e.decode(r)]}case Wr.prefix:{let e=t??Wr;return[Wr.prefix,e.decode(r)]}case Hn.prefix:{let e=t??Hn;return[Hn.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function xg(r,t,e){let{prefix:n}=e;if(n!==le.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Eg(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var $n=112,Sg=18;function Tl(r,t,e){let n=Yr(r),o=n+Yr(t),s=new Uint8Array(o+e.byteLength);return Gr(r,s,0),Gr(t,s,n),s.set(e,o),s}var Ag=Symbol.for("@ipld/js-cid/CID");var Pc={...Ic,...xc,...Lc,...bc,...wc,...Sc,...Ac,...vc,...Bc,...Ec},c4={...Rc,...Tc};function Dl(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var _l=Dl("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Uc=Dl("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Pt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),vg={utf8:_l,"utf-8":_l,hex:Pc.base16,latin1:Uc,ascii:Uc,binary:Uc,...Pc},Cs=vg;function de(r,t="utf8"){let e=Cs[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}function Nc(r,t){!t.enabled||!zr||(r?(t(`LOCAL_STATIC_PUBLIC_KEY ${de(r.publicKey,"hex")}`),t(`LOCAL_STATIC_PRIVATE_KEY ${de(r.privateKey,"hex")}`)):t("Missing local static keys."))}function kc(r,t){!t.enabled||!zr||(r?(t(`LOCAL_PUBLIC_EPHEMERAL_KEY ${de(r.publicKey,"hex")}`),t(`LOCAL_PRIVATE_EPHEMERAL_KEY ${de(r.privateKey,"hex")}`)):t("Missing local ephemeral keys."))}function Rl(r,t){!t.enabled||!zr||t(r?`REMOTE_STATIC_PUBLIC_KEY ${de(r.subarray(),"hex")}`:"Missing remote static public key.")}function Mc(r,t){!t.enabled||!zr||t(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${de(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Kc(r,t,e){!e.enabled||!zr||(e(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&de(r.k,"hex")}`),e(`CIPHER_STATE_2 ${t.n.getUint64()} ${t.k&&de(t.k,"hex")}`))}function Qr(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=Pt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function Fc(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Pl=Symbol.for("@achingbrain/uint8arraylist");function Ol(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Ts(r){return!!r?.[Pl]}var pe=class r{bufs;length;[Pl]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Ts(n)){e+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Ts(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ol(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ol(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Ts(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Qr(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Qr(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,h=e>a&&e<=c;if(f&&h){if(t===a&&e===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(h){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ts(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,h;for(let u=e;u<=c;u+=h){h=0;for(let d=f;d>=0;d--){let p=this.get(u+d);if(n[d]!==p){h=Math.max(1,d-a[p]);break}}if(h===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=Pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=At(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=At(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=At(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=Pt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=At(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=At(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=At(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=At(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=At(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Fc(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};function hr(r,t="utf8"){let e=Cs[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var Jr=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Lg=0,Ig=4294967295,Cg="Cipherstate has reached maximum n, a new handshake must be performed",_s=class{n;bytes;view;constructor(t=Lg){this.n=t,this.bytes=At(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Ig)throw new Error(Cg)}};var lr=At(0),tn=class{k;n;crypto;constructor(t,e=void 0,n=0){this.crypto=t,this.k=e,this.n=new _s(n)}hasKey(){return!!this.k}encryptWithAd(t,e){if(!this.hasKey())return e;this.n.assertValue();let n=this.crypto.encrypt(e,this.n.getBytes(),t,this.k);return this.n.increment(),n}decryptWithAd(t,e,n){if(!this.hasKey())return e;this.n.assertValue();let o=this.crypto.decrypt(e,this.n.getBytes(),t,this.k,n);return this.n.increment(),o}},Hc=class{cs;ck;h;crypto;constructor(t,e){this.crypto=t;let n=hr(e,"utf-8");this.h=Tg(t,n),this.ck=this.h,this.cs=new tn(t)}mixKey(t){let[e,n]=this.crypto.hkdf(this.ck,t);this.ck=e,this.cs=new tn(this.crypto,n)}mixHash(t){this.h=this.crypto.hash(new pe(this.h,t))}encryptAndHash(t){let e=this.cs.encryptWithAd(this.h,t);return this.mixHash(e),e}decryptAndHash(t){let e=this.cs.decryptWithAd(this.h,t);return this.mixHash(t),e}split(){let[t,e]=this.crypto.hkdf(this.ck,lr);return[new tn(this.crypto,t),new tn(this.crypto,e)]}},zc=class{ss;s;e;rs;re;initiator;crypto;constructor(t){let{crypto:e,protocolName:n,prologue:o,initiator:s,s:i,e:a,rs:c,re:f}=t;this.crypto=e,this.ss=new Hc(e,n),this.ss.mixHash(o),this.initiator=s,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 t=this.crypto.generateKeypair();return this.ss.mixHash(t.publicKey),this.e=t,t.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(t,e=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(t.byteLength<e+32)throw new Error("message is not long enough");this.re=t.sublist(e,e+32),this.ss.mixHash(this.re)}readS(t,e=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(t.byteLength<e+n)throw new Error("message is not long enough");let o=t.sublist(e,e+n);return this.rs=this.ss.decryptAndHash(o),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},jn=class extends zc{writeMessageA(t){return new pe(this.writeE(),this.ss.encryptAndHash(t))}writeMessageB(t){let e=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new pe(e,n,this.ss.encryptAndHash(t))}writeMessageC(t){let e=this.writeS();return this.writeSE(),new pe(e,this.ss.encryptAndHash(t))}readMessageA(t){try{return this.readE(t),this.ss.decryptAndHash(t.sublist(32))}catch(e){throw new Jr(`handshake stage 0 validation fail: ${e.message}`)}}readMessageB(t){try{this.readE(t),this.readEE();let e=this.readS(t,32);return this.readES(),this.ss.decryptAndHash(t.sublist(32+e))}catch(e){throw new Jr(`handshake stage 1 validation fail: ${e.message}`)}}readMessageC(t){try{let e=this.readS(t);return this.readSE(),this.ss.decryptAndHash(t.sublist(e))}catch(e){throw new Jr(`handshake stage 2 validation fail: ${e.message}`)}}};function Tg(r,t){if(t.length<=32){let e=At(32);return e.set(t),e}else return r.hash(t)}var _g=Math.pow(2,7),Dg=Math.pow(2,14),Rg=Math.pow(2,21),Ul=Math.pow(2,28),Nl=Math.pow(2,35),kl=Math.pow(2,42),Ml=Math.pow(2,49),kt=128,$e=127;function Wn(r){if(r<_g)return 1;if(r<Dg)return 2;if(r<Rg)return 3;if(r<Ul)return 4;if(r<Nl)return 5;if(r<kl)return 6;if(r<Ml)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kl(r,t,e=0){switch(Wn(r)){case 8:t[e++]=r&255|kt,r/=128;case 7:t[e++]=r&255|kt,r/=128;case 6:t[e++]=r&255|kt,r/=128;case 5:t[e++]=r&255|kt,r/=128;case 4:t[e++]=r&255|kt,r>>>=7;case 3:t[e++]=r&255|kt,r>>>=7;case 2:t[e++]=r&255|kt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Fl(r,t){let e=r[t],n=0;if(n+=e&$e,e<kt||(e=r[t+1],n+=(e&$e)<<7,e<kt)||(e=r[t+2],n+=(e&$e)<<14,e<kt)||(e=r[t+3],n+=(e&$e)<<21,e<kt)||(e=r[t+4],n+=(e&$e)*Ul,e<kt)||(e=r[t+5],n+=(e&$e)*Nl,e<kt)||(e=r[t+6],n+=(e&$e)*kl,e<kt)||(e=r[t+7],n+=(e&$e)*Ml,e<kt))return n;throw new RangeError("Could not decode varint")}var Vc=new Float32Array([-0]),je=new Uint8Array(Vc.buffer);function Hl(r,t,e){Vc[0]=r,t[e]=je[0],t[e+1]=je[1],t[e+2]=je[2],t[e+3]=je[3]}function zl(r,t){return je[0]=r[t],je[1]=r[t+1],je[2]=r[t+2],je[3]=r[t+3],Vc[0]}var qc=new Float64Array([-0]),Ut=new Uint8Array(qc.buffer);function Vl(r,t,e){qc[0]=r,t[e]=Ut[0],t[e+1]=Ut[1],t[e+2]=Ut[2],t[e+3]=Ut[3],t[e+4]=Ut[4],t[e+5]=Ut[5],t[e+6]=Ut[6],t[e+7]=Ut[7]}function ql(r,t){return Ut[0]=r[t],Ut[1]=r[t+1],Ut[2]=r[t+2],Ut[3]=r[t+3],Ut[4]=r[t+4],Ut[5]=r[t+5],Ut[6]=r[t+6],Ut[7]=r[t+7],qc[0]}var Og=BigInt(Number.MAX_SAFE_INTEGER),Pg=BigInt(Number.MIN_SAFE_INTEGER),zt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return dr;if(t<Og&&t>Pg)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>$l&&(o=0n,++n>$l&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return dr;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):dr}},dr=new zt(0,0);dr.toBigInt=function(){return 0n};dr.zzEncode=dr.zzDecode=function(){return this};dr.length=function(){return 1};var $l=4294967296n;function jl(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Wl(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function $c(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function ee(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Ds(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var jc=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,ee(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ee(this,4);return Ds(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ee(this,4);return Ds(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ee(this,4);let t=zl(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw ee(this,4);let t=ql(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw ee(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Wl(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw ee(this,t);this.pos+=t}else do if(this.pos>=this.len)throw ee(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new zt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw ee(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw ee(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ee(this,8);let t=Ds(this.buf,this.pos+=4),e=Ds(this.buf,this.pos+=4);return new zt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Fl(this.buf,this.pos);return this.pos+=Wn(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Wc(r){return new jc(r instanceof Uint8Array?r:r.subarray())}function Rs(r,t,e){let n=Wc(r);return t.decode(n,void 0,e)}function Gc(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return Pt(i);o+i>t&&(n=Pt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var pr=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Yc(){}var Xc=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ug=Gc();function Ng(r){return globalThis.Buffer!=null?Pt(r):Ug(r)}var Yn=class{len;head;tail;states;constructor(){this.len=0,this.head=new pr(Yc,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new pr(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Qc((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Os,10,zt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=zt.fromBigInt(t);return this._push(Os,e.length(),e)}uint64Number(t){return this._push(Kl,Wn(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=zt.fromBigInt(t).zzEncode();return this._push(Os,e.length(),e)}sint64Number(t){let e=zt.fromNumber(t).zzEncode();return this._push(Os,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zc,1,t?1:0)}fixed32(t){return this._push(Gn,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=zt.fromBigInt(t);return this._push(Gn,4,e.lo)._push(Gn,4,e.hi)}fixed64Number(t){let e=zt.fromNumber(t);return this._push(Gn,4,e.lo)._push(Gn,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Hl,4,t)}double(t){return this._push(Vl,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Zc,1,0):this.uint32(e)._push(Mg,e,t)}string(t){let e=jl(t);return e!==0?this.uint32(e)._push($c,e,t):this._push(Zc,1,0)}fork(){return this.states=new Xc(this),this.head=this.tail=new pr(Yc,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 pr(Yc,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Ng(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Zc(r,t,e){t[e]=r&255}function kg(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Qc=class extends pr{next;constructor(t,e){super(kg,t,e),this.next=void 0}};function Os(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Gn(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Mg(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Yn.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Kg,t,r),this},Yn.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Fg,t,r),this});function Kg(r,t,e){t.set(r,e)}function Fg(r,t,e){r.length<40?$c(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(hr(r),e)}function Jc(){return new Yn}function Ps(r,t){let e=Jc();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Zn;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Zn||(Zn={}));function tf(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Us(r,t){return tf("message",Zn.LENGTH_DELIMITED,r,t)}var Xn=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ns;(function(r){let t;r.codec=()=>(t==null&&(t=Us((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.webtransportCerthashes!=null)for(let s of e.webtransportCerthashes)n.uint32(10),n.bytes(s);if(e.streamMuxers!=null)for(let s of e.streamMuxers)n.uint32(18),n.string(s);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={webtransportCerthashes:[],streamMuxers:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(o.limits?.webtransportCerthashes!=null&&s.webtransportCerthashes.length===o.limits.webtransportCerthashes)throw new Xn('Decode error - map field "webtransportCerthashes" had too many elements');s.webtransportCerthashes.push(e.bytes());break}case 2:{if(o.limits?.streamMuxers!=null&&s.streamMuxers.length===o.limits.streamMuxers)throw new Xn('Decode error - map field "streamMuxers" had too many elements');s.streamMuxers.push(e.string());break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Ps(e,r.codec()),r.decode=(e,n)=>Rs(e,r.codec(),n)})(Ns||(Ns={}));var Qn;(function(r){let t;r.codec=()=>(t==null&&(t=Us((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.identityKey!=null&&e.identityKey.byteLength>0&&(n.uint32(10),n.bytes(e.identityKey)),e.identitySig!=null&&e.identitySig.byteLength>0&&(n.uint32(18),n.bytes(e.identitySig)),e.extensions!=null&&(n.uint32(34),Ns.codec().encode(e.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={identityKey:At(0),identitySig:At(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.identityKey=e.bytes();break}case 2:{s.identitySig=e.bytes();break}case 4:{s.extensions=Ns.codec().decode(e,e.uint32(),{limits:o.limits?.extensions});break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Ps(e,r.codec()),r.decode=(e,n)=>Rs(e,r.codec(),n)})(Qn||(Qn={}));async function rf(r,t,e){let n=await r.sign(Zl(t));return Qn.encode({identityKey:De(r.publicKey),identitySig:n,extensions:e})}async function nf(r,t,e){try{let n=Qn.decode(r),o=Cn(n.identityKey);if(e?.equals(o)===!1)throw new Error(`Payload identity key ${o} does not match expected remote identity key ${e}`);if(!t)throw new Error("Remote static does not exist");let s=Zl(t);if(!await o.verify(s,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new to(n.message)}}function Zl(r){let t=hr("noise-libp2p-static-key:");return r instanceof Uint8Array?Qr([t,r],t.length+r.length):(r.prepend(t),r)}var ef=class extends ue{stream;handshake;metrics;decoder;constructor(t,e,n){super({log:t.log,inactivityTimeout:t.inactivityTimeout,maxReadBufferLength:t.maxReadBufferLength,direction:t.direction}),this.stream=t,this.handshake=e,this.metrics=n,this.decoder=new As({lengthDecoder:$r,maxBufferSize:16*1024*1024,encodingLength:()=>2});let o=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",o);let s=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",s);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(t){let e=new pe;for(let n=0;n<t.byteLength;n+=65519){let o=n+65519;o>t.byteLength&&(o=t.byteLength);let s;t instanceof Uint8Array?s=this.handshake.encrypt(t.subarray(n,o)):s=this.handshake.encrypt(t.sublist(n,o)),this.metrics?.encryptedPackets.increment(),e.append(qr(s.byteLength)),e.append(s)}return e}decrypt(t){let e=new pe;for(let n=0;n<t.byteLength;n+=65535){let o=n+65535;if(o>t.byteLength&&(o=t.byteLength),o-ac<n)throw new Error("Invalid chunk");let s;t instanceof Uint8Array?s=t.subarray(n,o):s=t.sublist(n,o);let i=t.subarray(n,o-ac);try{let a=this.handshake.decrypt(s,i);this.metrics?.decryptedPackets.increment(),e.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return e}close(t){return this.stream.close(t)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(t){this.stream.abort(t)}sendData(t){return{sentBytes:t.byteLength,canSendMore:this.stream.send(this.encrypt(t))}}};function of(r,t,e){return new ef(r,t,e)}async function Xl(r,t){let{log:e,connection:n,crypto:o,privateKey:s,prologue:i,s:a,remoteIdentityKey:c,extensions:f}=r,h=await rf(s,a.publicKey,f),u=new jn({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Nc(u.s,e),e.trace("Stage 0 - Initiator starting to send first message."),await n.write(u.writeMessageA(lr),t),e.trace("Stage 0 - Initiator finished sending first message."),kc(u.e,e),e.trace("Stage 1 - Initiator waiting to receive first message from responder...");let d=u.readMessageB(await n.read(t));e.trace("Stage 1 - Initiator received the message."),Mc(u.re,e),Rl(u.rs,e),e.trace("Initiator going to check remote's signature...");let p=await nf(d,u.rs,c);e.trace("All good with the signature!"),e.trace("Stage 2 - Initiator sending third handshake message."),await n.write(u.writeMessageC(h),t),e.trace("Stage 2 - Initiator sent message with signed payload.");let[m,g]=u.ss.split();return Kc(m,g,e),{payload:p,encrypt:y=>m.encryptWithAd(lr,y),decrypt:(y,x)=>g.decryptWithAd(lr,y,x)}}async function Ql(r,t){let{log:e,connection:n,crypto:o,privateKey:s,prologue:i,s:a,remoteIdentityKey:c,extensions:f}=r,h=await rf(s,a.publicKey,f),u=new jn({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Nc(u.s,e),e.trace("Stage 0 - Responder waiting to receive first message."),u.readMessageA(await n.read(t)),e.trace("Stage 0 - Responder received first message."),Mc(u.re,e),e.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(u.writeMessageB(h),t),e.trace("Stage 1 - Responder sent the second handshake message with signed payload."),kc(u.e,e),e.trace("Stage 2 - Responder waiting for third handshake message...");let d=u.readMessageC(await n.read(t));e.trace("Stage 2 - Responder received the message, finished handshake.");let p=await nf(d,u.rs,c),[m,g]=u.ss.split();return Kc(m,g,e),{payload:p,encrypt:y=>g.encryptWithAd(lr,y),decrypt:(y,x)=>m.decryptWithAd(lr,y,x)}}var ks=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(t,e={}){let{staticNoiseKey:n,extensions:o,crypto:s,prologueBytes:i}=e,{metrics:a}=t;this.components=t,this.log=t.logger.forComponent("libp2p:noise");let c=s??al;this.crypto=cl(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?fl(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??At(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[fo]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(t,e){let n=t.log?.newScope("noise")??this.log,o=ic(t,{lengthEncoder:qr,lengthDecoder:$r,maxDataLength:65535}),s=await this.performHandshakeInitiator(o,this.components.privateKey,n,e?.remotePeer?.publicKey,e),i=Cn(s.payload.identityKey);return{connection:of(o.unwrap(),s,this.metrics),remoteExtensions:s.payload.extensions,remotePeer:va(i),streamMuxer:e?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(s.payload.extensions?.streamMuxers)}}getStreamMuxer(t){if(t==null||t.length===0)return;let e=this.components.upgrader.getStreamMuxers();if(e!=null)for(let n of t){let o=e.get(n);if(o!=null)return o}if(t.length)throw new gr("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(t,e){let n=t.log?.newScope("noise")??this.log,o=ic(t,{lengthEncoder:qr,lengthDecoder:$r,maxDataLength:65535}),s=await this.performHandshakeResponder(o,this.components.privateKey,n,e?.remotePeer?.publicKey,e),i=Cn(s.payload.identityKey);return{connection:of(o.unwrap(),s,this.metrics),remoteExtensions:s.payload.extensions,remotePeer:va(i),streamMuxer:e?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(s.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(t,e,n,o,s){let i,a=s?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Xl({connection:t,privateKey:e,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},s),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}async performHandshakeResponder(t,e,n,o,s){let i,a=s?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Ql({connection:t,privateKey:e,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},s),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}};function Jl(r={}){return t=>new ks(t,r)}var mr=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};function sf(r){throw new Error("Not implemented")}var af=class extends Es{writer;reader;constructor(t){super(t),this.writer=t.stream.writable.getWriter(),this.reader=t.stream.readable.getReader(),this.writer.closed.then(()=>{this.log("writer closed gracefully")}).catch(e=>{e.message.includes("STOP_SENDING")||e.message.includes("StopSending")?this.onRemoteCloseRead():e.message.includes("RESET_STREAM")||e.message.includes("Reset")?this.onRemoteReset():this.log("writer close promise rejected - %e",e)}),this.readData()}readData(){Promise.resolve().then(async()=>{for(;;){let t=await this.reader.read();if(t.value!=null&&this.onData(t.value),t.done){this.log("remote closed write"),this.onRemoteCloseWrite();return}if(this.readStatus==="paused")break}}).catch(t=>{this.abort(t)}).finally(()=>{this.reader.releaseLock()})}sendData(t){for(let n of t)this.writer.write(n).catch(o=>{this.abort(o)});if(this.log.trace("desired size after sending %d bytes is %d bytes",t.byteLength,this.writer.desiredSize),this.writer.desiredSize==null)return{sentBytes:t.byteLength,canSendMore:!1};let e=this.writer.desiredSize>0;return e||this.writer.ready.then(()=>{this.safeDispatchEvent("drain")},n=>{this.abort(n)}),{sentBytes:t.byteLength,canSendMore:e}}sendReset(t){this.writer.abort(t).catch(e=>{this.log.error("error aborting writer - %e",e)})}async sendCloseWrite(t){this.log("sendCloseWrite closing writer"),await Gt(this.writer.close().catch(()=>{}),t?.signal),this.log("sendCloseWrite closed writer")}async sendCloseRead(t){this.log("sendCloseRead cancelling reader"),await Gt(this.reader.cancel(),t?.signal),this.log("sendCloseRead cancelled reader")}sendPause(){}sendResume(){this.readData()}};function cf(r,t,e,n,o){return new af({...o,stream:r,id:t,direction:e,log:n.newScope(`${e}:${t}`),protocol:""})}var td="/webtransport",ff=class extends xs{webTransport;streamIDCounter;reader;constructor(t,e){super(e,{protocol:td,name:"muxer"}),this.webTransport=t,this.streamIDCounter=0,this.reader=this.webTransport.incomingBidirectionalStreams.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:n,value:o}=await this.reader.read();if(n||o==null)break;this.onRemoteStream(cf(o,String(this.streamIDCounter++),"inbound",this.log,this.streamOptions))}}).catch(n=>{this.log.error("could not create a new stream - %e",n)})}async onCreateStream(t){let e=await this.webTransport.createBidirectionalStream();return t?.signal?.throwIfAborted(),cf(e,String(this.streamIDCounter++),"outbound",this.log,t)}onData(){}sendReset(){this.webTransport.close()}};function ed(r){return{protocol:td,createStreamMuxer(t){return new ff(r,t)}}}var uf=class extends ws{cleanUpWTSession;constructor(t){super(t),this.cleanUpWTSession=t.cleanUpWTSession}sendData(t){return{sentBytes:t.byteLength,canSendMore:!0}}sendReset(){this.cleanUpWTSession("abort")}async sendClose(t){this.cleanUpWTSession("close"),t?.signal?.throwIfAborted()}sendPause(){}sendResume(){}},rd=r=>new uf(r);function nd(r,t){return t.filter(n=>!!r.find(o=>Et(n,o))).length===t.length}var Hg=Object.values(Xe).map(r=>r.decoder).reduce((r,t)=>r.or(t));function zg(r){return me.decode(Hg.decode(r))}function hf(r){if(!ds.matches(r))throw new no("Invalid multiaddr, was not a WebTransport address");let t=[],e;for(let s of r.getComponents())s.name==="certhash"&&t.push(zg(s.value??"")),s.name==="p2p"&&e==null&&(e=gh(s.value??""));let n=wh(r),o=n.host;return n.type==="ip6"&&o.includes(":")&&(o=`[${o}]`),{url:`https://${o}:${n.port}`,certhashes:t,remotePeer:e}}var Ms=class extends ue{writer;reader;constructor(t){super(t),this.writer=t.stream.writable.getWriter(),this.reader=t.stream.readable.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:e,value:n}=await this.reader.read();if(n!=null&&this.onData(n),e)break}}).catch(e=>{this.abort(e)})}async close(t){await Gt(this.writer.close(),t?.signal)}sendData(t){return this.writer.write(t.subarray()).catch(e=>{this.abort(e)}),{sentBytes:t.byteLength,canSendMore:!0}}sendReset(t){this.writer.abort(t).catch(e=>{this.log.error("could not send reset - %e",e)})}sendPause(){}sendResume(){}};var od=globalThis.WebTransport;var lf=class{log;components;config;metrics;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:webtransport"),this.components=t,this.config={...e,certificates:e.certificates??[]},t.metrics!=null&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_webtransport_dialer_events_total",{label:"event",help:"Total count of WebTransport dialer events by type"})})}[Symbol.toStringTag]="@libp2p/webtransport";[pf]=!0;[fo]=["@libp2p/transport"];async dial(t,e){e.signal.throwIfAborted(),this.log("dialing %s",t),e=e??{};let{url:n,certhashes:o,remotePeer:s}=hf(t),i,a,c=()=>{},f=!1,h=!1,u=!1;try{this.metrics?.dialerEvents.increment({pending:!0});let d=new od(`${n}/.well-known/libp2p-webtransport?type=noise`,{serverCertificateHashes:o.map(m=>({algorithm:"sha-256",value:Bt(m.digest)}))});c=m=>{if(!f)try{this.metrics?.dialerEvents.increment({[m]:!0}),d.close()}catch(g){this.log.error("error closing wt session - %e",g)}finally{a!=null&&(a.timeline.close=Date.now()),f=!0}},i=()=>{c(h?"noise_timeout":"ready_timeout")},e.signal.addEventListener("abort",i,{once:!0}),this.log("wait for session to be ready"),e.onProgress?.(new mr("webtransport:wait-for-session")),await Promise.race([d.closed,d.ready]),this.log("session became ready"),h=!0,this.metrics?.dialerEvents.increment({ready:!0}),d.closed.catch(m=>{this.log.error("error on remote wt session close - %e",m)}).finally(()=>{c("remote_close")}),this.metrics?.dialerEvents.increment({open:!0}),a=rd({remoteAddr:t,cleanUpWTSession:c,direction:"outbound",log:this.components.logger.forComponent("libp2p:webtransport:connection")});let p=await this.authenticateWebTransport({wt:d,maConn:a,remotePeer:s,certhashes:o,...e});if(u=!0,s!=null&&(u=s.equals(p)),!u)throw new gr("Failed to authenticate webtransport");return await e.upgrader.upgradeOutbound(a,{...e,skipEncryption:!0,remotePeer:p,muxerFactory:ed(d),skipProtection:!0})}catch(d){throw this.log.error("caught wt session err - %e",d),c(u?"upgrade_error":h?"noise_error":"ready_error"),d}finally{i!=null&&e.signal?.removeEventListener("abort",i)}}async authenticateWebTransport({wt:t,maConn:e,remotePeer:n,certhashes:o,onProgress:s,signal:i}){s?.(new mr("webtransport:open-authentication-stream"));let a=await t.createBidirectionalStream();i?.throwIfAborted();let c=new Ms({stream:a,log:e.log.newScope("muxer")}),f=Jl()(this.components);s?.(new mr("webtransport:secure-outbound-connection"));let{remoteExtensions:h,remotePeer:u}=await f.secureOutbound(c,{signal:i,remotePeer:n,skipStreamMuxerNegotiation:!0});if(s?.(new mr("webtransport:close-authentication-stream")),await c.close({signal:i}),!nd(h?.webtransportCerthashes??[],o.map(d=>d.bytes)))throw new rt("Our certhashes are not a subset of the remote's reported certhashes");return u}createListener(t){return sf(this.components,{...t,certificates:this.config.certificates})}listenFilter(){return[]}dialFilter(t){return globalThis.WebTransport==null?[]:t.filter(e=>{if(!ds.exactMatch(e))return!1;let{url:n,certhashes:o}=hf(e);return n!=null&&o.length>0})}};function Vg(r={}){return t=>new lf(t,r)}return ld(qg);})();
2
+ "use strict";var Libp2PWebtransport=(()=>{var Zs=Object.defineProperty;var tl=Object.getOwnPropertyDescriptor;var rl=Object.getOwnPropertyNames;var nl=Object.prototype.hasOwnProperty;var Re=(t,e)=>{for(var r in e)Zs(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&&Zs(t,s,{get:()=>e[s],enumerable:!(n=tl(e,s))||n.enumerable});return t};var ol=t=>sl(Zs({},"__esModule",{value:!0}),t);var ym={};Re(ym,{webTransport:()=>mm});var Bn=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 _n=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"}},Ot=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Tn=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},Cn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},In=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 Dn=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}},Rn=class extends ar{constructor(e,r){super(!0,e,r)}},On=class extends ar{constructor(e,r){super(!1,e,r)}};var Xs=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 Qs(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 Qs(t).capture===Qs(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=Qs(n);if(s?.signal?.aborted===!0)return;let o=u=>{s.once&&this.removeEventListener(e,r,s),il(r)?r.handleEvent(u):r(u)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(u=>u.callback!==r?!1:$a(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&&$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 Pn=Symbol.for("@libp2p/service-capabilities");var no={};Re(no,{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 ul(t){return t?.buffer instanceof ArrayBuffer}function Ut(t){return ul(t)?t:t.slice()}function fl(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,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%f>>>0,U=U/f>>>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+=f*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=fl,hl=ll,Za=hl;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=>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 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 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 ur({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 so={};Re(so,{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 oo={};Re(oo,{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:()=>ao,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=io,Dl=128,Ja=127;function io(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw io.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 io.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 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 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 ao(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,co(t),e??me.encoder):Wl(r,co(t),e??bt.encoder)}var rc=new WeakMap;function co(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&&ao(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(),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]=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 co(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 fr(t,o,0),fr(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 fo(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 fo(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 Nn(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(Nn(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(Nn(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(Nn(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 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(!Nn(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(!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 lo={};Re(lo,{base10:()=>eh});var eh=gt({prefix:"9",name:"base10",alphabet:"0123456789"});var ho={};Re(ho,{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 po={};Re(po,{base2:()=>nh});var nh=pe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mo={};Re(mo,{base256emoji:()=>ch});var uc=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=uc.reduce((t,e,r)=>(t[r]=e,t),[]),oh=uc.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=ur({prefix:"\u{1F680}",name:"base256emoji",encode:ih,decode:ah});var go={};Re(go,{base64:()=>uh,base64pad:()=>fh,base64url:()=>yo,base64urlpad:()=>lh});var uh=pe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),fh=pe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yo=pe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),lh=pe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bo={};Re(bo,{base8:()=>hh});var hh=pe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wo={};Re(wo,{identity:()=>dh});var dh=ur({prefix:"\0",name:"identity",encode:t=>Ya(Me(t)),decode:t=>Me(Wa(t))});var O0=new TextEncoder,P0=new TextDecoder;var So={};Re(So,{sha256:()=>Hr,sha512:()=>gh});var yh=20;function Eo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new xo(t,e,r,n,s)}var xo=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?fc(n,this.code,r?.truncate):n.then(s=>fc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function fc(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=Eo({name:"sha2-256",code:18,encode:hc("SHA-256")}),gh=Eo({name:"sha2-512",code:19,encode:hc("SHA-512")});var kt={...wo,...po,...bo,...lo,...ho,...so,...oo,...no,...go,...mo},j0={...So,...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))),vo=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:vo,ascii:vo,binary:vo,...kt},kn=bh;function ee(t,e="utf8"){let r=kn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function W(t,e="utf8"){let r=kn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var wh=parseInt("11111",2),Ao=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]&Ao)===Ao){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 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 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 Bo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=_h(t.byteLength);return new Q(Uint8Array.from([e.byteLength|Ao]),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]),Bo(e),e)}function Mn(t){let e=Uint8Array.from([0]),r=new Q(e,t);return new Q(Uint8Array.from([3]),Bo(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]),Bo(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"},_o=32,Lo=48,To=66;function Co(t){let e=it(t);return yc(e)}function yc(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===_o*2+1)return n=W(e.subarray(r,r+_o),"base64url"),s=W(e.subarray(r+_o),"base64url"),new dr({...Ih,key_ops:["verify"],x:n,y: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({...Dh,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({...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([Mn(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 Kn=BigInt(4294967295),bc=BigInt(32);function Ph(t,e=!1){return e?{h:Number(t&Kn),l:Number(t>>bc&Kn)}:{h:Number(t>>bc&Kn)|0,l:Number(t&Kn)|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 Io=(t,e,r)=>t>>>r,Do=(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 Fn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Ro=t=>t?`"${t}" `:"";function We(t,e=""){if(typeof t!="number")throw new TypeError(Ro(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Ro(e)+"expected integer >= 0, got "+t);return t}function Oe(t,e,r=""){if(Fn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&We(e,"length");let n=Fn(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=Ro(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 Hn(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 qn(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 zn(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 $n(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 Oo(...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 Po(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 Uo=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=qn(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 u=qn(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){pr(this),Hn(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:qn(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()}},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),No=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:u,H:f}=this;for(let l=0;l<64;l++){let d=Ye(a,6)^Ye(a,11)^Ye(a,25),p=f+d+Dc(a,c,u)+Hh[l]+Et[l]|0,b=(Ye(n,2)^Ye(n,13)^Ye(n,22))+Rc(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(){Fe(Et)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Fe(this.buffer)}},ko=class extends No{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),Mo=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:u,El:f,Fh:l,Fl:d,Gh:p,Gl:g,Hh:b,Hl:y}=this;return[e,r,n,s,o,i,a,c,u,f,l,d,p,g,b,y]}set(e,r,n,s,o,i,a,c,u,f,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=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=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)^Io(I,T,7),M=Kt(I,T,1)^Kt(I,T,8)^Do(I,T,7),U=St[w-2]|0,C=vt[w-2]|0,D=Mt(U,C,19)^$r(U,C,61)^Io(U,C,6),F=Kt(U,C,19)^Vr(U,C,61)^Do(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:u,Dl:f,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(u|0,f|0,C|0,D|0),u=a|0,f=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:u,l:f}=Xe(this.Dh|0,this.Dl|0,u|0,f|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,u,f,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)}},Ko=class extends Mo{constructor(){super(64,Pc)}};var Qe=Po(()=>new ko,Uo(1));var Fo=Po(()=>new Ko,Uo(3));function jn(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),Ho=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=zn,He=(...t)=>Oo(...t),mr=t=>$n(t),_t=Fn,at=t=>Ic(t),Vn=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 Wn(t){if(typeof t=="bigint"){if(!Bt(t))throw new RangeError("positive bigint expected, got "+t)}else Ho(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=Wn(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===""?Vn:BigInt("0x"+t)}function Je(t){return Mc(zn(t))}function et(t){return Mc(zn(Lt(Oe(t)).reverse()))}function Yn(t,e){if(We(e),e===0)throw new Error("zero output length is invalid");t=Wn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return $n(n.padStart(r,"0"))}function Gr(t,e){return Yn(t,e).reverse()}function Lt(t){return Uint8Array.from(Z(t))}function Bt(t){return typeof t=="bigint"&&Vn<=t}function qo(t,e,r){return Bt(t)&&Bt(e)&&Bt(r)&&e<=t&&t<r}function tt(t,e,r,n){if(!qo(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function yr(t){if(t<Vn)throw new Error("expected non-negative bigint, got "+t);return t===Vn?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),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...y)=>r(u,He(c,...y)),p=(y=s)=>{u=d(o,y),c=d(),y.length!==0&&(u=d(i,y),c=d())},g=()=>{if(f++>=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 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),te=BigInt(1),Tt=BigInt(2),qc=BigInt(3),zo=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>>=zo;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 ue(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,u=s-o*a;n=r,r=c,s=o,o=u}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 $o(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Vo(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)/zo,s=r.pow(e,n);return $o(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 $o(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 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 y=u.eql(u.sqr(l),c),x=u.cmov(f,l,y);return $o(u,x,c),x})}function Gc(t){if(t<qc)throw new Error("sqrt is not defined for small field");Vo(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,u){let f=c;if(f.is0(u))return u;if(Xr(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,y=f.sqr(p);for(;!f.eql(y,f.ONE);)if(b++,y=f.sqr(y),b===l)throw new Error("Cannot find square root");let x=te<<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 Xh(t){return Vo(t,"Fp.sqrt"),t%zo===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 Zn(t,e,r=!1){gr(t),jn(e,"nums"),Ne(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 Xr(t,e){gr(t);let r=t;Vo(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&&Ho(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,Gn=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):Yn(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?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 Zn(this,e,!0)}cmov(e,r,n){return Ne(n,"condition"),n?r:e}};function br(t,e={}){return Object.freeze(Gn.prototype),new Gn(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 Xn(t){let e=Xc(t);return e+Math.ceil(e/2)}function Qn(t,e,r=!1){Z(t);let n=t.length,s=Xc(e),o=Math.max(Xn(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):Yn(a,s)}var Yo=BigInt(0),Qr=BigInt(1),ed=BigInt(4),jo=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 Jn(t,e){Ct(t),tu(e,t);let r=Zn(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 Go(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 tu(t,e){jn(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 ru=new WeakMap;function Wo(t){return ru.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>Yo;){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 u=Number(t&o);t>>=i,u>s&&(u-=n,t+=Qr),a.push(u)}if(t!==Yo)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=Go(r,jo),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=ad(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 y=1;y<i;y++)g=y===p?o[d+y]: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),!qo(r,Qr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Wo(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(jo);if(!_t(o)||o.length!==jo)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 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===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=Wo(e);if(s===1||r>=this.Point.Fn.ORDER)return es(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),ru.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Wo(e)!==1}};function es(t,e,r,n=!1){if(Ct(t),tu(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 eu(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 ts(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 u=e[c];if(!(Bt(u)&&u!==Yo))throw new Error(`CURVE.${c} must be positive bigint`)}let s=eu(e.p,r.Fp,n),o=eu(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 rs=BigInt(0),ns=BigInt(1),ss=BigInt(2),ud=BigInt(4),nu=BigInt(8);function fd(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 su(t,e={}){Le(e,{},{},"extraOpts");let r=e,n=ts("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,u=ss<<BigInt(s.BYTES*8)-ns;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:rs}}}:r.uvRatio;if(!fd(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?ns:rs;return tt("coordinate "+E,w,T,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,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?u:s.ORDER;tt("point.y",D,rs,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=f(_),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(ss),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),ss),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===rs?b.ZERO:this.is0()||w===ns?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(nu):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===ns?this:a===ss?this.double():a===ud?this.double().double():a===nu?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:w,y:I}=this.toAffine(),T=s.toBytes(I);return T[T.length-1]|=f(w)?128:0,T}toHex(){return Wr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=E=>Jn(b,E),x=new wr(b,c);return x.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function ou(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,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(ct(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);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),os=BigInt(2);function iu(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 au(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 u=i===void 0?at:i,f=c?255:448,l=ld(r),d=c?32:56,p=BigInt(c?9:5),g=BigInt(c?121665:39081),b=c?os**BigInt(254):os**BigInt(447),y=c?BigInt(8)*(os**BigInt(251)-qe):BigInt(4)*(os**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(f-1);q>=qt;q--){let z=iu(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=iu(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?u(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 cu=BigInt(0),Zo=BigInt(1),uu=BigInt(2),dd=BigInt(3),pd=BigInt(5),md=BigInt(8),is=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yd={p:is,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:md,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function hu(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=is,a=t*t%o*t%o,c=ue(a,uu,o)*a%o,u=ue(c,Zo,o)*t%o,f=ue(u,pd,o)*u%o,l=ue(f,e,o)*f%o,d=ue(l,r,o)*l%o,p=ue(d,n,o)*d%o,g=ue(p,s,o)*p%o,b=ue(g,s,o)*p%o,y=ue(b,e,o)*f%o;return{pow_p_5_8:ue(y,uu,o)*t%o,b2:a}}function Xo(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var fu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function gd(t,e){let r=is,n=ne(e*e*e,r),s=ne(n*n*e,r),o=hu(t*s).pow_p_5_8,i=ne(t*n*o,r),a=ne(e*i*i,r),c=i,u=ne(i*fu,r),f=a===t,l=a===ne(-t,r),d=a===ne(-t*fu,r);return f&&(i=c),(l||d)&&(i=u),Zc(i,r)&&(i=ne(-i,r)),{isValid:f||l,value:i}}var Jr=su(yd,{uvRatio:gd}),lu=Jr.Fp;function bd(t){let{y:e}=t;return lu.toBytes(lu.div(Zo+e,Zo-e))}function wd(t){let e=Jr.Fp.BYTES;return Oe(t,e),Xo(Fo(t.subarray(0,e))).subarray(0,e)}function xd(t){return ou(Jr,Fo,Object.assign({adjustScalarBytes:Xo,toMontgomery:bd,toMontgomerySecret:wd,zip215:!0},t))}var du=xd({});var en=(()=>{let t=is,e=r=>{let{pow_p_5_8:n,b2:s}=hu(r);return ne(ue(n,dd,t)*s,t)};return au({P:t,type:"x25519",powPminus2:e,adjustScalarBytes:Xo,scalarMultBase:r=>{let n=ne(r,Jr.Fn.ORDER);if(n===cu)return cu;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"}},as=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 as("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 cs=32;var Qo,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 du.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function pu(t,e,r){return Qo==null&&(Qo=await Ed),Qo?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 fs=class{type="Ed25519";raw;constructor(e){this.raw=Jo(e,cs)}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=pu(this.raw,r,e);return us(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function ei(t){return t=Jo(t,cs),new fs(t)}function Jo(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),ti=Math.pow(2,28),ri=Math.pow(2,35),ni=Math.pow(2,42),si=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<ti)return 4;if(t<ri)return 5;if(t<ni)return 6;if(t<si)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 oi(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)*ti,r<re)||(r=t[e+5],n+=(r&Te)*ri,r<re)||(r=t[e+6],n+=(r&Te)*ni,r<re)||(r=t[e+7],n+=(r&Te)*si,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)*ti,r<re)||(r=t.get(e+5),n+=(r&Te)*ri,r<re)||(r=t.get(e+6),n+=(r&Te)*ni,r<re)||(r=t.get(e+7),n+=(r&Te)*si,r<re))return n;throw new RangeError("Could not decode varint")}function yu(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?oi(t,e):Cd(t,e)}var ai=new Float32Array([-0]),It=new Uint8Array(ai.buffer);function gu(t,e,r){ai[0]=t,e[r]=It[0],e[r+1]=It[1],e[r+2]=It[2],e[r+3]=It[3]}function bu(t,e){return It[0]=t[e],It[1]=t[e+1],It[2]=t[e+2],It[3]=t[e+3],ai[0]}var ci=new Float64Array([-0]),Ie=new Uint8Array(ci.buffer);function wu(t,e,r){ci[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 xu(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],ci[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>Eu&&(s=0n,++n>Eu&&(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 Eu=4294967296n;function Su(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 vu(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 ls(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var fi=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 ls(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ge(this,4);return ls(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ge(this,4);let e=bu(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ge(this,4);let e=xu(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 vu(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=ls(this.buf,this.pos+=4),r=ls(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=oi(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 fi(t instanceof Uint8Array?t:t.subarray())}function Vt(t,e,r){let n=rn(t);return e.decode(n,void 0,r)}function li(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 hi(){}var pi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Rd=li();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(hi,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 mi((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(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(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(di,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(gu,4,e)}double(e){return this._push(wu,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(di,1,0):this.uint32(r)._push(Ud,r,e)}string(e){let r=Su(e);return r!==0?this.uint32(r)._push(ui,r,e):this._push(di,1,0)}fork(){return this.states=new pi(this),this.head=this.tail=new jt(hi,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(hi,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 di(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 mi=class extends jt{next;constructor(e,r){super(Pd,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 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 yi(){return new sn}function Wt(t,e){let r=yi();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 ds={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function ps(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function gi(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){let a=i.int32();yield e(a)};return ps("enum",ds.VARINT,r,n,s)}function Gt(t,e,r){return ps("message",ds.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 bi;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(bi||(bi={}));(function(t){t.codec=()=>gi(bi)})(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={},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 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 wi;(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={},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 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})(wi||(wi={}));var an={};Re(an,{MAX_RSA_KEY_SIZE:()=>xi,generateRSAKeyPair:()=>Cu,jwkToJWKKeyPair:()=>Iu,jwkToPkcs1:()=>Hd,jwkToPkix:()=>Ai,jwkToRSAPrivateKey:()=>Ti,pkcs1MessageToJwk:()=>Si,pkcs1MessageToRSAPrivateKey:()=>Bi,pkcs1ToJwk:()=>Fd,pkcs1ToRSAPrivateKey:()=>Tu,pkixMessageToJwk:()=>vi,pkixMessageToRSAPublicKey:()=>Li,pkixToJwk:()=>qd,pkixToRSAPublicKey:()=>_i});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 Lu(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 _u(this.jwk,e,r)}};var xi=8192,Ei=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 Si(e)}function Si(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 vi(e)}function vi(t){let e=it(t[1],{offset:0});return{kty:"RSA",n:W(e[0],"base64url"),e:W(e[1],"base64url")}}function Ai(t){if(t.n==null||t.e==null)throw new se("JWK was missing components");return wt([Kd,Mn(wt([Ue(ee(t.n,"base64url")),Ue(ee(t.e,"base64url"))]))]).subarray()}function Tu(t){let e=it(t);return Bi(e)}function Bi(t){let e=Si(t);return Ti(e)}function _i(t,e){if(t.byteLength>=Md)throw new ir("Key size is too large");let r=it(t,{offset:0});return Li(r,t,e)}function Li(t,e,r){let n=vi(t);if(r==null){let s=Qe(rt.encode({Type:de.RSA,Data:e}));r=Ve(Ei,s)}return new Sr(n,r)}function Ti(t){if(Ru(t)>xi)throw new se("Key size is too large");let e=Iu(t),r=Qe(rt.encode({Type:de.RSA,Data:Ai(e.publicKey)})),n=Ve(Ei,r);return new on(e.privateKey,new Sr(e.publicKey,n))}async function Cu(t){if(t>xi)throw new se("Key size is too large");let e=await Du(t),r=Qe(rt.encode({Type:de.RSA,Data:Ai(e.publicKey)})),n=Ve(Ei,r);return new on(e.privateKey,new Sr(e.publicKey,n))}function Iu(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 Du(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 _u(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 Lu(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 Ru(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 ms=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),Hn(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 ms(e,r).update(n).digest());return t.create=(e,r)=>new ms(e,r),t})();var $d=BigInt(0),Ci=class extends Error{constructor(e=""){super(e)}},ut={Err:Ci,_tlv:{encode:(t,e)=>{let{Err:r}=ut;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}=ut;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}=ut;if(Wn(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}=ut;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}=ut;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: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}=ut;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)}},ys=(Object.freeze(ut._tlv),Object.freeze(ut._int),Object.freeze(ut));var Ou=(t,e)=>(t+(t>=0?e:-e)/Pu)/e;function Vd(t,e,r){tt("scalar",t,ft,r);let[[n,s],[o,i]]=e,a=Ou(i*t,r),c=Ou(-s*t,r),u=t-a*n-c*o,f=-a*s-c*i,l=u<ft,d=f<ft;l&&(u=-u),d&&(f=-f);let p=Zr(Math.ceil(yr(r)/2))+Xt;if(u<ft||u>=p||f<ft||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Ri(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ii(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&&Ri(r.format),r}var ft=BigInt(0),Xt=BigInt(1),Pu=BigInt(2),Di=BigInt(3),jd=BigInt(4);function Uu(t,e={}){let r=ts("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:u,clearCofactor:f,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=ku(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(!u)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(Nu(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(u&&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,Di),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,Di),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(Di),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(_.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===ft||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),es(A,R,N)}mulAddUnsafe(h,m,v){$(m);let R=[],N=[];return P(R,N,this,h),P(R,N,m,v),es(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:f?f(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=>Jn(A,S),L=new wr(A,g);return L.bits>=6&&A.BASE.precompute(6),Object.freeze(A.prototype),Object.freeze(A),A}function Nu(t){return Uint8Array.of(t?2:3)}function ku(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(ku(t.Fp,r),{seed:Math.max(Xn(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,Qn(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: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 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 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:f,keygen:d,Point:t,utils:l,lengths:s})}function Mu(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:u,BITS:f}=c,l=Xn(u),d=Go(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=u*Pu+Xt<a.ORDER;function I(S){let h=u>>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){Ri(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 ys.Err("invalid signature: DER signature too long");let{r:q,s:z}=ys.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+u: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(Nu((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(Ri(h),h==="der")return mr(ys.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-f;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(f);function B(S){return tt("num < 2^"+f,S,ft,$),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}=Ii(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===ft)return;let he;if(d!==void 0){let mt=Je(Qn(d(l),u)),Qf=c.inv(c.mul(mt,ye)),Jf=c.mul(mt,Y),el=c.mul(mt,q);he=c.create(Qf*c.create(Jf+el*ae))}else{let mt=Wc(ye,u);he=c.create(mt*c.create(Y+ae*q))}if(he===ft)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}=Ii(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}=Ii(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 Pi={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 Ku=BigInt(2);function Gd(t){let e=Pi.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=ue(f,r,e)*f%e,d=ue(l,r,e)*f%e,p=ue(d,Ku,e)*u%e,g=ue(p,s,e)*p%e,b=ue(g,o,e)*g%e,y=ue(b,a,e)*b%e,x=ue(y,c,e)*y%e,E=ue(x,a,e)*b%e,w=ue(E,r,e)*f%e,I=ue(w,i,e)*g%e,T=ue(I,n,e)*u%e,O=ue(T,Ku,e);if(!Oi.eql(Oi.sqr(O),t))throw new Error("Cannot find square root");return O}var Oi=br(Pi.p,{sqrt:Gd}),Zd=Uu(Pi,{Fp:Oi,endo:Yd}),vr=Mu(Zd,Qe);function Fu(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 gs=class{type="secp256k1";raw;_key;constructor(e){this._key=qu(e),this.raw=Hu(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 Fu(this._key,r,e,n)}};function Ui(t){return new gs(t)}function Hu(t){return vr.Point.fromBytes(t).toBytes()}function qu(t){try{return vr.Point.fromBytes(t),t}catch(e){throw new ir(String(e))}}function un(t,e){let{Type:r,Data:n}=rt.decode(t),s=n??new Uint8Array;switch(r){case de.RSA:return _i(s,e);case de.Ed25519:return ei(s);case de.secp256k1:return Ui(s);case de.ECDSA:return Co(s);default:throw new Pt}}function zu(t){let{Type:e,Data:r}=rt.decode(t.digest),n=r??new Uint8Array;switch(e){case de.Ed25519:return ei(n);case de.secp256k1:return Ui(n);case de.ECDSA:return Co(n);default:throw new Pt}}function xt(t){return rt.encode({Type:de[t.type],Data:t.raw})}var $u=Symbol.for("nodejs.util.inspect.custom"),Xd=114,fn=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()})`}[Xs]=!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")}[$u](){return`PeerId(${this.toString()})`}},ln=class extends fn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},hn=class extends fn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},dn=class extends fn{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))}[$u](){return`PeerId(${this.url})`}[Xs]=!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,Vu=2336;function ju(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 Wu(r)}function Ni(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 Wu(t){if(rp(t))return new ln({multihash:t});if(tp(t))try{let e=zu(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 In("Supplied PeerID Multihash is invalid")}function ep(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Jd&&t.code!==Vu)throw new Cn("Supplied PeerID CID is invalid");if(t.code===Vu){let e=W(t.multihash.digest);return new pn(new URL(e))}return Wu(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 Yu(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 bs=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 sp=45,op=15,ws=new bs;function Gu(t){if(!(t.length>op))return ws.new(t).parseWith(()=>ws.readIPv4Addr())}function Zu(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>sp))return ws.new(t).parseWith(()=>ws.readIPv6Addr())}function xs(t){return!!Gu(t)}function Xu(t){return!!Zu(t)}var Be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},lt=class extends Error{static name="ValidationError";name="ValidationError"},Es=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ss=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 Qu(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 Ju(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},ef=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let o=xs(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},tf=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(".")},rf=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 nf(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 sf(t){return ip.decode(t)}function of(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 up(t){return e=>{if(e>t)throw new lt(`Value must be smaller than or equal to ${t}`)}}function fp(...t){return e=>{for(let r of t)r(e)}}var mn=fp(ap,cp,up(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 Ss(`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:tf,validate:t=>{if(!xs(t))throw new lt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:273,name:"udp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:33,name:"dccp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:41,name:"ip6",size:128,valueToBytes:ef,bytesToValue:rf,stringToValue:nf,validate:t=>{if(!Xu(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:mn},{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:Qu},{code:445,name:"onion3",size:296,bytesToValue:Fi,valueToBytes:Ju},{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:of(yo),valueToBytes:sf},{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 af(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,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 cf(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 u=new Uint8Array(o+c+a),f=0;Er(n.code,u,f),f+=o,i!=null&&(s.size===ve&&(Er(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ke(r,e)}function uf(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 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 ff(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="/"),lf(t))return t.getComponents();if(t instanceof Uint8Array)return af(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),uf(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=cf(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=ff(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 Es(`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 lf(t){return!!t?.[ia]}var fe=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)}}),hf=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),Cs=V(54),Is=V(55),Ds=V(56),ca=V(53),t1=le(Cs,G(V(421))),r1=le(Is,G(V(421))),n1=le(Ds,G(V(421))),s1=le(De(ca,Ds,Cs,Is),G(V(421))),df=J(V(4),G(V(43))),pf=J(G(V(42)),V(41),G(V(43))),ua=De(df,pf),Tr=De(ua,ca,Cs,Is,Ds),o1=le(De(ua,J(De(ca,Ds,Cs,Is),G(V(421))))),i1=le(df),a1=le(pf),c1=le(ua),fa=J(Tr,V(6)),yn=J(Tr,V(273)),u1=le(J(fa,G(V(421)))),f1=le(yn),la=J(yn,fe(460),G(V(421))),Rs=J(yn,fe(461),G(V(421))),Ip=De(la,Rs),l1=le(la),h1=le(Rs),aa=De(Tr,fa,yn,la,Rs),mf=De(J(aa,fe(477),G(V(421)))),d1=le(mf),yf=De(J(aa,fe(478),G(V(421))),J(aa,fe(448),G(V(449)),fe(477),G(V(421)))),p1=le(yf),gf=J(yn,fe(280),G(V(466)),G(V(466)),G(V(421))),m1=le(gf),bf=J(Rs,fe(465),G(V(466)),G(V(466)),G(V(421))),Os=le(bf),Ts=De(mf,yf,J(fa,G(V(421))),J(Ip,G(V(421))),J(Tr,G(V(421))),gf,bf,V(421)),y1=le(Ts),Dp=J(G(Ts),fe(290),hf(fe(281)),G(V(421))),g1=le(Dp),Rp=De(J(Ts,fe(290),fe(281),G(V(421))),J(Ts,fe(281),G(V(421))),J(fe(281),G(V(421)))),b1=le(Rp),Op=J(Tr,De(J(V(6,"80")),J(V(6),fe(480)),fe(480)),G(V(481)),G(V(421))),w1=le(Op),Pp=J(Tr,De(J(V(6,"443")),J(V(6,"443"),fe(480)),J(V(6),fe(443)),J(V(6),fe(448),fe(480)),J(fe(448),fe(480)),fe(448),fe(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 Ps(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Us=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 Us(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 Us(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 Ns(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=Ps(),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=Ps()})}},u=y=>o!=null?o(y):(n.push(y),s),f=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 u({done:!1,value:y})},d=y=>i?s:(i=!0,y!=null?f(y):u({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)}},wf=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,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(wf(i));return}if(i&&(c=()=>{d(wf(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(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}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:u,removeListener:f}=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)f(p,l);for(let p of r.rejectionEvents)a.includes(p)||f(p,d)};for(let p of a)u(p,l);for(let p of r.rejectionEvents)a.includes(p)||u(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"},ks=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},Ms=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;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 Ms)};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](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Ns(),r=o=>{e.push(o.data)};this.addEventListener("message",r);let n=o=>{e.end(o.error)};this.addEventListener("close",n);let s=()=>{e.end()};this.addEventListener("remoteCloseWrite",s);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}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.log.error("abort with error - %e",e),this.status="aborted",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 Rn(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(){this.log("remote reset"),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 On(new Ln))}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.#e||this.readBuffer.byteLength>0||this.remoteWriteStatus!=="closed"&&this.readStatus!=="closed"||(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 Dn(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 Ks=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 xf(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Fs=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 _n;let r=this.onCreateStream({...this.streamOptions,...e});return xf(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 ks(`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 Hs=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){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.maybeDispatchEnd(),this.log("closed readable end gracefully"))}};var qp=4194304,qs=class extends Error{static name="UnwrappedError";name="UnwrappedError"},gn=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(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 u=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(o===!0)throw new qs("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 f.read(l)}let g=n.sublist(0,p);return n.consume(p),g},async write(l,d){if(o===!0)throw new qs("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",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return f}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??yu;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 gn("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 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 er(`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 er(`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 Wp=1024*1024*4,Yp=1024*1024*4,zs=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 gn("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 $s=t=>t?`"${t}" `:"";function Vs(t,e=""){if(typeof t!="boolean")throw new TypeError($s(e)+"expected boolean, got type="+typeof t);return t}function tr(t,e=""){if(typeof t!="number")throw new TypeError($s(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError($s(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=$s(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}var Ef=(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 Sf(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 vf(t,e){if(Qp(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function Af(t,e){return Ef(t,"defaults"),Ef(e,"opts"),Object.assign(t,e)}function Bf(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 _f(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 Lf=(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")}},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 bn(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(ge(e,t,"output"),r&&!wn(e))throw new Error("invalid output, must be aligned");return e}function Tf(t,e,r){tr(t),tr(e),Vs(r);let n=new Uint8Array(16),s=Gp(n);return s.setBigUint64(0,BigInt(e),r),s.setBigUint64(8,BigInt(t),r),n}function wn(t){return t.byteOffset%4===0}function Dr(t){return Uint8Array.from(ge(t))}var If=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),Jp=pt(st(If("expand 16-byte k"))),em=pt(st(If("expand 32-byte k")));function X(t,e){return t<<e|t>>>32-e}var xn=64,tm=16,Sa=2**32-1,Cf=Uint32Array.of();function rm(t,e,r,n,s,o,i,a){let c=s.length,u=new Uint8Array(xn),f=st(u),l=Rt&&wn(s)&&wn(o),d=l?st(s):Cf,p=l?st(o):Cf;if(!Rt){for(let g=0;g<c;i++){if(t(e,r,n,f,i,a),pt(f),i>=Sa)throw new Error("arx: counter overflow");let b=Math.min(xn,c-g);for(let y=0,x;y<b;y++)x=g+y,o[x]=s[x]^u[y];g+=b}return}for(let g=0;g<c;i++){if(t(e,r,n,f,i,a),i>=Sa)throw new Error("arx: counter overflow");let b=Math.min(xn,c-g);if(l&&b===xn){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]^f[x];g+=xn;continue}for(let y=0,x;y<b;y++)x=g+y,o[x]=s[x]^u[y];g+=b}}function Df(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Af({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),Vs(o),Vs(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=bn(d,f,!1),p&&vf(u,f),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||!wn(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,u,f,l,i),f}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),u=_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|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=_e(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],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*f)+A*(5*u)+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*f)+H*(5*u),L+=h>>>13,h&=8191;let m=L+C*u+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*f),L+=m>>>13,m&=8191;let v=L+C*f+D*u+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*f+F*u+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*f+K*u+$*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*f+$*u;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+$*f;L=q>>>13,q&=8191,q+=B*u+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*f+P*u+_*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*f+_*u+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),Sf(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}},Rf=_f(32,t=>new va(t));function nm(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],y=e[6],x=e[7],E=s,w=r[0],I=r[1],T=r[2],O=i,M=a,U=c,C=u,D=f,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++]=u+C|0,n[m++]=f+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=Df(nm,{counterRight:!1,counterLength:4,allowShortKeys:!1});var om=new Uint8Array(16),Of=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(om.subarray(r))},im=new Uint8Array(32);function Pf(t,e,r,n,s){s!==void 0&&ge(s,void 0,"AAD");let o=t(e,r,im),i=Tf(n.length,s?s.length:0,!0),a=Rf.create(o);s&&Of(a,s),Of(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=bn(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);t(e,r,c,c,1);let u=Pf(t,e,r,c,n);return i.set(u,a),Ze(u),i},decrypt(o,i){i=bn(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),u=Pf(t,e,r,a,n);if(!Bf(c,u))throw Ze(u),new Error("invalid tag");return i.set(o.subarray(0,-16)),t(e,r,i,i,1),Ze(u),i}}),Aa=Lf({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},am(sm));function Uf(t,e,r){return Ft(t),r===void 0&&(r=new Uint8Array(t.outputLen)),cn(t,r,e)}var En=Uint8Array.of(0),cm=Uint8Array.of();function Nf(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:u}=cn.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++){En[0]=p+1;let g=c._cloneInto(l);p&&g.update(f),g.update(r).update(En).digestInto(f),u._cloneInto(l).update(f).digestInto(f),a.set(f,o*p)}if(En[0]=i,i>1&&c.update(f),c.update(r).update(En).digestInto(f),u.update(f).digestInto(f),a.set(f,o*(i-1)),c.destroy(),u.destroy(),l?.destroy(),f!==a&&Fe(f),Fe(En),n===a.length)return a;let d=a.slice(0,n);return Fe(a),d}var kf={hashSHA256(t){return Qe(t.subarray())},getHKDF(t,e){let r=Uf(Qe,e,t),s=Nf(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 Mf=kf;function Kf(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 Ff(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 Hf(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 um=0,fm=4294967295,lm="Cipherstate has reached maximum n, a new handshake must be performed",js=class{n;bytes;view;constructor(e=um){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>fm)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 js(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:u}=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=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()}},Sn=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 vn;(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:[]},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 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(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 Zt('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 Zt('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 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})(vn||(vn={}));var An;(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),vn.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=vn.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*vn.codec().stream(o,o.uint32(),`${a}.extensions`,{limits:c.limits?.extensions});break}default:{o.skipType(f&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={}));async function Ra(t,e,r){let n=await t.sign(zf(e));return An.encode({identityKey:xt(t.publicKey),identitySig:n,extensions:r})}async function Oa(t,e,r){try{let n=An.decode(t),s=un(n.identityKey);if(r?.equals(s)===!1)throw new Error(`Payload identity key ${s} does not match expected remote identity key ${r}`);if(!e)throw new Error("Remote static does not exist");let o=zf(e);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Bn(n.message)}}function zf(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 zs({lengthDecoder:Or,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(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 $f(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=t,f=await Ra(o,a.publicKey,u),l=new Sn({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),Hf(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(f),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 Vf(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=t,f=await Ra(o,a.publicKey,u),l=new Sn({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(f),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 Ys=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??Mf;this.crypto=Kf(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?Ff(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??be(0)}[Symbol.toStringTag]="@libp2p/noise";[Pn]=["@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?.publicKey,r),i=un(o.payload.identityKey);return{connection:Pa(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Ni(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?.publicKey,r),i=un(o.payload.identityKey);return{connection:Pa(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Ni(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 $f({connection:e,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}async performHandshakeResponder(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Vf({connection:e,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}};function jf(t={}){return e=>new Ys(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 Hs{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 Wf="/webtransport",Ma=class extends Fs{webTransport;streamIDCounter;reader;constructor(e,r){super(r,{protocol:Wf,name:"muxer"}),this.webTransport=e,this.streamIDCounter=0,this.reader=this.webTransport.incomingBidirectionalStreams.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:n,value:s}=await this.reader.read();if(n||s==null)break;this.onRemoteStream(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 Yf(t){return{protocol:Wf,createStreamMuxer(e){return new Ma(t,e)}}}var Ka=class extends Ks{cleanUpWTSession;constructor(e){super(e),this.cleanUpWTSession=e.cleanUpWTSession}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}sendReset(){this.cleanUpWTSession("abort")}async sendClose(e){this.cleanUpWTSession("close"),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}},Gf=t=>new Ka(t);function Zf(t,e){return e.filter(n=>!!t.find(s=>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(!Os.matches(t))throw new Tn("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=ju(o.value??""));let n=Yu(t),s=n.host;return n.type==="ip6"&&s.includes(":")&&(s=`[${s}]`),{url:`https://${s}:${n.port}`,certhashes:e,remotePeer:r}}var Gs=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 Xf=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;[Pn]=["@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=()=>{},u=!1,f=!1,l=!1;try{this.metrics?.dialerEvents.increment({pending:!0});let d=new Xf(`${n}/.well-known/libp2p-webtransport?type=noise`,{serverCertificateHashes:s.map(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 nr("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=Gf({remoteAddr:e,cleanUpWTSession:c,direction:"outbound",log:this.components.logger.forComponent("libp2p:webtransport:connection")});let p=await this.authenticateWebTransport({wt:d,maConn:a,remotePeer:o,certhashes:s,...r});if(l=!0,o!=null&&(l=o.equals(p)),!l)throw new or("Failed to authenticate webtransport");return await r.upgrader.upgradeOutbound(a,{...r,skipEncryption:!0,remotePeer:p,muxerFactory:Yf(d),skipProtection:!0})}catch(d){throw this.log.error("caught wt session err - %e",d),c(l?"upgrade_error":f?"noise_error":"ready_error"),d}finally{i!=null&&r.signal?.removeEventListener("abort",i)}}async authenticateWebTransport({wt:e,maConn:r,remotePeer:n,certhashes:s,onProgress:o,signal:i}){o?.(new nr("webtransport:open-authentication-stream"));let a=await e.createBidirectionalStream();i?.throwIfAborted();let c=new Gs({stream:a,log:r.log.newScope("muxer")}),u=jf()(this.components);o?.(new nr("webtransport:secure-outbound-connection"));let{remoteExtensions:f,remotePeer:l}=await u.secureOutbound(c,{signal:i,remotePeer:n,skipStreamMuxerNegotiation:!0});if(o?.(new nr("webtransport:close-authentication-stream")),await c.close({signal:i}),!Zf(f?.webtransportCerthashes??[],s.map(d=>d.bytes)))throw new se("Our certhashes are not a subset of the remote's reported certhashes");return l}createListener(e){return Ua(this.components,{...e,certificates:this.config.certificates})}listenFilter(){return[]}dialFilter(e){return globalThis.WebTransport==null?[]:e.filter(r=>{if(!Os.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);})();
3
3
  //! TODO unclear how to add backpressure here?
4
4
  /*! Bundled license information:
5
5